I am trying to play a 48kHz , 24 bit .pcm file using core audio. But I hear only noise. I am using the PlayFile sample with some modifications,
I do not want to use a FilePlayer unit.
In MakeSimpleGraph() I only create the output unit and set its format according to the .pcm files ASBD
absd.Print() gives:
format: ABSD: 2 ch, 8000 Hz, 'lpcm' (0x0000000C) 24-bit little-endian signed integer
//create a default output unit
...
// set the input callback for the output unit here :
renderCallbackStruct.inputProc = RenderProc;
AudioUnitSetProperty(outputUnit, kAudioUnitProperty_SetRenderCallback ... )
//set the output format for the output unit
CAAudioUnit outputAU = CAAudioUnit(outputNode,outputUnit);
XThrowIfError(outputAU.SetFormat(kAudioUnitScope_Input,0,absd),"Set Format");
In my Input Callback RenderProc, i read and copy the file data into the ioData->mBuffers.
This works correctly for a bit depth of 16, but for bit depths of 24,I hear noise.
And for a .pcm file with bit depth of 32, i dont hear anything. How should I copy data for bit depth other than 16 bits ?
RenderProc(params...)
{
OSStatus err= noErr;
if(feof(fp))
{
ioData->mBuffers[0].mData = NULL;
ioData->mBuffers[0].mDataByteSize = 0;
}
// The data is in interleaved format
//read the pcm data into the buffer
fread(ioData->mBuffers[0].mData,ioData->mBuffers[0].mDataByteSize,1,fp);
return err;
}
I saw some samples casting the iodata->mBuffers[0] to a Float32* and using it, How to do this for 24/32 bits ?
Thanks
Hari