objective c - How to play a signal with AudioUnit (iOS)? -
i need generate signal , play iphone's speakers or headset.
to generate interleaved signal. need instantiate audiounit inherited class object next info: 2 channels, 44100 khz sample rate, buffer size store few frames.
then need write callback method take chink of signal , pit iphone's output buffer.
the problem have no idea how write audiounit inherited class. can't understand apple's documentation regarding it, , examples find either read file , play huge lag or use depricated constructions.
i start think stupid or something. please, help...
to play audio iphone's hardware audiounit
, don't derive audiounit
coreaudio c framework - instead give render callback in feed unit audio samples. following code sample shows how. need replace assert
s real error handling , you'll want change or @ least inspect audio unit's sample format using kaudiounitproperty_streamformat
selector. format happens 48khz floating point interleaved stereo.
static osstatus rendercallback( void* inrefcon, audiounitrenderactionflags* ioactionflags, const audiotimestamp* intimestamp, uint32 inbusnumber, uint32 innumberframes, audiobufferlist* iodata) { // inrefcon contains cookie // write innumberframes iodata->mbuffers[i].mdata here return noerr; } audiounit createaudiounit() { audiounit au; osstatus err; audiocomponentdescription desc; desc.componenttype = kaudiounittype_output; desc.componentsubtype = kaudiounitsubtype_remoteio; desc.componentmanufacturer = kaudiounitmanufacturer_apple; desc.componentflags = 0; desc.componentflagsmask = 0; audiocomponent comp = audiocomponentfindnext(null, &desc); assert(0 != comp); err = audiocomponentinstancenew(comp, &au); assert(0 == err); aurendercallbackstruct input; input.inputproc = rendercallback; input.inputprocrefcon = 0; // put cookie here err = audiounitsetproperty(au, kaudiounitproperty_setrendercallback, kaudiounitscope_input, 0, &input, sizeof(input)); assert(0 == err); err = audiounitinitialize(au); assert(0 == err); err = audiooutputunitstart(au); assert(0 == err); return au; }
Comments
Post a Comment