Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

PVSG - A Perl Virtual Sound Generator

by PetaMem (Priest)
on Jun 27, 2001 at 16:08 UTC ( [id://91886]=CUFP: print w/replies, xml ) Need Help??

Hi, this is a quite old project, so donīt look too much at the quality of the code. I always was interested in sound design. So I wrote various programs to compute sounds and to let them then be played with a sampler.

Youīll find the complete project at My Homepage

I know, that Perl isnīt perhaps the most suitable lang for this. Better said: Many people think this. What I wanted to do was a Virtual Sound Generator coupled wia WEB-Frontend and doing weird sounds, not necessary fast, but complex.

Feel free to use the snippets as you like - let me know if someone would like push this up. Some small examples:

Trivial additive synthesis. Shouldnīt be constrained to sinus only

# # Fourier Synthesis # sub fourier { my ($s1,@spectrum) = @_; my $coef; foreach $coef (@spectrum) { my @fpa = split /_/, $coef; # get frequency,phase and amp +litude &osc::sinus($s1,$fpa[0],$fpa[1],$fpa[2],1); } }
There are various oscilators in the package...and some neat low-level signal processing as for example:

# # set the maximum amplitude to 1/-1 # sub normalize { my $s1 = shift; my $max = &max($s1); &scale($s1,1/$max) if $max; } # # reduce/expand the frequency of a given sample # sub redex { my ($s1,$new_freq) = @_; my $old_freq = $$s1[$SMP_FREQ]; my $cells = $$s1[$SMP_CELLS]; my $redex = $new_freq / $old_freq; return if($redex == 1); # Nothing to be done my $newcells = $cells * $redex; my $a; if($redex > 1) { # Expand the original samp +le } elsif($redex < 1) { # Reduce the original samp +le for($a = 0; $a < $newcells; $a++) { $$s1[$a + $SMP_DATA] = $$s1[$a/$redex + $SMP_DATA]; } $$#s1 = $newcells + $SMP_DATA; } $$s1[$SMP_CELLS] = $newcells; # update the amount of cel +ls in sample }
Download it and feel free to expand, improve etc...

Ciao

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://91886]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found