Split UInt32 (audio frame) into two SInt16s (left and right)?

Posted by morgancodes on Stack Overflow See other posts from Stack Overflow or by morgancodes
Published on 2010-03-08T22:28:46Z Indexed on 2010/03/08 22:36 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

Total noob to anything lower-level than Java, diving into iPhone audio, and realing from all of the casting/pointers/raw memory access.

I'm working with some example code wich reads a WAV file from disc and returns stereo samples as single UInt32 values. If I understand correctly, this is just a convenient way to return the 32 bits of memory required to create two 16 bit samples. Eventually this data gets written to a buffer, and an audio unit picks it up down the road. Even though the data is written in UInt32-sized chunks, it eventually is interpreted as pairs of 16-bit samples.

What I need help with is splitting these UInt32 frames into left and right samples. I'm assuming I'll want to convert each UInt32 into an SInt16, since an audio sample is a signed value. It seems to me that for efficiency's sake, I ought to be able to simply point to the same blocks in memory, and avoid any copying.

So, in pseudo-code, it would be something like this:

UInt32 myStereoFrame = getFramefromFilePlayer;

SInt16* leftChannel = getFirst16Bits(myStereoFrame);
SInt16* rightChannel = getSecond16Bits(myStereoFrame);

Can anyone help me turn my pseudo into real code?

© Stack Overflow or respective owner

Related posts about audio

Related posts about iphone