简体   繁体   English

帮助FFT(快速傅立叶变换)和/或DSP

[英]Help with FFT(Fast Fourier Transforms) and/or DSP

Im trying to do a screen-flashing application, that flashes the screen according to the music(which will be frequencies, such as healing frequencies, etc...). 我试图做一个屏幕闪烁的应用程序,根据音乐闪烁屏幕(这将是频率,如愈合频率等......)。 I already made the player and know how will I make the screen flash, but I need to make the screen flash super fast according to the music, for example if the music speeds up, the screen-flash will flash faster. 我已经制作了播放器并且知道如何让屏幕闪烁,但是我需要根据音乐使屏幕快速闪烁,例如如果音乐加速,屏幕闪光会更快闪烁。 I understand that I would achieve this by FFT or DSP(as I only need to know when the frequency raises from some Hz, lets say 20 to change the color, making the screen-flash). 我知道我会通过FFT或DSP实现这一点(因为我只需要知道频率从某些Hz升高时,让我们说20改变颜色,使屏幕闪烁)。

But I've found that I understand NOTHING, even less try to implement it to my application. 但我发现我理解没有,甚至更少尝试将其应用到我的应用程序中。

Can somebody help me out to learn whichever both of them? 有人可以帮助我学习他们两个吗? My email is sismetic_chaos@hotmail.com. 我的电子邮件是sismetic_chaos@hotmail.com。 I really need help, I've been stucked for like 3 days not coding or doing anything at all, trying to understand, but I dont. 我真的需要帮助,我已经被困了3天没有编码或做任何事情,试图理解,但我没有。

PS:My application is written in C++ and Qt. PS:我的应用程序是用C ++和Qt编写的。

PS:Thanks for taking the time to read this and the willingness to help. PS:感谢您花时间阅读本文并愿意提供帮助。

Edit: Thanks to all for the answers, the problem is in no way solved yet, but I appreciate all the answers, I didnt thought I would get so many answers and info. 编辑:感谢所有的答案,问题仍然没有解决,但我欣赏所有的答案,我没想到我会得到这么多的答案和信息。 Thanks to you all. 谢谢大家。

The output of a FFT will give you the frequency spectrum of an audio sample, but extracting the tempo from the FFT output is probably not the way you want to go. FFT的输出将为您提供音频样本的频谱,但从FFT输出中提取速度可能不是您想要的方式。

One thing you can do is to use peak detection to identify the volume "spikes" that typically occur on the "down-beats" of the music. 您可以做的一件事是使用峰值检测来识别通常出现在音乐“下拍”中的音量“尖峰”。 If you can identify the down-beats, then you can use a resource like bpmdatabase.com to find the tempo of the song. 如果您可以识别下拍,那么您可以使用bpmdatabase.com之类的资源来查找歌曲的速度。 The tempo will tell you how fast to flash and the peaks you detected will tell you when to start flashing. 速度会告诉您闪光的速度有多快,您检测到的峰值会告诉您何时开始闪烁。 Have your app monitor your flashes to make sure that they generally occur at the same time as a peak (if the two start to diverge, then the tempo may have changed mid-song). 让你的应用程序监控你的闪光灯,以确保它们通常与峰值同时发生(如果两者开始发散,那么节奏可能在歌曲中期改变)。

That may sound straightforward, but this is actually a very non-trivial thing to implement. 这可能听起来很简单,但这实际上是一件非常重要的事情。 You might want to read this SO question for more information. 您可能想要阅读此SO问题以获取更多信息。 There are some quality links in the answers there. 那里的答案中有一些高质量的链接。

If I'm completely mis-interpreting what you are trying to do and you need to do FFTs for something different, then you might want to look at using one of the existing FFT libraries to do the heavy lifting for you. 如果我完全误解你要做的事情并且你需要为不同的东西做FFT,那么你可能想看看使用现有的FFT库来为你做繁重的工作。 Some examples are FFTW and KissFFT . 一些例子是FFTWKissFFT

This is a difficult problem, requiring more than an FFT. 这是一个难题,需要的不仅仅是FFT。 I'll briefly describe how I implemented beat detection when I was writing software for professional DJ equipment. 我将简要介绍在为专业DJ设备编写软件时如何实现节拍检测。

First of all, you'll need to cut down the amount of data you're dealing with, since there are only two or three beats per second, but tens of thousands of samples. 首先,你需要减少你正在处理的数据量,因为每秒只有两到三个节拍,但成千上万的样本。 You'll also need to look at different frequency ranges, since some types of music carry the tempo in the bassline, and others in percussion or other instruments. 您还需要查看不同的频率范围,因为某些类型的音乐会在低音线中播放节奏,而其他类型的音乐则在打击乐器或其他乐器中播放。 So pass the signal through several band-pass filters (I chose 8 filters, each covering one octave, from low bass to high treble), and then downsample each band by averaging the power over a few hundred samples. 因此,通过几个带通滤波器传递信号(我选择8个滤波器,每个滤波器覆盖一个八度音程,从低音到高音),然后通过平均几百个样本的功率对每个频段进行下采样。

