C++ reading 16bit Wav file

前端 未结 5 1034
感情败类
感情败类 2021-01-07 05:11

I\'m having trouble reading in a 16bit .wav file. I have read in the header information, however, the conversion does not seem to work.

For example, in Matlab if I r

5条回答
  •  梦毁少年i
    2021-01-07 05:32

    A 16-bit quantity gives you a range from -32,768 to 32,767, not from -256 to 255 (that's just 9 bits). Use:

    for (int i = 0; i < size; i += 2)
    {
        c = (data[i + 1] << 8) + data[i]; // WAV files are little-endian
        double t = (c - 32768)/32768.0;
        rawSignal.push_back(t);
    }
    

提交回复
热议问题