天天看点

android 音频系统工作流程梳理

ALSA可以分为ALSA driver、ALSA lib、ALSA application三个层次。

soc可以分为4个域:

  1. Codec domain ;
  2. Platform/Machine domain;
  3. Path domain -alsamixer, amixer;
  4. sound/soc/codecs目录Stream domain - DACs and ADCs.  aplay, arecord。

对codec内部的硬件构件抽象的部件包括:

  • Mixer      - Mixes several analog signals into a single analog signal.混合多个模拟信号到单个模拟信号
  • Mux        - An analog switch that outputs only one of many inputs.多路模拟信号的选择开关
  • PGA        - A programmable gain amplifier or attenuation widget.
  • ADC        - Analog to Digital Converter
  • DAC        - Digital to Analog Converter
  • Switch     - An analog switch
  • Input      - A codec input pin
  • Output     - A codec output pin
  • Headphone  - Headphone (and optional Jack)
  • Mic        - Mic (and optional Jack)
  • Line       - Line Input/Output (and optional Jack)
  • Speaker    - Speaker
  • Pre        - Special PRE widget (exec before all others)
  • Post       - Special POST widget (exec after all others)

    path的头尾端点就是用SND_SOC_DAPM_INPUT或者SND_SOC_DAPM_OUTPUT定义这个部件。

    Audio Codec中有许多部件,并且可以是任意的名字,ALSA怎么可能知道该如何操作这些部件来切换到你想要的路径,即时ALSA lib也不会关心这部分内容,这些细微的切换又ALSA application以上来完成,ALSA lib也最多提供各种操作mixer或者Mux的函数,如何切换是你应用的事情。

    对部件的操作函数是snd_mixer_selem_set_enum_item(),alsamixer也是通过这个函数达到切换的目的

    amixer-用户层  

     ->snd_ctl_ioctl-系统调用    

    ->snd_ctl_elem_write_user-内核钩子函数    

    ->snd_ctl_elem_wirte

    ->snd_ctl_find_id-遍历kcontrol链表找到name字段匹配的kctl    

    ->kctl->put()-调用kctl的成员函数put()    

    ->snd_soc_put_volsw_2r