读取方法返回两倍于实际存在的样本数

Read method returning twice the number of samples actually present

我有以下代码可以将音频文件的样本读入字节数组。

int signal_read = signal.Read(signal_sample, 0, signal_length);
MessageBox.Show(signal_read + "");

其中 signalWaveFileReaderclass 的对象。

MessageBox.Show 总是显示从软件 Audacity 获得的实际样本数的两倍。

read方法不是return从音频中读取的样本数吗?

不,它returns读取的字节数。

所以对于 16 位 PCM wav,它会给你两倍的样本量。如果是立体声 16 位,您将获得四倍的效果。

您可能想要使用填充 float[][] 数组的重载,而不是读取字节。例如,对于单声道音频:

var array = new float[][] { new float[sampleCount] };

var actualSamples = signal.Read(array, sampleCount);