IOS audio Queue Service

Source: Internet
Author: User

The audio Queue Service provides the possibility of filling the audio data block into the audio queue service buffer to play the sound. This method is similar.
The waveoutwrite method in windows. In this way, we can use this method to play the audio data transmitted from the network.
We need to fill the buffer in the aqoutputcallback callback provided by the queue service. Here we can fill in the data transmitted from the network.
 
See the Code:
Audiostreambasicdescription format; // audio format settings, which must be consistent with the configuration in the collection set
Memset (& format, 0, sizeof (Format ));
 
Format. msamplerate = 44100; // sampling rate (Stereo = 8000)
Format. mformatid = kaudioformatlinearpcm; // PCM format
Format. mformatflags = klinearpcmformatflagissignedinteger | klinearpcmformatflagispacked;
Format. mchannelsperframe = 1; // 1: Mono; 2: stereo
Format. mbitsperchannel = 16; // number of digits occupied by voice at each sampling point
Format. mbytesperframe = (format. mbitsperchannel/* format. mchannelsperframe;
Format. mframesperpacket = 1;
Format. mbytesperpacket = format. mbytesperframe * format. mframesperpacket;
 
Audioqueueref queue;
Audioqueuenewoutput (& format,
Aqplayer: aqoutputcallback,
This, // opaque reference to whatever you like
Cfrunloopgetcurrent (),
Kcfrunloopcommonmodes,
0,
& Queue );
 
Const int buffersize = 0xa000; // 48 k-around und 1/2 sec of 44 kHz 16 bit mono PCM
For (INT I = 0; I <knumberbuffers; ++ I)
Audioqueueallocatebufferwithpacketdescriptions (queue, buffersize, 0, & mbuffers [I]);
 
Audioqueuesetparameter (queue, kaudioqueueparam_volume, 1.0 );
 
Uint32 Category = kaudiosessioncategory_mediaplayback;
Audiosessionsetproperty (kaudiosessionproperty_audiocategory, sizeof (category), & category );
 
Audiosessionsetactive (true );
 
// Prime the queue with some data before starting
For (INT I = 0; I <knumberbuffers; ++ I)
Outputcallback (queue, mbuffers [I]);
 
Audioqueuestart (queue, null );
 
Enter data in callback:
 
Void outputcallback (void * inuserdata, audioqueueref inaq, audioqueuebufferref incompleteaqbuffer ){
// Fill
// Aqplayer * That = (aqplayer *) inuserdata;
Incompleteaqbuffer-> maudiodatabytesize = Next-> maudiodatabytescapacity;
For (INT I = 0; I <incompleteaqbuffer-> maudiodatabytesize; ++ I)
Next-> maudiodata [I] = rand ();
Audioqueueenqueuebuffer (queue, incompleteaqbuffer, 0, null );
}

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.