Android and Audio Formats/Sampling Rates

If you want to really geek out on this stuff and know how to connect the Android debugger to your phone, you can inspect what’s going on while your music is playing.

adb shell dumpsys media.audio_flinger

The result of this command will list multiple outputs. You want to find the one that says 1 Tracks of which 1 are active.

If I’m playing a CD quality FLAC rip from Neutron, I get something like this:

Output thread 0xe1634000, name AudioOut_AF5, tid 7875, type 1 (DIRECT):
  I/O handle: 2805
  Standby: no
  Sample rate: 44100 Hz
  HAL frame count: 1792
  HAL format: 0x6 (AUDIO_FORMAT_PCM_24_BIT_PACKED)
  HAL buffer size: 10752 bytes
  Channel count: 2
  Channel mask: 0x00000003 (front-left, front-right)
  Processing format: 0x6 (AUDIO_FORMAT_PCM_24_BIT_PACKED)
  Processing frame size: 6 bytes
  Pending config events: none
  Output device: 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
  Input device: 0 (AUDIO_DEVICE_NONE)
  Audio source: 0 (default)
  Normal frame count: 1792
  Last write occurred (msecs): 34
  Total writes: 1960
  Delayed writes: 0
  Blocked in write: yes
  Suspend count: 0
  Sink buffer : 0xe1389000
  Mixer buffer: 0xe20d9800
  Effect buffer: 0xe31e3800
  Fast track availMask=0xfe
  Standby delay ns=1000000000
  AudioStreamOut: 0xe4587940 flags 0x1 (AUDIO_OUTPUT_FLAG_DIRECT)
  Frames written: 3512320
  Suspended frames: 0
  Hal stream dump:
  Stream volumes in dB: 0:-10, 1:-25, 2:-19, 3:-17, 4:-23, 5:-23, 6:0, 7:-18, 8:-21, 9:-96, 10:-22, 11:0, 12:0
  Normal mixer raw underrun counters: partial=0 empty=0
  1 Tracks of which 1 are active
    Name Active Client Type      Fmt Chn mask Session fCount S F SRate  L dB  R dB  VS dB    Server Main buf  Aux buf Flags UndFrmCnt  Flushed
    none    yes   8660    3 00000006 00000003    3817   6720 A 3 44100     0     0     0   00359F00 E1389000 00000000 0x000         0        0
  0 Effect Chains
  Local log:
   04-06 07:54:22.428 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE) new device 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
   04-06 07:54:22.441 addTrack_l    (0xe220ee00) none     no   8660    3 00000006 00000003    3817   6720 A 1 44100     0     0     0   00000000 E1389000 00000000 0x000         0        0

I can see that the sample rate is correct at 441000 Hz and that it’s using DIRECT output (which means we’re bypassing the mixer). The fact that the audio stream is in 24 bit is actually crucial here. My source file is 16 bit, however players like Neutron and UAPP pad everything to 24 bits as a trick to bypass Android’s mixer, which only handles 16 bit audio.

When playing something from Google Play Music, I get this:

