Audio

ALSA:將音頻發送到兩個音頻設備

  • March 10, 2022

在我的筆記型電腦上,我有一個板載音效卡,還有一個連接的藍牙耳機。我已經在以下位置配置了藍牙設備/etc/asound.conf

# cat /etc/asound.conf

pcm.bluetooth {
   type bluetooth
   device 12:34:56:78:9a:bc
   profile "auto"
}

ctl.bluetooth {
   type bluetooth
}

現在我可以通過指定新的音頻設備來向耳機播放音頻,例如:

mplayer -ao alsa:device=bluetooth file.mp3

如果我想在我的預設設備上播放,我只需省略該設備:

mplayer file.mp3

但是,我需要配置 ALSA,以便預設情況下將所有聲音發送到兩個設備,而無需為每個應用程序顯式設置。

IE:

mplayer file.mp3

應該在筆記本音效卡和藍牙耳機上播放。

我怎樣才能做到這一點 ?

這是從**~/.asoundrc**執行此操作的一種方法;範例顯示了在預設 PCM 下聯合的板載和 Soundblaster 實時卡。

# duplicate audio to both devices
pcm.!default plug:both

ctl.!default {
 type hw
 card SB
}

pcm.both {
 type route;
 slave.pcm {
     type multi;
     slaves.a.pcm "sblive";
     slaves.b.pcm "onboard";
     slaves.a.channels 2;
     slaves.b.channels 4;
     bindings.0.slave a;
     bindings.0.channel 0;
     bindings.1.slave a;
     bindings.1.channel 1;

     bindings.2.slave b;
     bindings.2.channel 0;
     bindings.3.slave b;
     bindings.3.channel 1;
     bindings.4.slave b;
     bindings.4.channel 2;
     bindings.5.slave b;
     bindings.5.channel 3;
 }

 ttable.0.0 1;
 ttable.1.1 1;

 ttable.0.2 1; # front left
 ttable.1.3 1; # front right
 ttable.0.4 1; # copy front left to rear left
 ttable.1.5 1; # copy front right to rear right
}

ctl.both {
 type hw;
 card Live;
}

pcm.onboard {
  type dmix
  ipc_key 1024
  slave {
      pcm "hw:0,1"
      period_time 0
      period_size 2048
      buffer_size 65536
      buffer_time 0
      periods 128
      rate 48000
      channels 4
   }
   bindings {
      0 0
      1 1
      2 2
      3 3
   }
}

pcm.sblive {
  type dmix
  ipc_key 2048
  slave {
      pcm "hw:1,0"
      period_time 0
      period_size 2048
      buffer_size 65536
      buffer_time 0
      periods 128
      rate 48000
      channels 2
   }
   bindings {
      0 0
      1 1
   }
}

ctl.onboard {
  type hw
  card "SB"
}

ctl.sblive {
  type hw
  card "Live"
}

來源

引用自:https://unix.stackexchange.com/questions/293450