如何创建同时输出到 HDMI 和耳机插孔的 ALSA 虚拟设备?

如何创建同时输出到 HDMI 和耳机插孔的 ALSA 虚拟设备?

我可以告诉我的程序输出到 HDMI或者耳机插孔很好,但是有没有办法在 asound.conf 中创建一个同时输出到两者的虚拟设备?

此配置非常接近工作,但它会在耳机插孔上产生一种脉冲噪音。

pcm.internal {
  type hw
  card 1
  device 0
}

pcm.hdmi_hw {
  type hw
  card 0
  device 7
}

pcm.hdmi_complete {
  type softvol
  slave.pcm hdmi_hw
  control.name hdmi_volume
  control.card 1
}

pcm.sirmix {
    type plug
    slave.pcm {
        type multi
        slaves {
            a { channels 2 pcm "internal" }
            b { channels 2 pcm "hdmi_complete" }
        }
        bindings {
            0 { slave a channel 0 }
            1 { slave a channel 1 }
            2 { slave b channel 0 }
            3 { slave b channel 1 }
        }

    }
    ttable [
        [ 1 0 1 0 ]
        [ 0 1 0 1 ]
    ]
}

gst-launch-1.0 音频测试文件!音频转换! alsasink 设备=“sirmix”

答案1

所以显然上面的设置和管道本质上是好的,如果你去 ALSA 论坛,他们会推荐类似上面的东西,但是rate你的输出的匹配是必须另外考虑的。

pcm.internal {
  type hw
  card 1
  device 0
  rate 48000
}

pcm.hdmi_hw {
  type hw
  card 0
  device 7
  rate 48000
}

我的最终配置文件如下所示,其中包括各个输出设备及其共享父设备的音量控制,以及跨多个播放进程的混合:

pcm.m_headphone_mixed {
 type dmix
 ipc_key 595900
 ipc_perm 0666
 slave {
  pcm "hw:1,0" 
  rate 48000
  period_time 0
  period_size 1024
  buffer_size 4096
  format S16_LE
 }
 bindings {
  0 0
  1 1  
 }
}

pcm.m_headphone_rate_adjusted {
 type rate
 slave {
  pcm "m_headphone_mixed"
  rate 48000
 }
}

pcm.m_headphone {
 type softvol
 slave.pcm m_headphone_rate_adjusted
 control.name m_headphone_volume
 control.card 1
}

pcm.m_hdmi_mixed {
 type dmix
 ipc_key 595901
 ipc_perm 0666
 slave {
  pcm "hw:0,7"
  rate 48000
  period_time 0
  period_size 1024
  buffer_size 4096
  format S16_LE
  channels 2
 }
 bindings {
  0 0 # channel 0 -> channel 0 
  1 1
 }
}

pcm.m_hdmi {
 type softvol
 slave.pcm "m_hdmi_mixed"
 control.name m_hdmi_volume
 control.card 1 
}

pcm.m_all_base {
 type plug

 slave.pcm {
   type multi
   slaves {
       a { channels 2 pcm "m_hdmi" }
       b { channels 2 pcm "m_headphone" }
   }
   bindings [
       { slave a channel 0 }
       { slave a channel 1 }
       { slave b channel 0 }
       { slave b channel 1 }
   ]
 } 
}

pcm.m_all_routed {
type route
 slave.pcm "m_all_base"
 slave.channels 4

 ttable [
  [ 1 0 1 0 ] # route left to channels 0,2
  [ 0 1 0 1 ] # route right to channels 1,3
 ]
}

pcm.m_all {
 type softvol;
 control.name m_all_volume;
 control.card 1
 slave.pcm "m_all_routed"
}

pcm.!default "m_all"

这是为了让标准戴尔台式电脑同时输出到耳机插孔和 DisplayPort。

相关内容