You are not logged in.

#1 2008-02-13 23:03:39

print
Member
From: teh cloud
Registered: 2007-02-27
Posts: 173

netcat: streaming audio

Ok, netcat/CLI gurus,  how can I . . .

1) Play music on box A.
2) Use cat or dd or something to push the output of /dev/dsp on A to netcat listening on A.
3) Connect to netcat on A from B, and redirect the output to /dev/dsp on B

So basically, the music playing on box A automagically plays on B.  This will allow me to queue up a bunch of music on my server and listen to it as a streaming audio unicast from my laptop.  Is it possible?

Here's one approach that I can't get to work.  I just get scratchy hiss out of my speakers . . .
http://grox.net/misc/radio/

TIA,
print


% whereis whatis whence which whoami whois who

Offline

#2 2008-02-15 05:28:21

vogt
Member
From: Toronto, Canada
Registered: 2006-11-25
Posts: 389

Re: netcat: streaming audio

mpd+icecast can do that. By the way I think that /dev/dsp is uncompressed audio, so netcatting that over a connection works over lan, but isn't a very good use of bandwidth, reincoding is an option though...

Last edited by vogt (2008-02-15 05:29:51)

Offline

#3 2008-02-15 14:03:10

print
Member
From: teh cloud
Registered: 2007-02-27
Posts: 173

Re: netcat: streaming audio

vogt,

Thanks for your reply.  I am getting to the point now with Linux where I need to understand a little more about low-level stuff, like what exactly is coming out of /dev/dsp when you cat it.  Presuming you hadn't just told me that it is uncompressed audio, how could I have figured that out on my own?  Is there some way to inspect the data at a low level?

That's a separate issue.  To respond to your mpd+icecast suggestion, I have three reasons for not wanting to got that route:
1) Icecast is just another daemon I don't need.
2) mpd is just another daemon I don't need.
3) I use cmus as my CLI audio player, and I would just as soon change that as I would change from Archlinux to something else.  It's a really fine audio player.

That being said, I think your suggestion to reincode is what I was thinking in the first place.  Something like

cat /dev/dsp | lame | netcat

on the server side should give me an mp3 stream, no?

My main trouble is understanding what is coming out of /dev/dsp so I can work with it.  The grox.net page says about that that, "The type is raw. (there is no header as from a .wav file)" but his instructions don't seem to work for me.  Do you know how I can convert uncompressed audio into something useful?

Thanks!
-print

Last edited by print (2008-02-15 14:04:19)


% whereis whatis whence which whoami whois who

Offline

#4 2008-02-15 23:24:20

vogt
Member
From: Toronto, Canada
Registered: 2006-11-25
Posts: 389

Re: netcat: streaming audio

print wrote:

Presuming you hadn't just told me that it is uncompressed audio, how could I have figured that out on my own?  Is there some way to inspect the data at a low level?

You'd have to look at some documentation, which the arch devs decided to strip out (info /usr/share/doc...), so you just have manpages to look at, and google.

It is raw pcm, which looks uninteresting at the low level. Something like  audacity can show you a graphical representation though. But if you think that it is raw audio, you can just try to play it with aplay, and see what happens.

That's a separate issue.  To respond to your mpd+icecast suggestion, I have three reasons for not wanting to got that route:
1) Icecast is just another daemon I don't need.
2) mpd is just another daemon I don't need.
3) I use cmus as my CLI audio player, and I would just as soon change that as I would change from Archlinux to something else.  It's a really fine audio player.

cmus does have more features, but if you only use a basic subset of those (simple text search, just db + stream playing), mpd is equivalent; try it though I'm sure that cmus can feed icecast too...

I wouldn't be surprised if they both took similar resources, as most of the work is dealing with the stream, not the authentication or other miscellaneous 'features'.

On top of that, if you want something to be running all of the time, daemonized processes are easier to start/stop/restart and manage. Then there is (x)inetd to look into too.

By the way, maybe you need to know the useless use of cat.

< /dev/audio | lame - | netcat .......

Would work better (note, lame wants a '-' in order to read stdin)

