Hi all - I'm trying to read a wav file into a buffer but for some reason I could only read a specific wav file size. For example, I have a wav (no.wav) that's 16K that can get read but any other file that I have that's greater then 16K won't get read. Here is my code:
#!/usr/bin/perl use IO::Socket; use FileHandle; use IPC::Open2; $file = $ARGV[0]; open (FH, $file) || return undef; $fh = *FH; $file =~ /(gsm|wav)$/; my $type = $1; if ($type !~ /gsm|wav/) { warn "Unknown file type ($file)"; return undef; } print "FTYPE: $type\n"; #sox yellowaudio.wav -r 16000 -c 1 -s -w yellowaudio16k.raw $pid = open2(*SOXIN, *SOXOUT, "sox -t $type - -s -r 8000 -w -t wav - 2 +>/dev/null") || warn ("Could not open2.\n"); binmode $fh; binmode SOXIN; binmode SOXOUT; binmode $remote; print "hello\n"; while (defined(my $b = read $fh, my($buf), 4096)) { print "b = $b\n"; last if $b == 0; $count += $b; print SOXOUT $buf; print "count = $count\n"; } close SOXOUT;
I don't know why it can't read any wav file size greater then 16K. I think it might have to do with my cpu buffer size but when I run top this is what I have:
top - 17:43:41 up 2:31, 4 users, load average: 0.00, 0.02, 0.06 Tasks: 71 total, 1 running, 70 sleeping, 0 stopped, 0 zombie Cpu(s): 3.5% us, 2.1% sy, 3.3% ni, 86.1% id, 5.0% wa, 0.0% hi, 0 +.0% si Mem: 515584k total, 399400k used, 116184k free, 27072k buffe +rs Swap: 779144k total, 148k used, 778996k free, 298108k cache +d
The buffer looks fine, so I don't know what can be wrong. Any help will be greatly appreciated. Thanks.

In reply to I need some help with open2 by Anonymous Monk

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.