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>