How to read a wav in iPhone
How to read a wav in iPhone
- Subject: How to read a wav in iPhone
- From: Gabriele Palmas <email@hidden>
- Date: Mon, 23 Feb 2009 21:16:09 -0500
Hi all,
i'm trying to do the following with an iPhone: Wav file->Mixer->Output Obviously Mixer and Output are AU. The default AU that reads file (type generator) is not available on iPhone. So the only option remain is to use and InputCallBack for the mixer node. Here starts my trouble: I have to write this function that feeds the mixer when it needs packets. I'm confuse about the structure I have to use define my data and my buffer. Here is what I have done:
typedef struct
{
AudioStreamBasicDescription asbd;
float *data;
UInt32 numFrames;
UInt32 phase;
NSString *name;
} SndBuf;
#define MAXBUFS 8
typedef struct
{ bool playing;
AudioFileID audioFile;
int numbufs;
SndBuf bufs[MAXBUFS];
int select;
} SynthData;
Now if this is correct I have not idea how to get the data out of the file. I would like also to give you my RenderCallBack function so you have better understanding:
OSStatus renderInput(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
{
SynthData d = *(SynthData*)inRefCon; // get access to Sinewave's data
UInt32 bufSamples = d.bufs[inBusNumber].numFrames << 1;
float *in = d.bufs[inBusNumber].data;
float *outA = (float*)ioData->mBuffers[0].mData;
float *outB = (float*)ioData->mBuffers[1].mData;
if (!in) {
for (UInt32 i=0; i<inNumberFrames; ++i)
{
outA[i] = 0.f;
outB[i] = 0.f;
}
} else {
UInt32 phase = d.bufs[inBusNumber].phase;
for (UInt32 i=0; i<inNumberFrames; ++i)
{
outA[i] = in[phase++];
outB[i] = in[phase++];
if (phase >= bufSamples) phase = 0;
}
d.bufs[inBusNumber].phase = phase;
}
return noErr;
}
I got this out of the only exampple that uses RenderCallBack in my entire system that is called MixerController. Can anyone please help me?
Thanks.
Gab
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden