使用BPM检测时,索引超出范围。使用NAudio和SoundTouch.net从麦克风进行实时BPM检测

时间:2019-06-04 12:00:28

标签: c# naudio soundtouch

我想用NAudio从麦克风获取音频,然后将数据输入到BpmDetect的{​​{1}}

此程序应触发一些事件,以更改俱乐部中的照明程序。当不同的DJ以不同的速度播放音乐时,此代码段应从麦克风输入中检测到它。我以前尝试使用SoundTouch,但是从bpm检测中没有得到好的结果。

BASS.NET
  

Console.WriteLine(bpm.GetBpm());抛出System.IndexOutOfRangeException。

在创建sampleBuffer并将各种numSamples提供给var waveIn = new WaveInEvent(); waveIn.StartRecording(); var bpm = BpmDetect<TSampleType, TLongSampleType>.NewInstance(1, 8000); int z = 0; Console.WriteLine("WaveFormat of input:"); Console.WriteLine("Channels: " + waveIn.WaveFormat.Channels); Console.WriteLine("BitsPerSample: " + waveIn.WaveFormat.BitsPerSample); Console.WriteLine("SampleRate: " + waveIn.WaveFormat.SampleRate); Console.WriteLine("SampleRate: " + waveIn.WaveFormat.Encoding); Console.WriteLine("BufferMilliseconds: " + waveIn.BufferMilliseconds); /* WaveFormat of input: Channels: 1 BitsPerSample: 16 SampleRate: 8000 SampleRate: Pcm */ var sampleBuffer = new TSampleType[waveIn.WaveFormat.SampleRate / 10]; waveIn.DataAvailable += (s, a) => { // interpret as 16 bit audio for (int index = 0; index < a.BytesRecorded; index += 2) { short sample = (short)((a.Buffer[index + 1] << 8) | a.Buffer[index + 0]); // to floating point var sample32 = sample / 32768f; sampleBuffer[index / 2] = sample32; } bpm.InputSamples(sampleBuffer, 800); // pSoundTouch.PutSamples(sampleBuffer, nSamples); Dear future phil, check out lines 148 and below, best, past phil Console.WriteLine(z); if (z == 9) { Console.WriteLine(bpm.GetBpm()); z = 0; } z = z + 1; }; 时,我试图更改许多事情,例如不同的float强制转换。我不记得自己尝试过的所有内容,但我感觉自己在这里似乎遗漏了一些明显的东西。 谢谢你的任何建议:)

0 个答案:

没有答案