Function calls for iOS recording

Source: Internet
Author: User

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 ");

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.