Networked sound

See Sound.html for other sound issues.

Guides

  • Any?
  • Play music on clitunno and listen on sigillo:
    • sigillo: nasd -aa &
    • clitunno: export AUDIOSERVER="sigillo:0"
    • clitunno: alsaplayer -o nas

Software

  • NAS
    • nas (server)
    • nas-bin (client)
      • auinfo, auctl, auscope, aupanel, auedit
    • nas-doc
    • audiooss
      • alsaplayer-nas
      • nassink is in gstreamer0.8-misc
  • sox
  • jack
    • jackeq
    • qjackctl -- frontend
    • jack.udp (networked jack)
    • jack-tools
    • jack-rack
      • alsaplayer-jack
      • gstreamer-jack 
      • xmms-jack
  • arts
  • esound (for gnome -- same as esd)
    • esd -d /dev/dsp0.2 -tcp -public -port 5001 (on sigillo)
    • esdctl -s localhost:5001 unlock (allow remote input, on sigillo)
    • esdplay -s soundhost.5001 test.wav (testing from clitunno)


Instructions for NAS
  • root@sigillo:~#     
    • just install nas nas-doc
    • nasd -aa &
  • root@clitunno:~# 
    • export AUDIOSERVER="sigillo:0"
    • just install nas-bin
    • auplay /usr/lib/mozilla-firefox/res/samples/test.wav  (test)
    • just install alsaplayer-nas
    • alsaplayer -o nas
  • to eliminate skipping
    • ps aux | grep nas
    • sudo renice -19 <nas PID>
    • (or top r <nas PID> -19)
