配置文件路径/vendor/hardmony/oriole/hals/audio/config/arm64/audio_policy_config.xml

调用设置配置文件的接口setparams,如果配置设置失败,会报错setparams fail。

如果需要增加usb耳机,则需要添加usb的adapter,以及pin。进行适配usb耳机设备。

 <audioPolicyConfiguration xmlns:xi="http://www.w3.org/2001/XInclude" version="1.0">

    <adapters>适配器,包括primary麦克风扬声器,蓝牙a2dp.

        <adapter name="primary" supportSelectScene="0">适配器不支持选择场景 0,支持选择场景 1

            <pipes>数据流动的通道

                <pipe name="primary_output" role="output">数据流动的通道primary_output走扬声器输出

                    <paProp lib="libmodule-hdi-sink.z.so" role="sink" fixed_latency="1" render_in_idle_state="1" moduleName="Speaker"/>

                    <streamProps>

                        <streamProp format="s16le" sampleRates="48000" channelLayout="CH_LAYOUT_STEREO" bufferSize="4096"/>配置解码格式,采样率(22050,44100,48000),声道(CH_LAYOUT_STEREO为双声道2,CH_LAYOUT_MONO为单声道1),以及缓冲区大小(一般设置成4096,8192)

                    </streamProps>音频流属性

                    <attributes>

                        <attribute name="preload" value="true"/>true指示是否应该在播放或处理之前预先加载数据。

                    </attributes>

                </pipe>

                <pipe name="primary_input" role="input">走primary通路麦克风

                    <paProp lib="libmodule-hdi-source.z.so" role="source" moduleName="Built_in_mic"/>

                    <streamProps>

                        <streamProp format="s16le" sampleRates="22050" channelLayout="CH_LAYOUT_MONO" bufferSize="4096"/>配置解码格式(s16le16为编码),采样率(22050,44100,48000),声道(CH_LAYOUT_STEREO为双声道2,CH_LAYOUT_MONO为单声道1),以及缓冲区大小(一般设置成4096,8192)

                    </streamProps>

                </pipe>

            </pipes>

            <devices>支持的输出设备包括扬声器,有线耳机,头戴式耳机。pin设备相关引脚。

                <device name="Speaker_Out" type="DEVICE_TYPE_SPEAKER" pin="PIN_OUT_SPEAKER" role="output" supportPipes="primary_output"/>

        <device name="Earpiece_Out" type="DEVICE_TYPE_EARPIECE" pin="PIN_OUT_EARPIECE" role="output" supportPipes="primary_output"/>

                <device name="Wired_Headset_Out" type="DEVICE_TYPE_WIRED_HEADSET" pin="PIN_OUT_HEADSET" role="output" supportPipes="primary_output"/>有线耳机,属性,设备的角色是输出。在音频处理的上下文中,输出设备通常是将处理后的音频信号发送到用户或外部系统的设备

                <device name="Wired_Headphones_Out" type="DEVICE_TYPE_WIRED_HEADPHONES" pin="PIN_OUT_HEADPHONE" role="output" supportPipes="primary_output"/>

                <device name="Builtin_Mic_In" type="DEVICE_TYPE_MIC" pin="PIN_IN_MIC" role="input" supportPipes="primary_input"/>

                <device name="Wired_Headset_In" type="DEVICE_TYPE_WIRED_HEADSET" pin="PIN_IN_HS_MIC" role="input" supportPipes="primary_input"/>

            </devices>

        </adapter>

        <adapter name="a2dp">蓝牙播放

            <pipes>

                <pipe name="a2dp_output" role="output">

                    <paProp lib="libmodule-hdi-sink.z.so" role="sink" moduleName="Bt_Speaker"/>蓝牙扬声器

                    <streamProps>

                        <streamProp format="s16le" sampleRates="48000" channelLayout="CH_LAYOUT_STEREO" buffer_size="3840"/>支持16位解码,48000采样,双声道。

                        <streamProp format="s16le" sampleRates="44100" channelLayout="CH_LAYOUT_STEREO" buffer_size="3528"/>支持16位解码,44100采样,双声道。

                        <streamProp format="s24le" sampleRates="96000" channelLayout="CH_LAYOUT_STEREO" buffer_size="11520"/>支持24位解码,96000采样,双声道。

                    </streamProps>

                </pipe>

            </pipes>

            <devices>

                <device name="Bt_A2dp_Out" 设备名称 type="DEVICE_TYPE_BLUETOOTH_A2DP" 设备类型 pin="PIN_OUT_BLUETOOTH_A2DP" 蓝牙a2dp的引脚 role="output" supportPipes="a2dp_output"/>

            </devices>

        </adapter>

        <adapter name="remote" supportSelectScene="0">分布式耳机

            <pipes>

                <pipe name="distributed_output" role="output">

                    <paProp lib="libmodule-hdi-sink.z.so" role="sink" moduleName="Speaker"/>

                    <streamProps>

                        <streamProp format="s16le" sampleRates="48000" channelLayout="CH_LAYOUT_STEREO"/>音频流格式,16位解码,48000采样,双声道。

                    </streamProps>

                </pipe>

                <pipe name="distributed_input" role="input">分布式音频输入

                    <paProp lib="libmodule-hdi-source.z.so" role="source" moduleName="Built_in_mic"/>            

                    <streamProps>

                        <streamProp format="s16le" sampleRates="48000" channelLayout="CH_LAYOUT_STEREO"/>

                    </streamProps>

                </pipe>

            </pipes>

            <devices>

                <device name="Distributed_Out" type="DEVICE_TYPE_SPEAKER" pin="PIN_OUT_DAUDIO_DEFAULT" role="output" supportPipes="distributed_output"/>分布式音频输出

                <device name="Distributed_In" type="DEVICE_TYPE_MIC" pin="PIN_IN_DAUDIO_DEFAULT" role="input" supportPipes="distributed_input"/>

            </devices>

        </adapter>

    </adapters>

    <volumeGroups>

        <groups>

            <group name="volume_group">

                <sink name="primary_out"/>

            </group>

        </groups>

    </volumeGroups>

    <interruptGroups>

        <groups>

            <group name="interrupt_group">

                <sink name="primary_out"/>

            </group>

        </groups>

    </interruptGroups>

    <globalConfigs>

        <defaultOutput adapter="primary" pipe="primary_output" device="Speaker"/>

        <commonConfigs>

            <attribute name="updateRouteSupport" value="true"/>

        </commonConfigs>

        <paConfigs>

            <!-- audioLatency is no need any more after ipc, keeping it here just in case.-->

            <attribute name="audioLatency" value="90"/>   音频默认延迟,以确保缓冲区写入完成

            <!-- sinkLatency is no need any more after ipc, keeping it here just in case.-->

            <attribute name="sinkLatency" value="40"/>  sink设备写入延迟,蓝牙,音箱的输出延迟

        </paConfigs>

        <maxConcurrentInstances>

            <output>

                <attribute name="normal" flag="AUDIO_FLAG_NORMAL" value="128"/>

            </output>

            <!-- Actually, max input concurrent instances is also influenced by audio focus.-->

            <input>

                <attribute name="normal" flag="AUDIO_FLAG_NORMAL" value="16"/>

            </input>

        </maxConcurrentInstances>

    </globalConfigs>

</audioPolicyConfiguration>

 

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