我目前正在尝试将16位样本转换为32位浮点。但是,我遇到了一个问题,即我的32位浮点文件的音频时间减少了一半。 (例如,我的输入是一个4秒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);
}
}
答案 0 :(得分:3)
退出条件:
} while (bytesRead != 0 && converted.Length < reader.Length);
看起来很可疑;它听起来就像你扩展数据一样,所以我们应该期望converted.Length
更多而不是reader.Length
结束 - 所以我的猜测是这个退出条件导致它过早退出。