I, too, am a little fuzzy on how the select loop system works. Select just chooses the current FH, so how can I use that to buffer the input stream?

Also, once I have my stream buffered, could you or someone please provide a small bit of sample code for how to set up a child process? To date, my strength has been processing text files - not fancy pants networking or multiple threads!

I just tried the code below, but am beginning to understand that because the reading takes more time than it does to play 512 bytes worth of data, I get the interrupted playback. In fact, this code has also somehow corrupted the audio stream so that it plays a tone of some sort, rather like cartoon car horn sound. Learning how to set up a child process to smoothly feed aplay would really help me out!

# build up a buffer sysread(CLIENT, $read_buffer, 2048); syswrite(AUDIO_OUT, $read_buffer); # with buffer established, stream as usual while ( sysread(CLIENT, $read_buffer, 512) ) { $buffer .= $read_buffer; syswrite( AUDIO_OUT, $buffer, 512);

Thanks for your help so far. Cheers!

--------------------------

Some while later:

I've been reading and learned that threads are different from child processes. It would seem as if a thread would serve me best, since I don't want copies of all the filehandles and stuff. Is this correct? The code I have doesn't seem to execute the child code...

my $child_pid; if ( not defined($child_pid = fork()) ) { die "cannot fork: $!"; } elsif ($child_pid) { # I'm the parent # keep reading the stream while ( sysread(CLIENT, $read_buffer, 512) ) { $buffer .= $read_buffer; print "."; } } else { # I'm the child # with buffer established, stream as usual while ( $buffer ) { syswrite( AUDIO_OUT, $buffer, 512); print "-"; } exit; } waitpid($child_pid, 0);

In reply to Re^2: Audio Stream Buffer by reds
in thread Audio Stream Buffer by reds

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.