ios - Audio Queue Service Example using How to record sound in mp3 format in iPhone -
i new in ios developement.i have downloaded sample audio recorder project https://github.com/vecter/audio-queue-services-example using audio queue service of audiotoolbox framework .in sample project recorded audio format .aif. while run downloaded sample project working fine.in sample example project using how record audio .mp3 format .how can this?
simply have changed kaudiofileaifftype kaudiofilemp3type getting message nslog
//---------nslog message-------------- not recording, returning writing buffer 0 //------------------ - (void)startrecording { [self setupaudioformat:&recordstate.dataformat]; recordstate.currentpacket = 0; osstatus status; status = audioqueuenewinput(&recordstate.dataformat, audioinputcallback, &recordstate, cfrunloopgetcurrent(), kcfrunloopcommonmodes, 0, &recordstate.queue); if (status == 0) { // prime recording buffers empty data (int = 0; < num_buffers; i++) { audioqueueallocatebuffer(recordstate.queue, 16000, &recordstate.buffers[i]); audioqueueenqueuebuffer (recordstate.queue, recordstate.buffers[i], 0, null); } status = audiofilecreatewithurl(fileurl, kaudiofilemp3type, &recordstate.dataformat, kaudiofileflags_erasefile, &recordstate.audiofile); if (status == 0) { recordstate.recording = true; status = audioqueuestart(recordstate.queue, null); if (status == 0) { labelstatus.text = @"recording"; } } } if (status != 0) { [self stoprecording]; labelstatus.text = @"record failed"; } }
//---------------------------------------------------------------------------
- (void)startplayback { playstate.currentpacket = 0; [self setupaudioformat:&playstate.dataformat]; osstatus status; status = audiofileopenurl(fileurl, kaudiofilereadpermission, kaudiofilemp3type, &playstate.audiofile); if (status == 0) { status = audioqueuenewoutput(&playstate.dataformat, audiooutputcallback, &playstate, cfrunloopgetcurrent(), kcfrunloopcommonmodes, 0, &playstate.queue); if (status == 0) { // allocate , prime playback buffers playstate.playing = true; (int = 0; < num_buffers && playstate.playing; i++) { audioqueueallocatebuffer(playstate.queue, 16000, &playstate.buffers[i]); audiooutputcallback(&playstate, playstate.queue, playstate.buffers[i]); } status = audioqueuestart(playstate.queue, null); if (status == 0) { labelstatus.text = @"playing"; } } } if (status != 0) { [self stopplayback]; labelstatus.text = @"play failed"; } }
no cannot record mp3. reason behind explained in core audio documentation (page no 51 of core audio pdf).
in own words->
ios contains recording codecs listed in table 2-5. can see, neither mp3 nor aac recording available. this due high cpu overhead, , consequent battery drain, of these formats.
ios: recording audio formats
- apple lossless
- ilbc (internet low bitrate codec, speech codec)
- ima/adpcm (also known ima-4)
- linear pcm
- µμlaw , alaw
Comments
Post a Comment