My /dev/dsp contains nothing for me sad
/dev/audio contains 8 bit 8000 hz pcm that sounds terrible, but arecord could pick the right output to send to a named pipe...

But as I said, there is no point in reinventing the wheel; the stuff out there is pretty good, and probably just as flexible. But as a learning experience, there are more io options in *nix than unnamed pipes, so look into them too.

EDIT: the grox.net guy did make himself an audio streaming daemon, but probably incurred more overhead (which is worse than his unjustified hate of esd and artsd), because of the uncompressed audio (or reencoding, not just passing the original mpd or ogg off)

Last edited by vogt (2008-02-15 23:29:24)

Offline

#5 2008-02-16 13:38:13

Schnouki
Member
From: Nancy, France
Registered: 2007-10-28
Posts: 21
Website

Re: netcat: streaming audio

You may need to use "lame -r -" : -r tells lame that its input file is raw PCM and not a WAV or AIFF file.

And I'm not sure if it is what you want, but it would maybe be interesting to configure cmus to output on a named pipe instead of /dev/dsp, and then to use this named pipe as a source for lame. This would make your music play on your laptop only.

(And why not using "oggenc -r -" ? wink)


There's no place like ::1

Offline

#6 2008-02-16 15:43:08

print
Member
From: teh cloud
Registered: 2007-02-27
Posts: 173

Re: netcat: streaming audio

Schnouki, I considered the idea of changing the cmus output device; however, that means that when I want to listen to music on my server I have to switch it back, or change a symbolic link.  Could be done, but kind of hackish.  Right now I have a hellacious school schedule, but in a few months I will have more time to devote to this, and I will do so.  Thanks for your ideas


% whereis whatis whence which whoami whois who

Offline

#7 2008-02-16 18:11:20

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: netcat: streaming audio

you could use tee for creating 2 data streams (I'm not exactly sure about what I just said smile )
mkfifo audio.init audio.network
set the oss program to output to audio.init instead of /dev/dsp
cat -A audio.init > tee audio.network > /dev/dsp

now you have the audio stream to audio.network and to /dev/dsp (I think, since it looks ridiculous)
you can then open audio.network with netcat.
Today I spent some time trying to record/play some raw streams through alsa unsuccesfully... I was more successful through oss emulation.

Offline

#8 2008-02-17 20:17:54

print
Member
From: teh cloud
Registered: 2007-02-27
Posts: 173

Re: netcat: streaming audio

carlocci... could you be a little more specific?

AFAIK, /dev/dsp is oss, whereas pcm devices in /dev/snd are alsa.  here's my listing, do you have something similar?

# ll /dev/snd
total 0
crw-rw---- 1 root audio 116,  0 2008-02-09 06:54 controlC0
crw-rw---- 1 root audio 116,  4 2008-02-09 06:54 hwC0D0
crw-rw---- 1 root audio 116,  8 2008-02-09 06:54 midiC0D0
crw-rw---- 1 root audio 116, 24 2008-02-09 06:54 pcmC0D0c
crw-rw---- 1 root audio 116, 16 2008-02-09 06:54 pcmC0D0p
crw-rw---- 1 root audio 116, 17 2008-02-09 06:54 pcmC0D1p
crw-rw---- 1 root audio 116, 18 2008-02-09 06:54 pcmC0D2p
crw-rw---- 1 root audio 116,  1 2008-02-09 06:54 seq
crw-rw---- 1 root audio 116, 33 2008-02-09 06:54 timer

% whereis whatis whence which whoami whois who

Offline

#9 2008-02-21 20:17:42

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: netcat: streaming audio

cat /dev/urandom > /dev/dsp works
cat /dev/urandom > /dev/snd/pcmwhatever produces errors.

So, whereas "cat foo.wav > /dev/dsp" lets you hear the soundfile, "cat foo.wav > alsaplaybackdevice" doesn't.
Unless you use aplay/arecord.

I was disappointed since I always thought being able to stream to the audio card directly to be kind of cool.

Offline

Board footer

Powered by FluxBB