-------------------------------------------------
Alsa-lib User Space
-------------------------------------------------
Alsa Kernel Space
-------------------------------------------------
sound driver
-------------------------------------------------
Hardware
並鏈 接libasound .
對於上面的架構,在某一時刻只能有一個程序打開聲卡並佔有它,此時其它程序打開的話,會返回busy.
App1 App2
ESD , pulseaudio
-------------------------------------------------
Alsa-lib User Space
------------------------------------------------
Alsa Kernel Space
------------------------------------------------
sound driver
------------------------------------------------
Hardware
此時,應用程序將調用ESD,pulseaudio等混音器提供的接口。對於ESD,很多程序支持,比如mplayer . 對於pulseaudio ,有相應的patch。
Alsa本身也提供混音的plugin,dmix .
App1 App2
----------------------------------------------------
Alsa-lib (dmix) User Space
----------------------------------------------------
Alsa Kernel Space
----------------------------------------------------
sound driver
----------------------------------------------------
Hardware
此架構和架構1,應用程序不需要做任何修改,只需要修改/usr/share/alsa/asound.conf
架構1的/usr/share/alsa/asound.conf的例子:
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
架構3的/usr/share/alsa/asound.conf的例子:
pcm.card0 {
type hw
card 0
}
pcm.!default {
type plug
slave.pcm "dmixer"
}
pcm.dmixer {
type dmix
ipc_key 1025
slave {
pcm "hw:0,0"
period_time 0
period_size 4096
buffer_size 16384
periods 128
rate 44100
}
bindings {
0 0
1 1
}
}
關於配置,可以參考這個網站:
http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
對於period_size和buffer_size,要注意,這裏將它們修改爲1024 ,8192.
用mplayer進行測試:
board1:$mplayer -slave -quiet test1.mp3
board2:$mplayer -slave -quiet test2.mp3
就可以聽到2個音樂混在一起輸出,且可以各自控制各自的播放。