问题描述
我的声卡是 Audigy SE [SB0570].
My sound card is Audigy SE [SB0570].
我想同时在扬声器和耳机上播放相同的立体声流.
I want to play the same stereo stream not only on speakers but on headphones too, simultaneously.
我在我的空 ~/.asoundrc 上尝试这个配置
I try this config on my empty ~/.asoundrc
pcm.quad {
type multi
slaves.a.pcm "hw:0,0" #green hole
slaves.a.channels 2
slaves.b.pcm "hw:0,2" #black hole
slaves.b.channels 2
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
}
pcm.!default quad
它就像我想要的那样工作.但是现在很多流之间的共享频道坏了,我不能同时播放 2 个 mp3 文件.
and it works just as I want. But sharing channel between many streams is broken now and I can't play 2 mp3 files at the same time.
顺便说一下,/etc/asound.conf 也是空的.我不知道真正的系统 alsa 配置在哪里,可能是这个 /var/lib/alsa/asound.state 用 4705 行和数百个 控件很难理解的脂肪.## 块.
By the way /etc/asound.conf is empty too. I don't know where is the real system alsa configs are, may be this /var/lib/alsa/asound.state fat extremely hard understandable with 4705 lines and hundreds of control.## blocks.
推荐答案
你的想法是正确的.您可以使用type multi" alsa 模块向两个不同的设备播放声音.你只需要稍微扩展一下就可以构建完整的链.
Your idea is correct. You can use "type multi" alsa module to play sound to two different devices. You just need to extend it a little to build full chain.
卡片名称.通常最好使用卡片名称而不是索引:hw:CardName,2"而不是hw:0,2",因为卡片索引可能会在重新启动时更改,而名称通常不会更改.您可以在 cat/proc/asound/cards
和 aplay -l
输出中看到卡片名称.对于您的卡,名称可能是CA0106".
Card name. It's usually better to use card names instead of indexes: "hw:CardName,2" instead of "hw:0,2" because card index may change on reboot, and names usually don't change. You can see card names in cat /proc/asound/cards
and aplay -l
output. For your card the name is probably "CA0106".
混合.要允许多个应用程序同时播放,请在播放链中的type multi"和hw"之间放置type dmix".type dmix"模块将多个应用程序混合到同一个硬件缓冲区中.
Dmix. To allow several apps playing simultaneously put "type dmix" between "type multi" and "hw" in your playback chain. The "type dmix" module mixes multiple apps into the same hardware buffer.
路线.您的type multi"模块将输入通道 0,1,2,3 映射到从站a"的输出通道 0,1 和从站b"的通道 0,1,这意味着您有 4 个输入通道,而您有只有 2 个通道(立体声).要将 2 声道立体声转换为 4 声道以进行type multi",请先使用type route" pcm 将声道 0,1 复制到 0,1 和 2,3.
Route. Your "type multi" module maps input channels 0,1,2,3 to output channels 0,1 of slave "a" and channels 0,1 of slave "b", which implies that you have 4 input channels, while you have just 2 channels (stereo). To convert 2 channels stereo into 4 channels for "type multi" precede it with "type route" pcm duplicating channels 0,1 both to 0,1 and 2,3.
插头.不同的应用程序可能会尝试播放您的硬件不直接支持的格式/速率.因此,将类型插头"自动转换模块放在播放链链的首位是一个很好的做法——它将任何输入格式/速率转换为支持的输出.
Plug. Different applications may try playing formats/rates, not directly supported by your hardware. So it's a good practice to put "type plug" autoconversion module first in the playback chain chain — it will convert whatever input format/rate into a supported output.
整个播放链应该是这样的:
Overall the playback chain would be like:
default = plug -> route -> multi -> (dmix->hw:CA0106,0 + dmix->hw:CA0106,2)
Asym:但这只是播放链.如果您想将默认" pcm 指向它是不够的,因为默认"是默认用于播放和捕获的 pcm.要允许应用从默认"录制,您需要使用type asym"模块为其定义不同的播放和捕获链.捕获链可以如下所示:
Asym: But that's just playback chain. It's not enough if you want to point "default" pcm to it, because "default" is a pcm used by default both for playback and capture. To allow apps recording from "default" you need to define different playback and capture chains for it using "type asym" module. Capture chain can look like:
default = plug <- dsnoop <- hw
(type dsnoop"是一个类似 dmix 的捕获模块——它允许多个应用程序从同一设备捕获)
("type dsnoop" is a dmix-like module for capture — it allows multiple apps capturing from the same device)
您可以手动定义每个 pcms,但我建议走捷径并重用预定义的plug"、dmix"和dsnoop" pcms(在 /usr/share/alsa/alsa.xml 中定义).conf
、/usr/share/alsa/pcm/dmix.conf
、/usr/share/alsa/pcm/dsnoop.conf
).那么整个配置将是:
You can define each of those pcms by hand, but I suggest to take a shortcut and reuse predefined "plug", "dmix" and "dsnoop" pcms (defined in /usr/share/alsa/alsa.conf
, /usr/share/alsa/pcm/dmix.conf
, /usr/share/alsa/pcm/dsnoop.conf
). Then the whole config would be:
pcm.quad {
type multi
slaves.a.pcm "dmix:CA0106,0"
slaves.a.channels 2
slaves.b.pcm "dmix:CA0106,2"
slaves.b.channels 2
bindings.0 { slave a; channel 0; }
bindings.1 { slave a; channel 1; }
bindings.2 { slave b; channel 0; }
bindings.3 { slave b; channel 1; }
}
pcm.stereo2quad {
type route
slave.pcm "quad"
ttable.0.0 1
ttable.1.1 1
ttable.0.2 1
ttable.1.3 1
}
pcm.!default {
type asym
playback.pcm "plug:stereo2quad"
capture.pcm "plug:dsnoop:CA0106"
}
将其放在 ~/.asoundrc
(仅限您的用户)或 /etc/asound.conf
(所有用户)中.
Put this in ~/.asoundrc
(your user only) or /etc/asound.conf
(all users).
PS:人们通常希望在重启后保留他们的卷.许多发行版在关机时运行 alsactl store
以保存当前的音量控制,并在启动时运行 alsactl restore
以重新加载这些音量控制.默认情况下,alsactl
将这些音量控制保存在 /var/lib/alsa/asound.state
中.这是该文件的唯一用途.
PS: People often want their volumes to be preserved across reboot. So many distros run alsactl store
on shutdown to save current volume controls and alsactl restore
on startup to load those volume controls back. By default alsactl
saves those volume controls in /var/lib/alsa/asound.state
. That's the only purpose of that file.
链接:
这篇关于Alsa:如何在 2 个输出上复制流并保存系统配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!