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:
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.