当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 2 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [转帖]Allow multiple programs to play sound at once
帖子发表于 : 2006-11-25 0:22 
头像

注册: 2006-10-18 12:57
帖子: 417
送出感谢: 0 次
接收感谢: 1
来自:http://wiki.archlinux.org/index.php/Allow_multiple_programs_to_play_sound_at_once

In Linux, only one program can play a sound at a time unless you have a soundcard that supports hardware mixing (all/most onboard soundchips don't.) or one of the methods outlined under are being used. All the methods are using some form of software mixing.

Contents
* 1 dmix - Alsa's software mixing system.
* 2 ALSA with oss2jack
2.1 Notes
2.2 More Information
* 3 joss(up until now it has been called q3jack..)
* 4 OSS/Commercial - www.opensound.com (free)
* 5 Use soundcard that supports hardware mixing
* 6 Old or discouraged methods
6.1 aRTS - KDE Project's software mixing
6.2 Polypaudio - http://0pointer.de/lennart/projects/polypaudio/
6.3 NAS http://radscan.com/nas.html
6.4 ESD - http://www.tux.org/~ricdude/EsounD.html
6.5 USound - http://mattcamp.paunix.org/usound/
* 7 Problems and Solutions for certain programs
7.1 Skype
* 8 Other information


dmix - Alsa's software mixing system.

(dmix reduces the sound quality during mixing and it doesn't work well with some oss apps. You should try hardware mixing or oss2jack first.)

Put the following lines into /etc/asound.conf. note:in most cases this config is no longer needed!
代码:
#/etc/asound.conf start:
pcm.!default {
    type plug
    slave.pcm "dmixer"
}
pcm.dsp0 {
    type plug
    slave.pcm "dmixer"
}
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 8192
        rate 44100
    }
    bindings {
        0 0
        1 1
    }
}

ctl.dmixer {
    type hw
    card 0
}

#end.


And magically, next time a program tries to use sound, dmix will kick in.

