音频知识解答:为什么投屏内录的声音会比正常speaker播放的声音小?

投屏内录音频变小原因及解决方法

背景:

以前经常发现系统投屏在内录声音时候,传递的音频数据声音明显比正常情况下手机的声音小很多,当然为了测试方便也可以不需要投屏场景,大家可以考虑直接手机对声音进行内录,然后进行播放,在同一个设备上进行对比更加明显。那么这个
到底是为什么呢?学了audio框架课程的音量调节后我们来分析一下相关的原因。

所以我们的分析该问题首先复现该问题思路流程如下:

在这里插入图片描述
测试复现过程中注意:大家播放时候一定要都是使用自己写的代码AudioTrack播放,切勿使用一个阶段mp3,另一个阶段使用AudioTrack播放pcm,让二者这块本身有差异,导致可能播放的OutputThread等都不一致。

原因调研剖析

正常播放情况:

Output thread 0x6ffbca0880, name AudioOut_15, tid 1874, 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 devices: 0x2 (AUDIO_DEVICE_OUT_SPEAKER)
  Input device: 0 (AUDIO_DEVICE_NONE)
  Audio source: 0 (AUDIO_SOURCE_DEFAULT)
  Timestamp stats: n=4670 disc=28 cold=0 nRdy=0 err=13 rate=0.999998 jitterMs(ave=3.11586e-05 std=0.214696 min=-2.34047 max=2.15641) localSR(48000, 1.14338e-10) correctedJitterMs(ave=0.000355236 std=0.0181433 min=-0.465468 max=0.145208)
  Timestamp corrected: no
  Last write occurred (msecs): 49
  Process time ms stats: ave=1.42371 std=1.03049 min=0.491511 max=6.29083
  Hal write jitter ms stats: ave=-0.001908 std=0.847754 min=-4.07609 max=4.02198
  Threadloop write latency stats: ave=146.958 std=1.37849 min=140.084 max=148.385
  Master volume: 1.000000
  Master mute: off
  Mixer channel Mask: 0x3 (front-left, front-right)
  Normal frame count: 1920
  Total writes: 4694
  Delayed writes: 0
  Blocked in write: yes
  Suspend count: 0
  Fast track availMask=0xfe
  Standby delay ns=3000000000
  AudioStreamOut: 0x6e92e66110 flags 0x8 (AUDIO_OUTPUT_FLAG_DEEP_BUFFER)
  Frames written: 9012480
  Suspended frames: 0
  Thread throttle time (msecs): 572
  AudioMixer tracks: 86 98 
  Master mono: off
  Master balance: 0.000000 (balance 0 channelCount 2 volumes: 1 1)
  No FastMixer
Bluetooth latency modes are not enabled
HAL does not support Bluetooth latency modes
Supported latency modes: { }
  Stream volumes in dB: 0:-16, 1:-14, 2:-13, 3:0, 4:-4.8, 5:-8.7, 6:-inf, 7:-14, 8:-13, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0
  Normal mixer raw underrun counters: partial=0 empty=0
  2 Tracks of which 1 are active
    Type     Id Active Client Session Port Id S  Flags   Format Chn mask  SRate ST Usg CT  G db  L dB  R dB  VS dB  PortVol dB   Server FrmCnt  FrmRdy F Underruns  Flushed BitPerfect InternalMute   Latency
             86     no   5521     305      71 A  0x00D 00000001 00000003  44100  3   1  0    -6    -6    -6     0         -inf 000A30EC   3536       0 A     94596        0      false        false  135.94 k
             98    yes   4891     353      87 A  0x000 00000001 00000001   8000  3   1  2     0     0     0     0            0 00017C00   2592    2592 A         0        0      false        false  471.28 t

看得出播放音乐时候所在线程输出device为

 Output devices: 0x2 (AUDIO_DEVICE_OUT_SPEAKER)

在这里插入图片描述

可以看出正常情况下,这里的id为98的Active track的G db是0,也就是最大声音。

但是看看在内录声音时候的情况

