有人有示例如何将 BPMDetect 类与 naudio WaveIn 一起使用吗?
我总是得到 0 BPM。
这是我到目前为止所拥有的:
const int ConstWaveInSampleRate = 44100;
private BufferedWaveProvider bufferedWaveProvider;
private WaveIn m_WaveIn;
private WaveOut m_WaveOut;
private BPMDetect m_BpmDetect;
public NAudioBpmDetect()
{
int deviceNumber = 0;
m_WaveIn = new WaveIn();
m_WaveIn.DeviceNumber = deviceNumber;
int channels = NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels;
m_WaveIn.WaveFormat = new WaveFormat(ConstWaveInSampleRate, 16, 1);
m_WaveOut = new WaveOut();
m_BpmDetect = new BPMDetect(channels, ConstWaveInSampleRate);
m_WaveIn.DataAvailable += new EventHandler<WaveInEventArgs>(WaveIn_DataAvailable);
bufferedWaveProvider = new BufferedWaveProvider(m_WaveIn.WaveFormat);
bufferedWaveProvider.DiscardOnBufferOverflow = true;
m_WaveOut.Init(bufferedWaveProvider);
m_WaveIn.StartRecording();
m_WaveOut.Play();
}
void WaveIn_DataAvailable(object sender, WaveInEventArgs e)
{
bufferedWaveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
byte[] buffer = e.Buffer.Where((value, index) => index % 2 == 0).ToArray();
var waveBuffer = new WaveBuffer(buffer);
uint count = (uint)waveBuffer.FloatBuffer.Count();
m_BpmDetect.PutSamples(waveBuffer.FloatBuffer, count);
Console.WriteLine(m_BpmDetect.Bpm);
}
从缓冲区中拆分通道数据是否存在问题?