In-depth analysis of Android audio AudioSystem and androidaudiosystem

Source: Internet
Author: User

In-depth analysis of Android audio AudioSystem and androidaudiosystem

AudioSystem is an interface class provided by AudioPolicyService and AudioFlinger.


One of Android Audio systems: How does AudioTrack exchange with AudioFlinger?

In the Audio Subsystem of Android Framework, each audio stream corresponds to an AudioTrack instance, and each AudioTrack is registered to AudioFlinger at creation, audioFlinger is used to mix all audiotracks and then deliver them to AudioHardware for playback. Currently, Froyo of Android allows you to create up to 32 audio streams at the same time. That is to say, mixer processes a maximum of 32 AudioTrack data streams simultaneously. The main code for how to use AudioTrackAudioTrack is located in frameworks/base/media/libmedia/audiotrack. cpp. Now let's take an example to learn how to use AudioTrack. ToneGenerator is an implementation of Telephone Dialing and other tone waveforms in android. We will take it as an example: the initialization function of ToneGenerator: bool ToneGenerator: initAudioTrack () {// Open audio track in mono, PCM 16bit //, default sampling rate, default buffer size mpAudioTrack = new AudioTrack (); mpAudioTrack-> set (mStreamType, 0, AudioSystem: PCM_16_BIT, AudioSystem: CHANNEL_OUT_MONO, 0, 0, audioCallback, this, 0, 0, mThreadCanCallJava ); If (mpAudioTrack-> initCheck ()! = NO_ERROR) {LOGE ("AudioTrack-> initCheck failed"); goto initAudioTrack_exit;} mpAudioTrack-> setVolume (mVolume, mVolume); mState = TONE_INIT ;......} it can be seen that the creation process is very simple. First, a new AudioTrack instance is created, and then the set member function is called to complete parameter settings and register it in AudioFlinger, then, you can call other functions such as setting the volume to further set the audio parameters. An important parameter is audioCallback. audioCallback is a callback function that responds to AudioTrack notifications, such as data filling, loop playback, and playing position triggering. The callback function is usually written as follows: void ToneGenerator: audioCallback (int event, void * user, void * info) {if (event! = AudioTrack: EVENT_MORE_DATA) return; AudioTrack: Buffer * buffer = static_cast <AudioTrack: Buffer *> (info); ToneGenerator * lpToneGen = static_cast <ToneGenerator *> (user ); short * lpOut = buffer-> i16; unsigned int lNumSmp = buffer-> size/sizeof (short); const ...... remaining full text>

One of Android Audio systems: How does AudioTrack exchange with AudioFlinger?

In the Audio Subsystem of Android Framework, each audio stream corresponds to an AudioTrack instance, and each AudioTrack is registered to AudioFlinger at creation, audioFlinger is used to mix all audiotracks and then deliver them to AudioHardware for playback. Currently, Froyo of Android allows you to create up to 32 audio streams at the same time. That is to say, mixer processes a maximum of 32 AudioTrack data streams simultaneously. The main code for how to use AudioTrackAudioTrack is located in frameworks/base/media/libmedia/audiotrack. cpp. Now let's take an example to learn how to use AudioTrack. ToneGenerator is an implementation of Telephone Dialing and other tone waveforms in android. We will take it as an example: the initialization function of ToneGenerator: bool ToneGenerator: initAudioTrack () {// Open audio track in mono, PCM 16bit //, default sampling rate, default buffer size mpAudioTrack = new AudioTrack (); mpAudioTrack-> set (mStreamType, 0, AudioSystem: PCM_16_BIT, AudioSystem: CHANNEL_OUT_MONO, 0, 0, audioCallback, this, 0, 0, mThreadCanCallJava ); If (mpAudioTrack-> initCheck ()! = NO_ERROR) {LOGE ("AudioTrack-> initCheck failed"); goto initAudioTrack_exit;} mpAudioTrack-> setVolume (mVolume, mVolume); mState = TONE_INIT ;......} it can be seen that the creation process is very simple. First, a new AudioTrack instance is created, and then the set member function is called to complete parameter settings and register it in AudioFlinger, then, you can call other functions such as setting the volume to further set the audio parameters. An important parameter is audioCallback. audioCallback is a callback function that responds to AudioTrack notifications, such as data filling, loop playback, and playing position triggering. The callback function is usually written as follows: void ToneGenerator: audioCallback (int event, void * user, void * info) {if (event! = AudioTrack: EVENT_MORE_DATA) return; AudioTrack: Buffer * buffer = static_cast <AudioTrack: Buffer *> (info); ToneGenerator * lpToneGen = static_cast <ToneGenerator *> (user ); short * lpOut = buffer-> i16; unsigned int lNumSmp = buffer-> size/sizeof (short); const ...... remaining full text>

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.