Output thread 0x6ff581d880, name AudioOut_4D, tid 5859, type 0 (MIXER):
  I/O handle: 77
  Standby: no
  Sample rate: 48000 Hz
  HAL frame count: 1024
  HAL format: 0x1 (AUDIO_FORMAT_PCM_16_BIT)
  HAL buffer size: 4096 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 devices: 0x8000 (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)
  Input device: 0 (AUDIO_DEVICE_NONE)
  Audio source: 0 (AUDIO_SOURCE_DEFAULT)
  Timestamp stats: n=124 disc=1 cold=0 nRdy=0 err=0 rate=0.999947 jitterMs(ave=-0.000933826 std=2.41554 min=-10.9483 max=16.1616) localSR(48099.5, 8.55952e-06) correctedJitterMs(ave=-0.00776279 std=2.14526 min=-10.9483 max=16.1616)
  Timestamp corrected: no
  Last write occurred (msecs): 36
  Process time ms stats: ave=0.990861 std=1.06776 min=0.241823 max=10.5633
  Hal write jitter ms stats: ave=-0.320497 std=2.07707 min=-16.0205 max=2.75328
  Threadloop write latency stats: ave=62.2473 std=6.49902 min=8.23516 max=67.3149
  Master volume: 1.000000
  Master mute: off
  Mixer channel Mask: 0x3 (front-left, front-right)
  Normal frame count: 1024
  Total writes: 123
  Delayed writes: 0
  Blocked in write: yes
  Suspend count: 0
  Fast track availMask=0xfe
  Standby delay ns=3000000000
  AudioStreamOut: 0x6e92e6cba0 flags 0 (AUDIO_OUTPUT_FLAG_NONE)
  Frames written: 125952
  Suspended frames: 0
  
  Thread throttle time (msecs): 9
  AudioMixer tracks: 92 
  Master mono: off
  Master balance: 0.000000 (balance 0 channelCount 2 volumes: 1 1)
  No FastMixer
Bluetooth latency modes are not enabled
HAL does not support Bluetooth latency modes
Supported latency modes: { }
  Stream volumes in dB: 0:-16, 1:-11, 2:-8.7, 3:-33, 4:-4.8, 5:-8.7, 6:-inf, 7:-11, 8:-11, 9:0, 10:-23, 11:-21, 12:0, 13:0, 14:0
  Normal mixer raw underrun counters: partial=0 empty=0
  2 Tracks of which 1 are active
    Type     Id Active Client Session Port Id S  Flags   Format Chn mask  SRate ST Usg CT  G db  L dB  R dB  VS dB  PortVol dB   Server FrmCnt  FrmRdy F Underruns  Flushed BitPerfect InternalMute   Latency
             90     no    999       0       0 I  0x000 00000005 00000003  48000 13   f  0  -inf     0     0     0            0 00000000   3072       0 I         0        0      false        false       new
             92    yes   4891     321      81 A  0x000 00000001 00000001   8000  3   1  2   -33     0     0     0          -33 00005200   2592    2592 A         0        0      false        false  386.97 t

明显可以发现,这里的id为92的active track正在播放,他的输出设备是

 Output devices: 0x8000 (AUDIO_DEVICE_OUT_REMOTE_SUBMIX)

这个track的全局的音量系数为G db = -33
在这里插入图片描述
根据音频框架课程学习的,音量相关知识基础,可以得出内录时候投屏时候的音量为什么比较小的原因如下:

在这里插入图片描述
每个音量调节都是对应StreamType的VolumeStreamState里面mIndexMap,每个device对应的音量大小也是各自独立的,所以这个原因就导致同样是播放music这种StreamType的声音,但是明显AUDIO_DEVICE_OUT_SPEAKER发出声音大小比内录AUDIO_DEVICE_OUT_REMOTE_SUBMIX出来声音大。

就因为设备AUDIO_DEVICE_OUT_SPEAKER和设备AUDIO_DEVICE_OUT_REMOTE_SUBMIX属于不同的音量index值,需要单独针对应设备进行额外设置。

解决办法:

上面已经剖析清楚了相关直接播放的speaker声音比内录到的声音大的原因了,解决办法其实就比较简单,那就是需要针对内录情况下的设备AUDIO_DEVICE_OUT_REMOTE_SUBMIX对应的音量index和正常播放的设备AUDIO_DEVICE_OUT_SPEAKER音量index做成一致既可以。

做成一致方式很简单,可以用以下2种方式:
1、直接引导用户自己在内录声音时候要进行音量条的设置,因为这个时候输出设备是AUDIO_DEVICE_OUT_REMOTE_SUBMIX,所以音量调节就是针对这个设备的

2、直接系统框架子AudioService中,把AUDIO_DEVICE_OUT_SPEAKER的音量系数index,等比例映射到AUDIO_DEVICE_OUT_REMOTE_SUBMIX中即可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值