C++ reading 16bit Wav file

前端 未结 5 969
感情败类
感情败类 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条回答
  •  醉梦人生
    2021-01-07 05:35

    You might want something more like this:

    uint16_t c;
    for(unsigned i=0; (i < size); i++)
    {
       // get a 16 bit pointer to the array
       uint16_t* p = (uint16_t*)data;
       // get the i-th element
       c = *( p + i );
       // convert to signed? I'm guessing this is what you want
       int16_t cs = (int16_t)c;
       double t = (cs-256)/256.0;
       rawSignal.push_back(t);
    }
    

    Your code converts the 8 bit value to a signed value then writes it into an unsigned variable. You should look at that and see if it's what you want.

提交回复
热议问题