Skip to main content
gamedev.net
🔒 Locked

two's complement conversion help

Started by audiocoder 0 replies 350+ views
Original Post
audiocoder
audiocoder
My data comes as a stream of bytes out of a wavefile: byte0 = low order sample0 L byte1 = high order sample0 L byte2 = low order sample0 R byte3 = high order sample0 R byte4 = low order sample1 L byte5 = high order sample1 L byte6 = low order sample1 R byte7 = high order sample1 R etc... byte1 and byte0 make up one 16 bit signed word. I'd like to convert these bytes into an integer in the range -32768 -> 32767. I'd also like to convert them back to put back into the stream... Can anyone help me figure out how to do this in C? Thanks!
twanvl
twanvl
int16bits = highbyte<<8 | lowbyte;lowbyte  = int16bits & 0xFF;highbyte = int16bits>>8 & 0xFF;

To get it in the range -32768..32767 simply use a signed short

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.