Output thread 0xe1608000, name AudioOut_AFD, tid 8447, type 4 (OFFLOAD):
  I/O handle: 2813
  Standby: no
  Sample rate: 44100 Hz
  HAL frame count: 65536
  HAL format: 0x1000000 (AUDIO_FORMAT_MP3)
  HAL buffer size: 65536 bytes
  Channel count: 2
  Channel mask: 0x00000003 (front-left, front-right)
  Processing format: 0x1000000 (AUDIO_FORMAT_MP3)
  Processing frame size: 1 bytes
  Pending config events: none
  Output device: 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
  Input device: 0 (AUDIO_DEVICE_NONE)
  Audio source: 0 (default)
  Normal frame count: 65536
  Last write occurred (msecs): 1184
  Total writes: 7
  Delayed writes: 0
  Blocked in write: no
  Suspend count: 0
  Sink buffer : 0xe45db000
  Mixer buffer: 0xe0f80000
  Effect buffer: 0xe1883000
  Fast track availMask=0xfe
  Standby delay ns=1000000000
  AudioStreamOut: 0xe4587500 flags 0x31 (AUDIO_OUTPUT_FLAG_DIRECT|AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD|AUDIO_OUTPUT_FLAG_NON_BLOCKING)
  Frames written: 200620
  Suspended frames: 0
  Hal stream dump:
  Stream volumes in dB: 0:-10, 1:-25, 2:-19, 3:-17, 4:-23, 5:-23, 6:0, 7:-18, 8:-21, 9:-96, 10:-22, 11:0, 12:0
  Normal mixer raw underrun counters: partial=0 empty=0
  1 Tracks of which 1 are active
    Name Active Client Type      Fmt Chn mask Session fCount S F SRate  L dB  R dB  VS dB    Server Main buf  Aux buf Flags UndFrmCnt  Flushed
    none    yes   7236    3 01000000 00000003    3793  65536 A 3 44100     0     0     0   00040FAC E45DB000 00000000 0x000    192596        0
  0 Effect Chains
  Local log:
   04-06 07:58:10.039 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE) new device 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
   04-06 07:58:10.047 addTrack_l    (0xe317e800) none     no   7236    3 01000000 00000003    3793  65536 A 1 44100     0     0     0   00000000 E45DB000 00000000 0x000         0        0

Interestingly this is not using the MIXER output but rather OFFLOAD because it’s actually delegating MP3 decoding to the hardware level. I’m not really sure if/how the mixer is involved in this particular path.

And lastly here’s what it looks like when I’m playing a podcast from Castbox.

