in reply to Audio Stream Buffer
I think that you will get better results from four-arg select or the higher level IO::Select.
The select loop would allow several input packets to accumulate (with the .= operator) while a stalled write to *AUDIO_OUT is cooking. Once the delay in output is resolved, you'd have all the received data to pass along.
That will be most effective if you have an intermediate child process which can quickly read and buffer what you write to it and handle writes to the audio player in its own good time.
Update: Here's a fairly dumb example of a select loop. It reads from STDIN and writes to a child of open.
Sorry I couldn't write closer to the problem, but my setup doesn't have alsasound installed.#!/usr/bin/perl open my $ofh, '-|', '/usr/bin/perl', 'lazyread.pl' or die $!; my ($inv, $ouv, $erv); $inv = $ouv = $erv = ''; vec($inv, fileno(*STDIN), 1) = 1; vec($ouv, fileno($fh), 1) = 1; $erv = $inv | $ouv; my $string = ''; { my $num = select my $in = $inv, my $out = $ouv, my $err = $erv, undef; sysread *STDIN, $string, -1, 10, length($string) or last if $in ne $inv; $string = substr($string, syswrite( $ofh, $string, length($string) +)) if $string && $out ne $ouv; redo; } __END__ #!/usr/bin/perl # lazyread.pl open my $fh, '>', 'lazy' or die $!; while (<>) { print $fh $_; sleep 5; }
reds, your fork example looks pretty good, but I think I see the problem. The child process will be unable to see changes the parent makes in its copy of $buffer. You'd need to set up IPC between the two, like a pipe or socket, to pass data.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Audio Stream Buffer
by tachyon (Chancellor) on Jul 01, 2004 at 02:17 UTC | |
|
Re^2: Audio Stream Buffer
by reds (Novice) on Jul 01, 2004 at 03:57 UTC |