@zentara:

Thanks for your reply!
This is definitely very useful!

I am using FreeBSD 5.x or 6.x and the standard sound system FreeBSD supplies.
I will work thru your samples

Again,
Thank you!

Maarten


zentara wrote:

On Mon, 14 Aug 2006 08:42:30 -0400, [EMAIL PROTECTED] (zentara)
wrote:


Here is an old script I wrote to act as an applause-meter. It's very
rudimentary, but it should show the basic idea. This script is recording
the dsp output, so you may have to have your cards "Capture" turned
on, so it will sample whatever is coming out of the sound card.

Here is a slightly improved version that will give continuous output.

I put a while(1) loop in there, and commented out the microphone
input.  I can play a song while executing this script, and the average
will go to zero right after the playing stops.

I will also mention that the ecasound package has a utility called
ecasignalview, which produces a bar like text graph output using
*.  You could run that thru a piped open and just count the *'s in the
output.
See  http://perlmonks.org?node_id=494964

However, I think you are better off using the /dev/dsp directly, like
below.

##############################################################
#!/usr/bin/perl
use Audio::DSP;
#alsamixer must be setup right, AC'97 capture adjusts sensitivity,
#just turn it up to 100 for this to work as intended

($buf, $chan, $fmt, $rate) = (4096, 1, 16 , 8000);

$dsp = new Audio::DSP(buffer   => $buf,
                    channels => $chan,
                    format   => $fmt,
                    rate     => $rate);

$dsp->init() || die $dsp->errstr();

while(1){
my $samples = 1500;
my $num_tot = 0; my $div_tot = 0;

# Record x samples of sound
for (1..$samples) {
       #read 16 bits of raw data
       my $data = $dsp->dread(16); # || die $dsp->errstr();
       my $num =  unpack( 'v', $data  );
#filter out baseline noise
       if($num > 65000){next}else{
            print  "$num ";   
           $num_tot += $num;
           $div_tot += 32768;  #gives a good average
        }
}

print "\n\nAverage ",sprintf('%0.2f',$num_tot/$div_tot),"\n\n";

}

$dsp->close();

__END__






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to