简体   繁体   中英

Unexpected values while reading wav blocks in C++

I have a what seems to be an easy problem yet I can't seem to get the results I want.

According to the Wav Format , a 16-bit wav file is signed and values range from -32768 to 32767. Yet I can only seem to be getting positive integers, what am I missing?

Here's a screenshot of the few bits of data I outputted:

跑跑程序Wav十六进制值

  • Additionally, can someone explain how to tell apart the right channel data and left channel data? I can't seem to find enough examples of this. Thanks.

Here's the code I used, wav.getFile() returns the file pointer exactly after reading all the other header data.

int SoundData;

        for( int i = 0; i < 32; i++ )
        {

            fread( &SoundData, 4, 1, wav.getFile() );
            cout << SoundData << endl;
        }

Thanks in advance everyone.

SoundData更改为short int是否有帮助?

(going to put this as answer suggestion):

You're reading 4 bytes at a time ... don't you want to read 2 bytes at a time (16 bits)?

so

fread( &SoundData, 4, 1, wav.getFile() );

should become

fread( &SoundData, 2, 1, wav.getFile() );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM