来自实时音频输入的每分钟节拍数 [英] Beats per minute from real-time audio input

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

问题描述

我想编写一个简单的 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.

我见过这篇游戏开发文章,这绝对没有帮助.我经历了并试图实施他正在做的事情,但它没有奏效.

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.

推荐答案

使用滑动窗口 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];

虚部类似.

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 high frequencies.

如果您想在流行音乐中找到 BPM,您可能应该专注于低音.您可以通过对功率谱的较低部分求和来获取低音强度.使用哪些数字取决于采样频率:

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 个样本.现在您最终要计算每 256 个样本的 bassIntensity.

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.

祝你好运!

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