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


In reply to PVSG - A Perl Virtual Sound Generator by PetaMem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.