Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between AudioManager's stream types at low level?

There are several stream types in AudioManager. How did they differ at low level? Could it be that usage of e.g. AudioManager.STREAM_MUSIC blocks input microphone stream? Or something else?

like image 534
Kirill Boyarshinov Avatar asked Jul 09 '14 11:07

Kirill Boyarshinov


1 Answers

As usual, whatever you Google won't document can (sometimes) be understood from the code

https://android.googlesource.com/platform/frameworks/base/+/00ccd5d026fcd0e4b9d27dc5a9ffa13ca0408449/media/java/android/media/AudioService.java

As for blocking, it's not really that streams block one another, it's just that modes block things. MODE_IN_COMMUNICATION blocks most of the streams.

Ducking: A common and "polite" behaviour when playing a long running stream (e.g. MUSIC) is to listen to an audio focus callback and lower the volume of your stream manually upon "can duck" event. The volume should return to its previous level when the focus returns to your stream.

The stream type affects the volume that streams contributes to the sum of all sounds at a given time:

   /** @hide Maximum volume index values for audio streams */
private int[] MAX_STREAM_VOLUME = new int[] {
    5,  // STREAM_VOICE_CALL
    7,  // STREAM_SYSTEM
    7,  // STREAM_RING
    15, // STREAM_MUSIC
    7,  // STREAM_ALARM
    7,  // STREAM_NOTIFICATION
    15, // STREAM_BLUETOOTH_SCO
    7,  // STREAM_SYSTEM_ENFORCED
    15, // STREAM_DTMF
    15  // STREAM_TTS

This array from AudioService.java shows the default maximum volume for a given stream. Other code:

    private void readPersistedSettings() {
    final ContentResolver cr = mContentResolver;
    mRingerMode = System.getInt(cr, System.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
    mVibrateSetting = System.getInt(cr, System.VIBRATE_ON, 0);
    mRingerModeAffectedStreams = Settings.System.getInt(cr,
            Settings.System.MODE_RINGER_STREAMS_AFFECTED,
            ((1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_NOTIFICATION)|
             (1 << AudioSystem.STREAM_SYSTEM)|(1 << AudioSystem.STREAM_SYSTEM_ENFORCED)));
    mMuteAffectedStreams = System.getInt(cr,
            System.MUTE_STREAMS_AFFECTED,
            ((1 << AudioSystem.STREAM_MUSIC)|(1 << AudioSystem.STREAM_RING)|(1 << AudioSystem.STREAM_SYSTEM)));
    mNotificationsUseRingVolume = System.getInt(cr,
            Settings.System.NOTIFICATIONS_USE_RING_VOLUME, 1);

seems to indicate what streams are muted or reduced in volume when the phone starts 'ringing' or when a call is in progress.

like image 184
Meymann Avatar answered Oct 08 '22 21:10

Meymann