Output thread 0xe3303a00, name AudioOut_15, tid 1668, type 0 (MIXER):
  I/O handle: 21
  Standby: no
  Sample rate: 48000 Hz
  HAL frame count: 1920
  HAL format: 0x1 (AUDIO_FORMAT_PCM_16_BIT)
  HAL buffer size: 7680 bytes
  Channel count: 2
  Channel mask: 0x00000003 (front-left, front-right)
  Processing format: 0x1 (AUDIO_FORMAT_PCM_16_BIT)
  Processing frame size: 4 bytes
  Pending config events: none
  Output device: 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
  Input device: 0 (AUDIO_DEVICE_NONE)
  Audio source: 0 (default)
  Normal frame count: 1920
  Last write occurred (msecs): 23
  Total writes: 81157
  Delayed writes: 0
  Blocked in write: yes
  Suspend count: 0
  Sink buffer : 0xe4a63000
  Mixer buffer: 0xe4345000
  Effect buffer: 0xe4a71000
  Fast track availMask=0xfe
  Standby delay ns=3000000000
  AudioStreamOut: 0xe4a5af20 flags 0x8 (AUDIO_OUTPUT_FLAG_DEEP_BUFFER)
  Frames written: 155821440
  Suspended frames: 0
  Hal stream dump:
  Thread throttle time (msecs): 966
  AudioMixer tracks: 0x00000001
  Master mono: off
  No FastMixer
  Stream volumes in dB: 0:-10, 1:-25, 2:-19, 3:-17, 4:-23, 5:-23, 6:0, 7:-18, 8:-21, 9:-96, 10:-22, 11:0, 12:0
  Normal mixer raw underrun counters: partial=0 empty=0
  1 Tracks of which 1 are active
    Name Active Client Type      Fmt Chn mask Session fCount S F SRate  L dB  R dB  VS dB    Server Main buf  Aux buf Flags UndFrmCnt  Flushed
       0    yes   8569    3 00000001 00000001    3825  14144 A 3 44100     0     0     0   000143DC E4A63000 00000000 0x000      1768        0
  0 Effect Chains
  Local log:
   04-05 11:52:31.785 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 11:52:31.790 addTrack_l    (0xe220df00)    0     no   6441    3 00000001 00000003    2265  14144 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 11:53:19.283 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 11:53:21.002 removeTrack_l (0xe220df00)    0     no   6441    3 00000001 00000003    2265  14144 T 1 44100     0     0     0   0020F220 E4A63000 00000000 0x404         0        0
   04-05 12:00:07.392 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-05 13:06:44.465 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 13:06:44.467 addTrack_l    (0xe317e200)    0     no   6441    3 00000001 00000003    2265  14144 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 13:06:52.286 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 13:06:53.527 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 13:06:54.286 removeTrack_l (0xe317e200)    0     no   6441    3 00000001 00000003    2265  14144 T 1 44100     0     0     0   000675C0 E4A63000 00000000 0x404         0        0
   04-05 13:06:54.464 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-05 13:13:48.705 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 13:13:48.710 addTrack_l    (0xe220f100)    0     no   6441    3 00000001 00000003    2265  14144 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 13:19:05.366 removeTracks_l(0xe220f100)    0     no   6441    3 00000001 00000003    2265  14144 P 3 44100     0     0     0   00D4F6A0 E4A63000 00000000 0x400         0        0
   04-05 14:52:54.233 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-05 15:51:24.057 removeTrack_l (0xe220f100)    0     no   6441    3 00000001 00000003    2265  14144 T 3 44100     0     0     0   00D4F6A0 E4A63000 00000000 0x400         0        0
   04-05 17:08:28.206 removeTrack_l (0xe220e380)    0     no   2488    3 00000001 00000003    2633   1772 T 0 22050     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 17:08:53.328 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x1 (AUDIO_DEVICE_OUT_EARPIECE)
   04-05 17:08:55.758 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x1 (AUDIO_DEVICE_OUT_EARPIECE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 17:12:56.046 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0x1 (AUDIO_DEVICE_OUT_EARPIECE)
   04-05 17:13:23.069 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x1 (AUDIO_DEVICE_OUT_EARPIECE) new device 0 (AUDIO_DEVICE_NONE)
   04-05 17:29:13.474 removeTrack_l (0xe317d480)    1     no   2488    3 00000001 00000003    2777   1772 T 0 22050     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 17:36:44.845 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x1 (AUDIO_DEVICE_OUT_EARPIECE)
   04-05 17:36:47.543 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0x1 (AUDIO_DEVICE_OUT_EARPIECE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 17:39:32.907 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-05 17:39:34.283 addTrack_l    (0xe317da80)    0     no  16344    3 00000001 00000003    2737  33075 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x004         0        0
   04-05 17:39:34.539 removeTrack_l (0xe317da80)    0     no  16344    3 00000001 00000003    2737  33075 T 1 44100     0     0     0   000014AC E4A63000 00000000 0x404         0        0
   04-05 17:39:34.580 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 17:52:24.811 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-05 23:31:38.594 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-05 23:31:38.595 addTrack_l    (0xe317d180)    0     no   7800    3 00000001 00000003    3673  24960 A 1 48000  -inf  -inf     0   00000000 E4A63000 00000000 0x000         0        0
   04-05 23:31:41.278 removeTrack_l (0xe317d180)    0     no   7800    3 00000001 00000003    3673  24960 T 1 48000  -inf  -inf     0   0001C980 E4A63000 00000000 0x601      1922    21120
   04-05 23:58:26.878 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-06 00:08:52.907 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
   04-06 00:08:52.916 addTrack_l    (0xe317e500)    0     no  18361    3 00000001 00000003    3713  14144 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x000         0        0
   04-06 00:09:00.879 removeTracks_l(0xe317e500)    0     no  18361    3 00000001 00000003    3713  14144 P 3 44100     0     0     0   000538C8 E4A63000 00000000 0x400      1768        0
   04-06 00:22:44.784 removeTrack_l (0xe317e500)    0     no  18361    3 00000001 00000003    3713  14144 T 1 44100     0     0     0   000538C8 E4A63000 00000000 0x600      1768    14144
   04-06 07:47:37.847 CFG_EVENT_RELEASE_AUDIO_PATCH: old device 0x2 (AUDIO_DEVICE_OUT_SPEAKER) new device 0 (AUDIO_DEVICE_NONE)
   04-06 07:59:38.871 CFG_EVENT_CREATE_AUDIO_PATCH: old device 0 (AUDIO_DEVICE_NONE) new device 0x8 (AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
   04-06 07:59:38.878 addTrack_l    (0xe220f100)    0     no   8569    3 00000001 00000001    3825  14144 A 1 44100     0     0     0   00000000 E4A63000 00000000 0x000         0        0

This is going through the mixer at 48 KHz sample rate.

6 Likes