我想在 BufferReady 方法的末尾调用 Spectrum 方法,但我不知道为什么会出现错误,这告诉我我向它传递了错误的参数。Raw
是一个int
。
void microphone_BufferReady(object sender, EventArgs e) {
if (buffer.Length <= 0) return;
// Retrieve audio data
microphone.GetData(buffer);
double[] sampleBuffer = new double[(Utilities.NextPowerOfTwo((uint)buffer.Length))];
int index = 0;
for (int i = 0; i < 2048; i += 2) {
sampleBuffer[index] = Convert.ToDouble(BitConverter.ToInt16((byte[])buffer, i)); index++;
}
//ERROR UNDER
double[] spectrum = FourierTransform.Spectrum(sampleBuffer, Raw);// I GOT ERROR HERE
}
-----------------------
public static double[] Spectrum(ref double[] x, int method = Raw)
{
//uint pow2Samples = FFT.NextPowerOfTwo((uint)x.Length);
double[] xre = new double[x.Length];
double[] xim = new double[x.Length];
Compute((uint)x.Length, x, null, xre, xim, false);
double[] decibel = new double[xre.Length / 2];
for (int i = 0; i < decibel.Length; i++)
decibel[i] = (method == Decibel) ? 10.0 * Math.Log10((float)(Math.Sqrt((xre[i] * xre[i]) + (xim[i] * xim[i])))) : (float)(Math.Sqrt((xre[i] * xre[i]) + (xim[i] * xim[i])));
return decibel;
}