rk3576 sai tdm调试
RK3576 SAI TDM 调试
- 驱动
- HAL 层
- SO 修改
- SO 编译
- audio_policy_configuration.xml修改
- 调试&验证
- 调试信息
- 抓取送往驱动前的原始数据
- dumpsys
配置 SAI1 输出 16 声道数据
驱动
采用外挂 DSP 的方案,只管输出数据就行
---a/common/kernel-6.1/arch/arm64/boot/dts/rockchip/xxx.dtsi+++b/common/kernel-6.1/arch/arm64/boot/dts/rockchip/xxx.dtsi @@-91,8+91,37@@ regulator-min-microvolt=<12000000>;regulator-max-microvolt=<12000000>;};+++dummy_codec:dummy-codec{+status="okay";+compatible="rockchip,dummy-codec";+#sound-dai-cells=<0>;+};++vehicle_adsp_sound:vehicle-adsp-sound{+status="okay";+compatible="simple-audio-card";+simple-audio-card,name="rockchip,tdm";+simple-audio-card,format="dsp_b";+simple-audio-card,mclk-fs=<512>;+simple-audio-card,cpu{+sound-dai=<&sai1>;+dai-tdm-slot-num=<16>;+dai-tdm-slot-width=<32>;+};+simple-audio-card,codec{+sound-dai=<&dummy_codec>;+};+};};+&es8388_sound{+status="disabled";+};HAL 层
SO 修改
源码路径:hardware/rockchip/audio/tinyalsa_hal/audio_hw.c
---a/common/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c+++b/common/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c @@-92,6+92,16@@staticstructpcm_configpcm_config={.format=PCM_FORMAT_S16_LE,};++staticstructpcm_configpcm_config_16ch_out={+.channels=16,+.rate=48000,+.period_size=1024,+.period_count=4,+.format=PCM_FORMAT_S16_LE,+};++staticstructpcm_configpcm_config_in={#ifPCM_REFERENCE_CHANNELS.channels=PCM_CAPTURE_CHANNELS+PCM_REFERENCE_CHANNELS,@@-651,7+661,8@@structdev_proc_infoSPEAKER_OUT_NAME[]=/* add codes& dai name here*/{"rockchiprt5670c",NULL,},{"rockchiprt5672c",NULL,},{"rockchipaw882xx",NULL,},-{"rk3528acodec",NULL},+{"rk3528acodec",NULL,},+{"rockchiptdm",NULL,},{NULL,NULL},/* Note! Must end with NULL, else will cause crash */};@@-4200,8+4218,18@@staticintadev_open_output_stream(structaudio_hw_device*dev,type=OUTPUT_LOW_LATENCY;}-ALOGD("out->config.rate = %d, out->config.channels = %d out->config.format = %d",-out->config.rate,out->config.channels,out->config.format);++if(devices==AUDIO_DEVICE_OUT_SPEAKER){+ALOGE("speaker out 16 chn");+out->supported_channel_masks[0]=AUDIO_CHANNEL_OUT_5POINT1;+out->supported_channel_masks[1]=AUDIO_CHANNEL_INDEX_MASK_16;+out->config=pcm_config_16ch_out;+out->channel_mask=AUDIO_CHANNEL_INDEX_MASK_16;//AUDIO_CHANNEL_OUT_9POINT1POINT6;+}++ALOGE("out->config.rate = %d, out->config.channels = %d out->config.format = %d, config->channel_mask = 0x%x",+out->config.rate,out->config.channels,out->config.format,config->channel_mask);out->stream.common.get_sample_rate=out_get_sample_rate;out->stream.common.set_sample_rate=out_set_sample_rate;@@-5098,6+5126,7@@staticvoidadev_open_init(structaudio_device*adev)charvalue[PROPERTY_VALUE_MAX];if(property_get("vendor.audio.period_size",value,NULL)>0){pcm_config.period_size=atoi(value);+pcm_config_16ch_out.period_size=pcm_config.period_size;pcm_config_in.period_size=pcm_config.period_size;}if(property_get("vendor.audio.in_period_size",value,NULL)>0)SO 编译
source build/envsetup.sh lunch rk3576s_u-userdebug mmm hardware/rockchip/audio/tinyalsa_hal/adb-d root adb-d remount adb-d push audio.primary.rk30board.so/vendor/lib/hw/adb-d rebootaudio_policy_configuration.xml修改
源码路径:device/rockchip/common/audio_policy_configuration_singlehal.xml
diff--git a/device/rockchip/common/audio_policy_configuration_singlehal.xml b/device/rockchip/common/audio_policy_configuration_singlehal.xml index eba2888f797..d43adf27793100644---a/device/rockchip/common/audio_policy_configuration_singlehal.xml+++b/device/rockchip/common/audio_policy_configuration_singlehal.xml @@-28,7+28,7@@<mixPorts><mixPort name="primary output"role="source"flags="AUDIO_OUTPUT_FLAG_PRIMARY"><profile name=""format="AUDIO_FORMAT_PCM_16_BIT"-samplingRates="44100 48000"channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>+samplingRates="44100 48000"channelMasks="AUDIO_CHANNEL_INDEX_MASK_16"/></mixPort><mixPort name="spdif_passthrough"role="source"flags="AUDIO_OUTPUT_FLAG_DIRECT">调试&验证
调试信息
部分调试信息不显示,可以执行logcat -G 64M增大 log 缓冲区
logcat-s modules.primary.audio_hal抓取送往驱动前的原始数据
vendor.audio.record指定抓取多少 MB
rm/data/misc/audioserver/debug.pcm mkdir-p/data/misc/audioserver/touch/data/misc/audioserver/debug.pcm setprop vendor.audio.record5chmod777-R/data/misc/audioserver setenforce0du-h/data/misc/audioserver/adb-d pull/data/misc/audioserver/debug.pcm adb-d root adb-d remount adb-d push audio_policy_configuration_singlehal.xml/vendor/etc/adb-d shell sync adb-d shell stop adb-d shell start抓取原始数据后使用Audacity 进行播放(文件 -> 导入 -> 原始数据 -> 根据播放的音源设置)
dumpsys
dumpsys media.audio_flinger可以查看送往hal层的数据格式
Output thread0xb400007f6c7958f0,name AudioOut_D,tid3147,type0(MIXER):I/O handle:13Standby:no Sample rate:48000Hz HAL frame count:960HAL format:0x1(AUDIO_FORMAT_PCM_16_BIT)HAL buffer size:30720bytes Channel count:16Channel mask:0x8000ffff(index mask,bits:0xffff)Processing format:0x1(AUDIO_FORMAT_PCM_16_BIT)Processing frame size:32bytes 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=2328disc=1cold=0nRdy=0err=3rate=1jitterMs(ave=6.18763e-06std=0.0178616min=-0.0625277max=0.0458923)localSR(48000,3.60454e-11)correctedJitterMs(ave=-1.70485e-07std=0.00835348min=-0.022509max=0.0245337)Timestamp corrected:no Last writeoccurred(msecs):32dumpsys media.audio_policy可以查看当生效的配置文件
...Config source:/vendor/etc/audio_policy_configuration_singlehal.xml...以及配置的输出格式
Hardwaremodules(4):1.Handle:10;"primary"-OutputMixPorts(3):1."primary output";0x0002(AUDIO_OUTPUT_FLAG_PRIMARY)-Profiles(1):1."";AUDIO_FORMAT_PCM_16_BIT(0x1)sampling rates:44100,48000channel masks:0x8000ffffAUDIO_ENCAPSULATION_TYPE_NONE