in reply to Measuring the sound level (dB(A)) with PERL

I am stuck- can anyone help?

I find this construct quite suspicious:

while(1) { if ($cnt == 8000) { } read($fh, $buffer, 1); if(defined($buffer)) { $cnt++; } }

Replies are listed 'Best First'.
Re^2: Measuring the sound level (dB(A)) with PERL
by pryrt (Abbot) on Nov 09, 2016 at 15:30 UTC

    actually, that part is correct. John-Robie is trying to calculate the amplitude every 8000 samples. Assuming it's an 8kHz sample rate on the mic, that would be related to the power for the last second of sound, which is quite reasonable thing to do.

      If I point the open() to a file containing a single byte (I don't have a /dev/dsp1), then the loop will happily run 80,000 times in less than 0.01 seconds. That's why I'm suspicious if that loop is really doing what it's supposed to do.

        Yes it does. There are just 8000 samples per second and your system is capable doing more buffer loads per second. But this does not matter to the code - this part of the code works. It there are no values from the USB device /dev/dsp1 just no values will be collected...