Kev
Kev

Reputation: 121

Understanding AurioTouch

In the AurioTouch example for iPhone the following code is used to add samples into a draw buffer that gets used when rendering to the screen

SInt8 *data_ptr = (SInt8 *)(ioData->mBuffers[0].mData);
for (int i=0; i<numFrames; i++)
{
    if ((i+drawBufferIdx) >= drawBufferLen)
    {
        cycleOscilloscopeLines();
        drawBufferIdx = -i;
    }

    drawBuffers[0][i + drawBufferIdx] = data_ptr[2];
    data_ptr += 4;
}

I simply cannot understand why this works. The actual mData buffer contains SInt32 samples in fixed point 8.24 LPCM.

However, the loop seems to be extrating the 3rd byte of every sample as an SInt8 and using this value (which will range from -128 to +127) to represent the sample.

How is this a valid value for the sample if the sample is meant to be a 24 bit value? Why is it looking at the 3rd byte of an SInt32 and casting to an SInt8?

I am very confused. Kudos to anyone who can explain it to me!

Upvotes: 4

Views: 2361

Answers (1)

hotpaw2
hotpaw2

Reputation: 70673

The top 8 bits of a 24-bit number are the most significant part. The remaining less significant part is too small, relative to full-scale, to display on an iPhone display. The most significant 8-bits are located in the 3rd byte of a little-endian 24 bit data type in memory.

Upvotes: 5

Related Questions