NAS unaware applications
  • root@sigillo:~#
    • nasd -aa &
  • root@clitunno:~#
    • export AUDIOSERVER="sigillo:0"
    • just install audiooss
    • audiooss xawtv -noxv (doesn't work)
  • you may need sox to redirect the sound -- something along these lines
    • LD_PRELOAD= sox -w -s -c 2 -r 44100 -t ossdsp /dev/dsp -t raw -
    • LD_PRELOAD=libaudiooss.so sox -t raw -w -s -c 2 -r 44100 - -t ossdsp /dev/dsp
    • it's likely not worth the hassle to get video and sound to both transfer

Installation history

26 December 2004: networked audio

I tried several different applications and ended up pursuing NAS, which seems to be the most developed.
  • sox can apparently do some sort of redirection (cf btaudio instructions), but may not be that powerful
  • artsd can do it, but it crashed for me and is being deprecated
How to redirect sound to another machine using KDE and aRtsd (source) (this didn't work)

It is possible to make your sound generating application send the sound to another computer. First you must make the machine that is to play the sound (the one with the soundcard that might be connected to your HiFi) accept sound being sent to it. It needs to run the artsd daemon in networking mode and it needs to be listening on a TCP port.

To set up the sound playing computer open the KDE Control Center and go to Sound System. On the General tab click on "Enable networked sound". On the Hardware tab tick on the "Use other custom options" and add the options -p 5001 -u

Hardcore shell users can also start artsd with something like artsd -n -u -p 5001 Basically this tells artsd to use networked sound (-n), have no protection (!) (-u) and work via port 5001 (-p 5001).

The computer that wants to send the sound needs to tell its artsd to send the sound to the target machine. You do this by setting the Environment ALSA_SERVER to the target. Such as: export ALSA_SERVER=192.168.0.5:5001 Then start your favorite sound application. Note: if this is xmms make sure it is sending it's output to aRts in the options.

You could use this to send the sound from your laptop to a computer attached to your Stereo that has very little disk capacity. You could send sound from your media server to your workstation. Of course you can also ssh -XC to the target machine and run the application there if you have the media there. This offers interesting possibilities.

I tried this and sound looks good on clitunno -- lots of sound servers available. So here are the steps:
  1. On sigillo, open kcontrol, go to sound system, and enter: Use other custom options -p 8001 -u.
    1. This tells sigillo to accept networked sound from port 8000
    2. It crashes and cannot handle the entry
    3. I try to issue, killall artsd && artsd -n -u -p 5001 & (which does the same thing)
    4. ALSA lib pcm_hw.c:563:(snd_pcm_hw_start) SNDRV_PCM_IOCTL_START failed: Broken pipe
    5. I reported the problem to ALSA-users (but the crashing has not do with not stopping artsd first!)
  2. On clitunno, issue
    1. export ALSA_SERVER=sigillo:5001
    2. Start xmms and set output to artsd
    3. I don't see anything in nmap clitunno (port 5001 is not open)
So it crashes on sigillo -- but then again, the error message in 1D appears when I do any kind of change to the sound server, so it may not matter one bit. If I explicitly stop the sound server before I start it with the new values, I seem to not get the crash itself. Still, no sound comes through and I'm clearly wasting time on this.
Since artsd didn't work, I looked at jackd, but it doesn't seem to do network audio.  It has a great frontend, qjackctl.
    • jack -- routes and manipulates audio from/to multiple sources
    • alsaplayer-jack gstreamer-jack jackeq jack-tools xmms-jack jack-rack
    • qjackctl -- frontend!
    • I asked on the jack mailing list if it could be used for networking sound, and it can:

      Yes, there's a udp transport client that works well for this, although because of the network delay you really need low
      latency configurations on both machines to keep sync with something like video. Don't know if that's important for your
      application or not. The client is called jack.udp available from http://www.alphalink.com.au/~rd/sw/jack.html
I see from the link that jack.udp is actively maintained, with instructions. Still, it's likely that NAS is better, as it was designed specifically for the job.
  • nas (network sound daemon)
I need NAS, "the audio equivalent of an X server." Nas will open the default audio device and keep others from using it -- but will release the device when not using it. An alternative is to use audiooss, which wraps any program that uses /dev/dsp.  It will intercept most uses of  /dev/dsp and make the equivalent nas calls instead."  I set nas not to set the mixer on startup. 

Here's how it's supposed to work:
	$  nasd -aa &		# -aa allows any host access
$ export AUDIOSERVER="`hostname`:0"
$ auinfo
$ audemo examples/sounds
$ ...
"In TCP/IP environments, audio server names look like: tcp/hostname:portnum
auinfo -audio tcp/ncdunit:8000
I asked on the mailing list for help; nas 1.7-2 seems to have solved the problem.
    • nas-bin contains auinfo, auctl, auscope, aupanel, auedit -- wow, this thing is huge.
    • nas-doc has instructions (use gs and page down to go backwards)
    • audiooss is "a compatibility utility that allows programs written for the popular Open Sound System (OSS) interface to run using the Network Audio System (NAS) instead"
So with nas 1.7-2 I try the above and get this:
# nasd -aa &
[1] 8488
root@clitunno:~# config: Maxfrags set to 3
config: Minfrags set to 2
config: Fragsize set to 256
config: Maxfrags set to 3
config: Minfrags set to 2
config: Fragsize set to 256
@(#)Network Audio System Release 1.7
@(#)Network Audio System Release 1.7
AuInitPhysicalDevices();
Init: will close device when finished with stream.
Init: Leaving the mixer device options alone at startup.
openDevice OUT /dev/dsp mode 2
openDevice(1) IN /dev/dsp1 mode 0
Input open(/dev/dsp1) failed: No such device, using output device
setupSoundcard(...);
++ Setting up Output device (/dev/dsp)
+++ requesting wordsize of 16, got 16
+++ requesting 2 channel(s), got 2 channel(s)
+++ Requesting minimum sample rate of 5000, got 5000
+++ Requesting maximum sample rate of 44100, got 44100
setTimer(rate = 0);
createServerComponents(...);
closeDevice: out
closeDevice OUT /dev/dsp mode 2
closeDevice: mixer

#export AUDIOSERVER=clitunno:0
# auinfo
Audio Server:           tcp/clitunno:8000
Version Number:         2.2
Vendor:                 Network Audio System Release 1.7 - VoxWare
Vendor Release:         1
Min Sample Rate:        5000
Max Sample Rate:        44100
Max Tracks:             32
Number of Formats:      7
Formats:                ULAW8  LinearUnsigned8  LinearSigned8
                        LinearSigned16MSB  LinearUnsigned16MSB
                        LinearSigned16LSB  LinearUnsigned16LSB
Number of Elem Types:   12
Element Types:          ImportClient  ImportDevice  ImportBucket
                        ImportWaveForm  Bundle  MultiplyConstant  AddConstant
                        Sum  ExportClient  ExportDevice  ExportBucket
                        ExportMonitor
Number of Wave Forms:   2
Wave Forms:             Square  Sine
Number of Actions:      3
Actions:                ChangeState  SendNotify  Noop
Number of Devices:      3
    Device 0:
        Changable:      Gain  LineMode
        ID:             0x23
        Kind:           PhysicalInput
        Use:            Import
        Format:         LinearUnsigned8
        Num Tracks:     2
        Access:         Import  List
        Description:    "Stereo Channel Input"
        Min Rate:       5000
        Max Rate:       44100
        Location:       Left  Right  External
        Gain Percent:   50
        Num Children:   0
    Device 1:
        Changable:      Gain
        ID:             0x22
        Kind:           PhysicalOutput
        Use:            Export
        Format:         LinearSigned16LSB
        Num Tracks:     2
        Access:         Export  List
        Description:    "Stereo Channel Output"
        Min Rate:       5000
        Max Rate:       44100
        Location:       Center  Internal
        Gain Percent:   50
        Num Children:   1
        Children:       0x21
    Device 2:
        Changable:      Gain
        ID:             0x21
        Kind:           PhysicalOutput
        Use:            Export
        Format:         LinearSigned16LSB
        Num Tracks:     1
        Access:         Export  List
        Description:    "Mono Channel Output"
        Min Rate:       5000
        Max Rate:       44100
        Location:       Center  Internal
        Gain Percent:   50
        Num Children:   0
Number of Buckets:      0
root@clitunno:~# serverReset();
setTimer(rate = 0);
closeDevice: out
closeDevice: output device already closed
closeDevice: mixer
closeDevice: mixerdevice already closed
 done.
AuInitPhysicalDevices();
Init: will close device when finished with stream.
Init: Leaving the mixer device options alone at startup.
setTimer(rate = 0);
createServerComponents(...);
I try aupanel too and now it opens, showing input mode Line-in (selected) and Microphone, but Output mode grayed out. What is this with needing both an input and an output device?

I do a strace on alsamixer to find out where the sound device nodes really are -- the alsa configuration is in /usr/share/alsa/alsa.conf, and alsamixer is using /dev/snd/controlC0. You can check which cards are defined by issuing
cat /proc/asound/cards
Alsamixer will start with one of these commands
alsamixer -c 0
alsamixer -D hw:0
However, let's disregard the TV card for now and assume I only have one sound card -- what I need is a way to pipe that to tcp. How do I do that?

I issue,
nmap clitunno
8000/tcp open  http-alt
So the sound is now being piped to port 8000! So that's some progress. Then on clitunno, I try to start alsaplayer so that it plays to nas rather than to the speakers:
# alsaplayer -o nas
The NAS documentation is atrocious. I had a look at the documentation in /usr/share/doc/nas, which is embarrassing; that in /usr/share/doc/nas-doc is not much better. There are really no instructions. The man page is not bad, but it assumes you know how NAS works. To see the ps files, use gs and page up to go backwards.

I guess this is a good example of how making something work just takes too much time and energy.
  • I could try EsounD, but it's for Gnome.

Music Player Daemon (mpd)

You could use mpd (music player daemon), which is in Debian. It would run on trevi, and then you'd run a client such as mpc (command-line), gmpc (gtk 2.2, in Debian), glurp (gtk 2.4), ncmpc (ncurses) on sigillo.

I installed mpd on trevi as a system daemon) -- it pulled in no dependencies. You can start it:

just start mpd
I don't need to run it as a system daemon, but installing it this way helps me configure it. I set the music files to /usr/share/mpd/music (use symlinks to /vc/music) and the playlists to /usr/share/mpd/playlists. Port MPD listens on is 6600.  The database got created (empty at first) and mpd starts. To recreate the database, issue
mpd --create-db
I then installed mpc on both clitunno and sigillo and issued this on sigillo:
export MPD_HOST=trevi && export MPD_PORT=6600
I then installed gmpc and can control music from both systems -- but it only plays on clitunno.  With some work you could likely get mpd to play on sigillo, but it's not clear it's any better than other clients.



 

 

 

top
Debate
Evolution
CogSci

Maintained by Francis F. Steen, Communication Studies, University of California Los Angeles


CogWeb