Every few seconds, you'll have a thousand or so samples in each band. 每隔几秒钟,你就会在每个乐队中拥有一千个左右的样本。 Your next tool is an autocorrelation, to identify repetitive patterns in the music. 您的下一个工具是自相关,以识别音乐中的重复模式。 The peaks of the autocorrelation tell you what the beat is more or less likely to be; 自相关的高峰告诉你节拍的可能性或多或少; but you'll need to make up some heuristics to compare all the frequency bands to find a beat that you can be confident in, and to avoid misleading syncopations. 但你需要编制一些启发式算法来比较所有频段,以找到你可以信赖的节拍,并避免误导性的切分。 If you can manage that, then you'll have a reasonable guess at the tempo, but no idea of the phase (ie exactly when to flash the screen). 如果你可以管理它,那么你将对节奏有一个合理的猜测,但不知道相位(即确切地何时闪烁屏幕)。

Now you can look at the a smoothed version of the audio data for peaks, some of which are likely to correspond to beats. 现在,您可以查看峰值音频数据的平滑版本,其中一些可能与节拍相对应。 Initially, look for the strongest peak over the course of a few seconds and take that as a downbeat. 最初,在几秒钟内寻找最强的峰值并将其视为悲观。 In conjunction with the tempo you estimated in the first stage, you can predict when the next beat is due, and measure where you actually saw something like a beat, and adjust your estimate to more closely match the data. 结合您在第一阶段估计的速度,您可以预测下一个节拍到期的时间,并测量您实际看到的节拍类型,并调整您的估计值以更接近地匹配数据。 You can also maintain a confidence level based on how well the predicted beats match the measured peaks; 您还可以根据预测的节拍与测量峰值的匹配程度来保持置信水平; if that drops too low, then restart the beat detection from scratch. 如果降得太低,则从头开始重新启动节拍检测。

There are a lot of fiddly details to this, and it took me some weeks to get it working nicely. 这有很多细节,我需要几个星期的时间才能让它运转良好。 It is a difficult problem. 这是一个难题。

Or for a simple visualisation effect, you could simply detect peaks and flash the screen for each one; 或者,对于简单的可视化效果,您可以简单地检测峰值并为每个峰值闪烁屏幕; it will probably look good enough. 它可能看起来不错。

It sounds like maybe you're trying to get your visualizer to flash the screen in time with the music somehow. 听起来好像你正试图让你的可视化工具以某种方式及时闪现屏幕。 I don't think calculating the FFT is going to help you here. 我不认为计算FFT会对你有所帮助。 At any given instant, there will be many simultaneous frequency components, all over the audio spectrum (roughly 20 Hz to 20 kHz). 在任何给定的瞬间,在整个音频频谱(大约20Hz到20kHz)内将存在许多同时的频率分量。 But you're likely to be a lot more interested in the musical tempo (beats per minute -- more like 5 Hz or below), and that's not going to show up anywhere in an FFT of the raw audio signal. 但是你可能对音乐节奏更感兴趣(每分钟节拍 - 更像是5赫兹或更低),并且这不会出现在原始音频信号的FFT中的任何地方。

You probably need something much simpler -- some sort of real-time peak detection. 您可能需要更简单的东西 - 某种实时峰值检测。 Whenever you see a peak greater than some threshold above the average volume, make your screen flash. 每当您看到峰值高于某个阈值高于平均音量时,请使屏幕闪烁。

Of course, more complicated visualizations might well take advantage of the FFT, but not the one you're describing. 当然,更复杂的可视化可能会利用FFT,但不是你所描述的那个。

My recommendation would be to find a library that does this for you. 我的建议是找一个能为你做这件事的图书馆。 Unless you have a lot of mathematics to back you up, I think you will be wasting a ton of your time trying to learn FFTs when all you really want out is some sort of 'base hits per minute' number out which you can adjust your graphics to accordingly. 除非你有很多数学支持你,否则我认为当你真正想要的是某种“每分钟基本命中数”时,你会浪费大量的时间来学习FFT,你可以调整你的相应的图形。

Check out this similar post: here 看看这个类似的帖子: 这里

It took me about three weeks to understand the mathematics behind FFTs and then another week to write something in Matlab using those concepts. 我花了大约三个星期的时间来理解FFT背后的数学,然后又花了一周的时间来使用这些概念在Matlab中编写一些东西。 If you are discouraged after three days, don't try and roll your own. 如果您在三天后气馁,请不要尝试自己动手。

I hope this is helpful advice and not discouraging. 我希望这是有用的建议,而不是令人沮丧。

-Brian J. Stinar- -Brian J. Stinar-

As previous answers have noted, an FFT is probably not the tool you need in order to solve your problem, which requires tempo detection rather than spectral analysis. 正如之前的答案所指出的,FFT可能不是解决问题所需的工具,这需要速度检测而不是光谱分析。

For an example of what can be done using FFT - and of how a particular FFT implementation was integrated into a Qt application, take a look at this blog post which describes the spectrum analyzer demo I developed. 有关使用FFT来完成一个例子-与特定FFT实现是如何集成到Qt应用程序,看看这个博客帖子描述了频谱分析仪的演示中,我发展。 Code for the demo is shipped with Qt itself, in the demos/spectrum directory. 演示代码随Qt本身一起提供,位于演示/频谱目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM