我想在BufferReady方法的末尾調用Spectrum方法,但我不知道爲什麼會出現錯誤,這告訴我將錯誤參數傳遞給它。 Raw
是int
。我應該通過什麼參數來調用該方法C#
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;
}
你得到的錯誤信息是什麼? – Hoeloe