You might find that only one user can use the dmixer at a time. This is probably ok for most but for those like myself who run mpd as a seperate user this poses a problem. When mpd is playing my normal user can't play though the dmixer. While its quite possible to just run mpd under my login account I found another solution. Adding the line ipc_key_add_uid 0 to the pcm.dmixer block disables this locking. The following is a snippet of my asound.conf, the rest is the same as above.
代码:
...
pcm.dmixer {
 type dmix
 ipc_key 1024
 ipc_key_add_uid 0
slave {
...

To make most programs use Alsa, make sure /etc/libao.conf only contains the following.
代码:
default_driver=alsa10

For other programs who insist on their own audio setup, eg, XMMS or Mplayer, you would need to set their specific options.

For mplayer, open up ~/.mplayer/config (or /etc/mplayer/mplayer.conf for global setting) and put the following line in:
代码:
ao=alsa

For XMMS/Beep Media Player, go into their options and make sure the sound driver is set to Alsa, not oss.

To do this in XMMS:

* Open XMMS
Options -> preferences.
Choose the Alsa output plugin.

For applications which do not provide a ALSA output, you can use aoss. To use aoss, when you run the program, prefix it with aoss(alsa-oss), eg:
代码:
aoss realplay

If you don't want to have to do that each time, look at examples below.

your running firefox and you want to get sound from your propriatory flash-plugin which only has oss sound output support:
/usr/bin/firefox:
代码:
#!/bin/sh
export MOZILLA_LAUNCHER=firefox

aoss /opt/mozilla/bin/firefox "$@"

same but switfox(NOTE: i made this file myself simply switching the entries. I do NOT know if this startups swiftfox in the way it is intended so beware)

/usr/bin/swiftfox:
代码:
#!/bin/bash

export MOZILLA_LAUNCHER=swiftfox

aoss /opt/swiftfox/swiftfox "$@"


Also selfmade so beware as i'm not excactly a script whiz(and 9.0-20060616.6 would probably need to be modified to your version on upgrade ofc):

/usr/bin/opera:

代码:
#!/bin/sh
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/lib/libaspell.so.15"
export LD_LIBRARY_PATH
export OPERA_FORCE_JAVA_ENABLED="1"
aoss /usr/lib/opera/9.0-20060616.6/opera "$@"


And remember to make the scripts executable ofc:
代码:
chmod +x /usr/bin/file


ALSA with oss2jack

UPDATE: Stopped working with ET and Quake3 for some unknown reason... :/ I(nut543, author of oss2jack packages) now recommend to just use the aoss method and the 'snd_pcm_oss' kernel module for games & apps aoss don't support(like ET).

(UPDATE: oss2jack 0.25-6 works perfectly with ET, kernel26beyond 2.6.17.beyond3)

"oss2jack - A Linux kernel based approach to using OSS applications with the Jack Audio Connection Kit"

You might want to remove esd, artsd, polypaudio, etc. too as you won't really be needing them unless an app only has artsd output for example.

To use oss2jack, you will need two packages,oss2jackand fusd-kor.

You will need to download the tarballs for each package and run makepkg to create the package. 1.

After having installed the packages, put the oss2jack after jack-audio-connection-kit in the DAEMONS array in /etc/rc.conf if you want oss2jack to start automagically on boot.

Edit /etc/conf.d/jack-audio-connection-kit and change the SERVER_PARAMS and DRIVER_PARAMS to suit your needs. I make the entries look like this:
代码:
SERVER_PARAMS="-R -s -d alsa"
DRIVER_PARAMS="hw:0 -p 64 -r 44100"                              #the reason you write "hw:0" is because the "-d" is already specified in /etc/rc.d/jack-audio-connection-kit thus making jackd run like "jackd -R -s -d alsa -d hw:0 -p 64 -r 44100"

If you have a slower computer, you may want to increase the period from 64 to 128 or 256.1 ( 512 or 1024 is just fine, don't waste your CPU)

This can be used as solution to the "teamspeak and mic + ingame sound/music while using xmms" or whatever problem one see all around the net. If you need more info see the oss2jack site (linked below).
Notes
* Wine requires the audio to be 'Emulated' (change in winecfg's audio tab)

* If you have MOD_AUTOLOAD="yes" in your rc.conf you might need to have !snd_pcm_oss !snd_seq_oss in your MODULES array to disable autoloading of these modules by udev.

* If you need to start oss2jack as a user(with realtime capabilties), you need to compile and install the realtime-lsm module.

* Some apps/games require the snd-mixer-oss kernel-module loaded(UT2004 for example), this might be(but probably isn't) unstable for the oss2jack daemon. Note that alsamixer will still let you set PCM, MASTER, etc volume regardless of if you have snd-mixer-oss loaded.

* If you have issues setting the OSS volumes, try using audacity to set the volumes. Audacity is available in the Extra repository and is a sound editor that uses OSS. It has controls for input (mic) and output volumes. The voluemes set with Audacity are OSS volumes, not ALSA volumes. You should only use this solution if using an ALSA mixer doesn't work for some reason, as setting the OSS volumes may unintentionally change the ALSA volues due to oss2jack's emulation.

* If you are running other OSS drivers in your kernel, you will have to bind oss2jack to a different device. To bind oss2jack to /dev/dsp2, edit /etc/rc.d/os2jack and change the line:
代码:
/usr/bin/oss2jack &

to this:
代码:
/usr/bin/oss2jack -n 2 &

If you're using kernel26beyond (patched and optimized for desktop), you can install schedtool and start jackd by schedtool -I -e jackd.... The "-I" option means a special, limited real-time priority policy, which may use only up to 80% of CPU (to prevent your system from freeze)

More Information
oss2jack
oss2jack installation instructions
JACK Audio Connection Kit
Errors I encountered
--Read this if you have other problems not mentioned here

joss(up until now it has been called q3jack..)

recently a similar solution as the above has come up which doesn't require a kernel module but has other limitations (08-03-2006). update: now the download link works on the site again. Note that it has no capture support as-of-yet (05-09-2006).

I haven't tried it out but here is all i know about it(if you try it out please improve this entry):
http://www.linux-gamers.net/modules/newbb/viewtopic.php?topic_id=2075&forum=14

mirror: http://www.craknet.net/joss developers(down) site: http://www.konstruktiv.org/q3jack/

OSS/Commercial - www.opensound.com (free)

OSS/Commercial is a commercial sound driver that contains a software mixer in kernel-space, and it's free for personal and non-commecial use. SeeOSS_Commercial_Setup for more information.



Use soundcard that supports hardware mixing

Old SoundBlaster Live series (emu10k1 chip) and new Audigy series (emu10k2 chip) cards are known to work.

The SoundBlaster Live 5.1 is fairly easy to find and is cheap to buy.

Note: new cheap Audigy SE, Audigy 2 NX, SoundBlaster Live 24bit and SoundBlaster Live 7.1 does not support hardware mixing (they use other chips).

99% of motherboards with integrated sound do not support hardware mixing.

The onboard VIA8237 chip supports 4-stream hardware mixing. However it does only 3 for some motherboards (the 4th makes no sound), or just broken. Even if it works, the quality is not good compared to jackd/oss2jack or oss/commercial's.

Old or discouraged methods

The following methods are NOT designed for music or games, but short-time audio such as chat notify. They require a lot of CPU resource and have very high latency.

aRTS - KDE Project's software mixing
代码:
pacman -S arts

Then if you use KDE, aRTS will be started for you automatically. If you don't use KDE and want arts to start whenever you start your computer, add this line to a system startup file such as /etc/rc.local:

代码:
/opt/kde/bin/artsd -a oss &

To hear the music, set your program's audio outputs to arts.

For apps that do not provide an aRTS output, you may prefix them with artsdsp, eg:
代码:
/opt/kde/bin/artsdsp -m xmms
or
代码:
/opt/kde/bin/artsdsp -m EnemyTerritory <-- although the sound will lagg behind.

If you find you have problems, try different arguments, which can be found by running the commands below.

代码:
artsd --help
artsdsp --help


Polypaudio http://0pointer.de/lennart/projects/polypaudio/

polypaudio is a less intensive implementation of a sound mixing server than ESD and ARTS but doesn't have fancy 3D sound effects etc like arts. Ubuntu Linux is switching to this server instead of ESD.

NAS http://radscan.com/nas.html

Unique features. Check the readme. Has builtin mixing. You may get it to work with libaudioss, therefore nearly audio apps that have an OSS output will work with this, and it will be "lag-free". It does not have mmap support however, and this causes it to not work with many games.

ESD http://www.tux.org/~ricdude/EsounD.html

ESD is a dated solution that hasn't been updated for many years, however it has excellent application support and works well for basic desktop usage.

adding 'esd' to the daemons section in rc.conf did the trick for me.

USound http://mattcamp.paunix.org/usound/

USound is somewhat similar to the Enlightened Sound Daemon (EsounD), but as the name suggests, USound aims to be more useful, particularly for consumer desktop and multimedia applications. At the time of writing (0.2) it has support for libao, mplayer, madplay and Speak Freely

Problems and Solutions for certain programs

Skype

Click here for a Skype dmix how-to.

Other information

* http://www.linuxdj.com/audio/quality/
* http://ck.kolivas.org/faqs/audio_hints
* See Gentoo-Wiki referring to dmix for information on how to set up different programs (firefox, mpd etc.) to use dmix


页首
 用户资料  
 
2 楼 
 文章标题 :
帖子发表于 : 2006-11-25 0:37 
头像

注册: 2006-10-18 12:57
帖子: 417
送出感谢: 0 次
接收感谢: 1
补充一下,上面的虽然是基于archlinux的,但是对ubuntu也是有借鉴作用的,所以
转过来了,希望对大家有帮助,


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 2 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 3 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译