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