reds has asked for the wisdom of the Perl Monks concerning the following question:
Greetings fellow monks.
I am writing a small little ditty that grabs an audio stream from one machine (using Audio Hijack Pro, if you're curious), pipes it over the network to a listening daemon which then plays said audio over a stereo. I'm working over an 802.11b network (higher latency than Ethernet).
My question arises from poor results I've been seeing. I can't figure out how to buffer a couple seconds of audio so that the bursty, lagged nature of the 802.11b transmission doesn't lead to buffer underruns in aplay. Right now I'm seeing an underrun every second or so. Nasty.
On the client side (sender), I've got a basic:
my $buf; while ( read(STDIN, $buf, 128) ) { print SOCKET, $buf; }
On the server side (receiver), I've currently got this:
# open up our pipe and turn off the default buffering open AUDIO_OUT, "|/usr/bin/aplay -f S32_BE -r22050 -c2 --buffer-time=5 +00000 -" or die "aplay pipe broken\n"; select(AUDIO_OUT); $| = 1; select(STDOUT); my $stream; # these 2 lines are an attempt to fill up aplay's buffer # it doesn't appear to work at all read(CLIENT, $stream, 512); print AUDIO_OUT $stream; # read the stream and dump it out to aplay while ( defined( $stream = <CLIENT> ) ) { print AUDIO_OUT $stream; }
I've seen some disucssion here about sysread() vs. read(), but I can't seem to figure out how I would dump the audio to AUDIO_OUT without print() (you're not supposed to mix buffered functions with unbuffered ones).
Any help would be greatly appreciated! Chris H.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Audio Stream Buffer
by Zaxo (Archbishop) on Jul 01, 2004 at 01:36 UTC | |
by tachyon (Chancellor) on Jul 01, 2004 at 02:17 UTC | |
by reds (Novice) on Jul 01, 2004 at 03:57 UTC | |
Re: Audio Stream Buffer
by tachyon (Chancellor) on Jul 01, 2004 at 02:02 UTC | |
by reds (Novice) on Jul 01, 2004 at 03:13 UTC | |
Re: Audio Stream Buffer
by monkey_boy (Priest) on Jul 01, 2004 at 08:27 UTC | |
Re: Audio Stream Buffer
by aquarium (Curate) on Jul 01, 2004 at 06:07 UTC |