iphone - AudioUnit Input Samples -


so having trouble here audiounit taking in data microphone/line-in in ios. able set think okay , calling recordingcallback, data getting out of buffer not correct. returns same thing, zeros , random large numbers. know causing this. code follows.

setting audio unit

osstatus status;  // describe audio component audiocomponentdescription desc; desc.componenttype = kaudiounittype_output; desc.componentsubtype = kaudiounitsubtype_remoteio; desc.componentflags = 0; desc.componentflagsmask = 0; desc.componentmanufacturer = kaudiounitmanufacturer_apple;  // component audiocomponent inputcomponent = audiocomponentfindnext(null, &desc); status = audiocomponentinstancenew(inputcomponent, &audiounit);  // enable io recording uint32 flag = 1; status = audiounitsetproperty(audiounit,                                kaudiooutputunitproperty_enableio,                                kaudiounitscope_input,                                kinputbusnumber,                               &flag,                                sizeof(flag)); // disable playback io flag = 0; status = audiounitsetproperty(audiounit,                                kaudiooutputunitproperty_enableio,                                kaudiounitscope_output,                                koutputbusnumber,                               &flag,                                sizeof(flag));  // describe format audiostreambasicdescription audioformat; audioformat.msamplerate         = 44100.00; audioformat.mformatid           = kaudioformatlinearpcm; audioformat.mformatflags        = kaudioformatflagsnativefloatpacked |kaudioformatflagisnoninterleaved; audioformat.mframesperpacket    = 1; audioformat.mchannelsperframe   = 1; audioformat.mbitsperchannel     = 32; audioformat.mbytesperpacket     = 4; audioformat.mbytesperframe      = 4;  // apply format status = audiounitsetproperty(audiounit,                                kaudiounitproperty_streamformat,                                kaudiounitscope_output,                                kinputbusnumber,                                &audioformat,                                sizeof(audioformat));  // set input callback aurendercallbackstruct callbackstruct; callbackstruct.inputproc = recordingcallback; callbackstruct.inputprocrefcon = (__bridge void*)self; status = audiounitsetproperty(audiounit,                                kaudiooutputunitproperty_setinputcallback,                                kaudiounitscope_global,                                kinputbusnumber,                                &callbackstruct,                                sizeof(callbackstruct)); status = audiounitinitialize(audiounit); 

input callback

static osstatus recordingcallback(void *inrefcon,                                    audiounitrenderactionflags *ioactionflags,                                    const audiotimestamp *intimestamp,                                    uint32 inbusnumber,                                    uint32 innumberframes,                                    audiobufferlist *iodata) {      audiobufferlist bufferlist;     bufferlist.mnumberbuffers = 1;     bufferlist.mbuffers[0].mdatabytesize = 4;     bufferlist.mbuffers[0].mnumberchannels = 1;     bufferlist.mbuffers[0].mdata = malloc(sizeof(float)*innumberframes); //     inputaudio *input = (__bridge inputaudio*)inrefcon;      osstatus status;      status = audiounitrender([input audiounit],                               ioactionflags,                               intimestamp,                               inbusnumber,                               innumberframes,                               &bufferlist);      float* result = (float*)&bufferlist.mbuffers[0].mdata;      if (input->counter == 5) {         (int = 0;i<innumberframes;i++) {             printf("%f ",result[i]);         }     }     input->counter++;     return noerr; } 

anyone ever encounter similar problem or see wrong in code. in advance help!

i basing of off of michael tysons core audio remoteio code

if remember correctly, samples audio buffer in callback aren't floats, they're sint16. try casting samples this:

sint16 *sn16audiodata= (sint16 *)(bufferlist.mbuffers[0].mdata); 

and these should max , min values:

#define sn16_max_sample_value 32767 #define sn16_min_sample_value -32768 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -