Int I, bufferbytesize;
Uint32 size;
Cfurlref URL;
Readarri = 0;
Try {
Mfilename = cfstringcreatecopy (kcfallocatordefault, inrecordfile );
// Specify the recording format
Setupaudioformat (kaudioformatlinearpcm );
// Create the queue
Xthrowiferror (audioqueuenewinput (
& Mrecordformat,
Myinputbufferhandler,
This/* userdata */,
Null/* Run loop */, null /*
Run loop mode */,
0/* flags */, & mqueue), "audioqueuenewinput
Failed ");
// Get the record format back from the queue's Audio Converter --
// The file may require a more specific stream description than was necessary to create the encoder.
Mrecordpacket = 0;
Size = sizeof (mrecordformat );
Xthrowiferror (audioqueuegetproperty (mqueue, kaudioqueueproperty_streamdescription,
& Mrecordformat, & size), "couldn't get queue's format ");
Nsstring * recordfile = [nstemporarydirectory () stringbyappendingpathcomponent:
(Nsstring *) inrecordfile];
Url = cfurlcreatewithstring (kcfallocatordefault, (cfstringref) recordfile, null );
// Create the audio file
Xthrowiferror (audiofilecreatewithurl (URL, kaudiofilecaftype,
& Mrecordformat, kaudiofileflags_erasefile,
& Mrecordfile), "audiofilecreatewithurl failed ");
Cfrelease (URL );
// Copy the cookie first to give the file object as much info as we can about the data going in
// Not necessary for PCM, but required for some compressed audio
Copyencodercookietofile ();
// Allocate and enqueue Buffers
Bufferbytesize = computerecordbuffersize (& mrecordformat, kbufferdurationseconds );//
Enough bytes for half a second
For (I = 0; I <knumberrecordbuffers; ++ I ){
Xthrowiferror (audioqueueallocatebuffer (mqueue, bufferbytesize, & mbuffers [I]),
"Audioqueueallocatebuffer failed ");
Xthrowiferror (audioqueueenqueuebuffer (mqueue, mbuffers [I], 0, null ),
"Audioqueueenqueuebuffer failed ");
}
// Start the queue
Misrunning = true;
Xthrowiferror (audioqueuestart (mqueue, null), "audioqueuestart
Failed ");
}
Catch (caxexception & E ){
Char Buf [256];
Fprintf (stderr, "error: % s (% s) \ n", E. moperation, E. formaterror (BUF ));
}
Catch (...){
Fprintf (stderr, "an unknown
Error occurred \ n ");
}