From Amarok Wiki

Danish | Deutsch | English | Türkçe| 简体中文


在下面,你会发现一个配置文件的例子,它将帮你启用你机器上的 Dmix 插件.

  • 注意,如果你使用的发行版中内置在 alsa-lib 中的 dmix 插件(在 Debian 及基本 Debian 的系统中是 libasound2) 不起作用,下面的指导才是必须的!你也可以通过设置 "plug:dmix" 为虚拟 ALSA 设备来使用内置的预设好的 dmix 插件.
  • 同时还要注意,"如果你的 ALSA 版本在 1.0.9rc2 或更高,你就不需要再安装 dmix 了.Dmix 对那些不支硬件混音(hw mixing)的声卡是默认有效的." -- 摘自 alsa wiki. 所以, 最简单的解决方案就是把旧的配置文件删除,然后重新安装 alsa (如果安装好后没有反应, 可能内核模块需要重启). 如果你正在运行最近的一个 alsa 版本, 你可能不能同时使用同一个配置文件来获得一个以上的声音服务, 这是一个错误(BUG).

你可以在 ~/.asoundrc(只会对你使用的用户有效)或 /etc/asound.conf (影响整个系统) 中保存配置文件. 编辑完这些文件之后, 你只需要重启一下 ALSA 应用程序就可以了.

pcm.ossmix {
   type dmix
   ipc_key 1024
   slave {
       pcm "hw:0,0"            # make sure this matches the actual device
       #period_time 0          # not necessary since ALSA 1.0pre
       period_size 1024        # Use a power of 2
       buffer_size 4096        # must be a multiple of period_size
       #rate 44100             # not necessary; let alsa-lib handle this
   }
   bindings {
       0 0
       1 1                     # bind only the first 2 channels
   }
}
pcm.duplex
{
   type asym
   playback.pcm "ossmix"
   capture.pcm "dsnoop"
}
# Everything shall be dmixed, so redefine "default":
# Note that this is _not_ a good idea, since dmix doesn't allow mmap access currently
#pcm.!default {
#   type plug
#   slave.pcm "duplex"
#}
# OSS via aoss should d(mix)stroyed:
pcm.dsp0 {
   type plug
   slave.pcm "duplex"
}
ctl.ossmix {
   type hw
   card 0
}

要测试 dmix 是否在启作用, 你可能需要同时运行两个或三个 "alsaplayer" 程序 (或其他 ALSA 程序, 例如 Amarok):

alsaplayer -o alsa -d plug:ossmix some.mp3

or

aplay -D plug:ossmix some.mp3

如果你的程序在做对处理器敏感的工作, 例如正在编译或使用 OpenGL 显示, 在 ~/.asoundrc 中增加缓冲大小(buffer_size)可能会有帮助. 增加的大小值应该是 2 的 n 次方, 例如:

pcm.ossmix {
   type dmix
   ipc_key 1024
   slave {
       pcm "hw:0,0"
       #period_time 0
       period_size 1024
       buffer_size 16384        # buffer size = 4096 x 2 x 2
       #rate 44100
   }
   bindings {
       0 0
       1 1
   }
}