Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can PERL play a sound?

Status
Not open for further replies.

NateBro

Programmer
Sep 1, 2004
233
US
I was looking at the audio Mod's on cpan.org and google, but didn't see anything about PERL playing a sound. is there a way to input a frecuency into PERL and output a sound? if not, what would be the best way to go about doing so?

thanks for your time!
Nate_Bro
 
Thanks, but for some reason it does not play on my computer, but i found Win32::Sound and it works good, only i can't get it to play a pacific frequency that i want.

this is the part i'm having trouble with...
Code:
    # Generate 44100 samples ( = 1 second)
    for $i (1..44100) {

        # Calculate the pitch 
        # (range 0..255 for 8 bits)
        $v = sin($counter/2*3.14) * 128 + 128;    

        # "pack" it twice for left and right
        $data .= pack("cc", $v, $v);

        $counter += $increment;
    }

how can i get this to play a list of random freq. like: 122 125 100 40 52... ?

any help would be great! :) thanks for all your time!
 
Code:
my $random = int(rand(100)); # returns a random integer from 0 to 99

my $random = int(rand(100)) + 50; # returns a random integer from 50 to 149

my @array = (
   122,
   125,
   100,
   40,
   52,
);
my $random = $array [ int(rand(scalar(@array))) ]; # returns random element from @array


-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
I'm sorry, i was not very clear on what the problemo was, i know how to get a random number, but i can't seem to get one to play right.

lets say i want to play freq. 120 if i make $counter = 120; it will not work. if i make $v = 120; it will not work.

Code:
 $v = sin($counter/2*3.14) * 128 + 128;    

        $data .= pack("cc", $v, $v);

i'm guessing that $v has to be some kind of multiple of the play rate, 44100. but i can't seem to find the right equation.

thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top