每分钟节拍从实时音频输入

每分钟节拍从实时音频输入

本文介绍了每分钟节拍从实时音频输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个简单的C#应用​​程序来监视线路的音频,给我的电流(好,滚动平均)每分钟心跳。

I'd like to write a simple C# application to monitor the line-in audio and give me the current (well, the rolling average) beats per minute.

我见过的this gamedev文章,那是绝对没有帮助。我经历了,并试图实现他在做什么,但它只是不工作。

I've seen this gamedev article, and that was absolutely no help. I went through and tried to implement what he was doing but it just wasn't working.

我知道必须吨,这个解决方案,因为大量的DJ软件,这样做,但我没有找到任何开源库或说明书上做自己运气好的话。

I know there have to be tons of solutions for this, because lots of DJ software does it, but I'm not having any luck in finding any open-source library or instructions on doing it myself.

推荐答案

计算一个powerspectrum用滑动窗口FFT:以1024个样本:

Calculate a powerspectrum with a sliding window FFT:Take 1024 samples:

double[] signal = stream.Take(1024);

其提供给一个FFT算法:

Feed it to an FFT algorithm:

double[] real = new double[signal.Length];
double[] imag = new double[signal.Length);
FFT(signal, out real, out imag);

您将得到一个实部和虚部。不要扔掉的虚部。做同样的实部为虚。而这是事实,虚部为pi / 2之间的相位差与真实,它仍然包含的频谱信息的50%。

You will get a real part and an imaginary part. Do NOT throw away the imaginary part. Do the same to the real part as the imaginary. While it is true that the imaginary part is pi / 2 out of phase with the real, it still contains 50% of the spectrum information.

编辑:

计算,而不是幅度,让你有当它是响亮而接近于零大量的当它是安静的功率:

Calculate the power as opposed to the amplitude so that you have a high number when it is loud and close to zero when it is quiet:

for (i=0; i < real.Length; i++) real[i] = real[i] * real[i];

类似地,对于虚部

Similarly for the imaginary part.

for (i=0; i < imag.Length; i++) imag[i] = imag[i] * imag[i];

现在你有一个功率谱在过去的1024个样本。其中,频谱的第一部分是低频率和频谱的最后一部分是高频率。

Now you have a power spectrum for the last 1024 samples. Where the first part of the spectrum is the low frequencies and the last part of the spectrum is the highfrequencies.

。可以总结了功率谱的下部拿起低音强度。哪些号码的使用取决于采样频率:

If you want to find BPM in popular music you should probably focus on the bass. You can pick up the bass intensity by summing the lower part of the power spectrum. Which numbers to use depends on the sampling frequency:

double bassIntensity = 0;
for (i=8; i < 96; i++) bassIntensity += real[i];

现在做同样的再次但是你计算出新的频谱之前,移动窗口256个采样。现在,你最终计算bassIntensity,每256个样本。

Now do the same again but move the window 256 samples before you calculate a new spectrum. Now you end up with calculating the bassIntensity for every 256 samples.

这是一个很好的输入您的BPM分析。当低音是安静,你没有拍,当它是响亮,你有一个节拍。

This is a good input for your BPM analysis. When the bass is quiet you do not have a beat and when it is loud you have a beat.

祝你好运!

这篇关于每分钟节拍从实时音频输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 05:26