帮助 FFT(快速傅立叶变换)和/或 DSP
我正在尝试做一个屏幕闪烁应用程序,它根据音乐(这将是频率,例如治疗频率等)闪烁屏幕。 我已经制作了播放器并且知道如何让屏幕闪烁,但是我需要根据音乐使屏幕闪烁超快,例如如果音乐加快,则屏幕闪烁会闪烁得更快。我知道我可以通过 FFT 或 DSP 来实现这一点(因为我只需要知道频率何时从某个 Hz 升高,比如说 20 来改变颜色,使屏幕闪烁)。
但我发现我什么都不懂,更不用说尝试将其实现到我的应用程序中。
有人可以帮我学习他们两个吗?我的电子邮件地址是[电子邮件受保护]。我真的需要帮助,我已经被困了大约 3 天,没有编码或做任何事情,试图理解,但我没有。
PS:我的应用程序是用 C++ 和 Qt 编写的。
PS:感谢您花时间阅读本文并愿意提供帮助。
编辑:感谢大家的答案,问题还没有解决,但我感谢所有的答案,我没想到我会得到这么多的答案和信息。谢谢大家。
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).
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 [email protected]. 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.
PS:My application is written in C++ and Qt.
PS:Thanks for taking the time to read this and the willingness to help.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个难题,需要的不仅仅是 FFT。我将简要描述我在为专业 DJ 设备编写软件时如何实现节拍检测。
首先,您需要减少正在处理的数据量,因为每秒只有两到三个节拍,但有数万个样本。您还需要查看不同的频率范围,因为某些类型的音乐以低音线节奏,而另一些则以打击乐器或其他乐器节奏。因此,让信号通过几个带通滤波器(我选择了 8 个滤波器,每个滤波器覆盖一个八度音程,从低音到高音),然后通过对数百个样本的功率进行平均来对每个频段进行下采样。
每隔几秒钟,每个频段就会有一千个左右的样本。您的下一个工具是自相关,用于识别音乐中的重复模式。自相关的峰值告诉您节拍或多或少可能是什么;但您需要进行一些启发式比较所有频段,以找到您可以自信的节拍,并避免误导性的切分音。如果你能做到这一点,那么你将对节奏有一个合理的猜测,但不知道阶段(即确切的何时闪烁屏幕)。
现在您可以查看音频数据的平滑版本的峰值,其中一些可能对应于节拍。最初,寻找几秒钟内最强的峰值,并将其视为悲观情绪。结合您在第一阶段估计的节奏,您可以预测下一个节拍何时到期,并测量您实际看到的类似节拍的位置,并调整您的估计以更接近地匹配数据。您还可以根据预测的节拍与测量的峰值的匹配程度来维持置信水平;如果下降得太低,则从头开始重新启动节拍检测。
这其中有很多繁琐的细节,我花了几周的时间才让它顺利工作。这是一个难题。
或者,为了获得简单的可视化效果,您可以简单地检测峰值并为每个峰值闪烁屏幕;它可能看起来足够好。
This is a difficult problem, requiring more than an FFT. I'll briefly describe how I implemented beat detection when I was writing software for professional DJ equipment.
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.
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 (i.e. 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.
FFT 的输出将为您提供音频样本的频谱,但从 FFT 输出中提取节奏可能不是您想要的方式。
您可以做的一件事是使用峰值检测来识别通常出现在音乐“强拍”上的音量“尖峰”。如果您可以识别悲观节奏,那么您可以使用 bpmdatabase.com 等资源来查找节奏歌曲。速度将告诉您闪烁的速度,您检测到的峰值将告诉您何时开始闪烁。让您的应用程序监视您的闪光,以确保它们通常与峰值同时发生(如果两者开始发散,则节奏可能在歌曲中间发生了变化)。
这听起来可能很简单,但这实际上是一件非常不简单的事情。您可能想阅读这个问题了解更多信息信息。那里的答案中有一些高质量的链接。
如果我完全误解了您想要做的事情,并且您需要对不同的东西进行 FFT,那么您可能需要考虑使用现有的 FFT 库之一来为您完成繁重的工作。一些示例是 FFTW 和 KissFFT。
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.
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. 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. 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. Some examples are FFTW and KissFFT.
听起来也许您正在尝试让可视化工具及时闪烁屏幕
不知怎么的音乐。我认为计算 FFT 对您没有帮助。在任何
在给定的瞬间,整个音频频谱(大约 20 Hz 到 20 kHz)都会有许多同时出现的频率分量。但您可能会对以下内容更感兴趣
音乐节奏(每分钟节拍——更像是 5 Hz 或更低),这不会显示
原始音频信号 FFT 中的任意位置。
您可能需要更简单的东西——某种实时峰值检测。
每当您看到峰值大于平均音量之上的某个阈值时,
让你的屏幕闪烁。
当然,更复杂的可视化很可能会利用 FFT,
但不是你所描述的那个。
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. At any
given instant, there will be many simultaneous frequency components, all over the audio spectrum (roughly 20 Hz to 20 kHz). 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.
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,因为你真正想要的只是某种“每分钟的基本点击数”,你可以通过它来调整你的 FFT。图形相应。
看看这个类似的帖子:
此处
我花了大约三周的时间才理解 FFT 背后的数学原理,然后又花了一周的时间才理解使用这些概念在 Matlab 中写一些东西。如果三天后你灰心丧气,就不要尝试自己动手。
我希望这是有用的建议而不是令人沮丧。
-布莱恩·J·斯蒂纳尔-
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.
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. 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-
正如前面的答案所指出的,FFT 可能不是您解决问题所需的工具,它需要节奏检测而不是频谱分析。
有关使用 FFT 可以完成哪些操作以及如何将特定 FFT 实现集成到 Qt 应用程序中的示例,请查看 这篇博文 描述了我开发的频谱分析仪演示。演示代码随 Qt 本身一起提供,位于 demos/spectrum< /a> 目录。
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.
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. Code for the demo is shipped with Qt itself, in the demos/spectrum directory.