我目前正在尝试将 16 位样本转换为 32 位浮点。但是,我遇到了一个问题,我的 32 位浮点文件的音频时间减半。(例如,我的输入是一个四秒的 16 位PCM WAV,我的输出变成一个两秒的 IEEE 浮点 WAV。)这是代码。
using (WaveFileReader reader = new WaveFileReader(file.wav))
{
IWaveProvider stream32 = new Wave16ToFloatProvider(reader);
using (WaveFileWriter converted = new WaveFileWriter(temp.wav))
{
// Buffer length needs to be a power of 2 for FFT to work nicely.
// However, make the buffer too long and pitches aren't detected fast enough.
// Successful buffer sizes: 8192, 4096, 2048, 1024 (some
// pitch detection algorithms need at least 2048).
byte[] buffer = new byte[8192];
int bytesRead;
do
{
bytesRead = stream32.Read(buffer, 0, buffer.Length);
converted.Write(buffer, 0, bytesRead);
} while (bytesRead != 0 && converted.Length < reader.Length);
}
}