我想在BufferReady方法的末尾调用频谱方法,但我不知道为什么会出现错误,它告诉我我向它传递了错误的参数。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;
}发布于 2012-12-11 01:30:59
向Spectrum方法调用的第一个参数添加ref关键字
double[] spectrum = FourierTransform.Spectrum(ref sampleBuffer, Raw);更新ref关键字状态,该数组应该通过引用频谱方法传递,如果您将在频谱方法中为x赋值,那么这将为microphone_BufferReady方法中的sampleBuffer变量赋值。但是正如Jon在评论中所说的,在这种特殊情况下,ref可以从您的频谱方法定义中删除(但您也必须修改该方法的所有其他调用)。
https://stackoverflow.com/questions/13805979
复制相似问题