http://qs321.pair.com?node_id=197478

Rain is a computer music composition that I wrote while I was a grad student at CalArts. It is an additive synthesis piece, composed entirely out of sine waves (plus a reverb). I wrote the piece in Perl and Csound.

Listen: Rain.ogg or Rain.mp3
Csound: Rain.orc Rain.sco
Perl: Rain.pl Rain.pm Chaos.pm ComputerMusic.pm ScoreFilter.pm

As a computer musician, I can't stress enough how important of a tool Perl is to me. Perl allows me to do things in Csound that would normally be impossible or impracticle. Without Perl, Rain would have never been written.

Good or bad, I'd really love to hear your thoughts / criticism.

Also... I'm not sure if "Cool Uses for Perl" is the best place to post my Perl compositions. If you feel there is a better place, please let me know where and why you feel it belongs there.

Enjoy!

jake
  • Comment on Rain - Musical Composition written with Perl

Replies are listed 'Best First'.
Re: Rain - Musical Composition written with Perl
by blakem (Monsignor) on Sep 13, 2002 at 10:00 UTC
    That certainly is a 'Cool Use for Perl' (I'm listening to it right now) but this phrase confuses me:
    composed entirely out of sine waves (plus a reverb)
    Can't all sounds be "composed entirely out of sine waves"? Isn't that what the Fourier transform is all about?

    -Blake

      Can't all sounds be "composed entirely out of sine waves"? Isn't that what the Fourier transform is all about?
      Good questions.

      In a nutshell... Yes. As a general rule, all sounds can be composed of sine waves. The fourier transform breaks down a waveform into a series of sinusoids, each with its own frequency, phase and amplitude. The sum of these sinusoids equals the original waveform. I'm guessing you already know this.

      Although I am using sine waves, the difference here is that there is no original waveform. Every bleep you hear is constructed entirely from scratch using sine waves. This is called additive synthesis in the world of sound design. Breaking down vs. Building up.

      As for the reverb... After the bleeps are generated, they are sent through the reverb instrument to spatialize the sound. Hope I've answered your questions.
        Ah, got it. So its the difference between "The Brooklyn Bridge consists of individual atoms" and "The Brooklyn Bridge was designed and built at the atomic level from individual atoms." The former is trivially true, the latter is quite a different story.

        -Blake

Re: Rain - Musical Composition written with Perl
by mojotoad (Monsignor) on Sep 13, 2002 at 16:16 UTC
    Soothing music. Sounds nice. Is the beat supposed to be natural/chaotic, or jazz?

    Personally I'd be tempted to post the comositions into Perl Poetry, even though strictly speaking, the sounds aren't "composed of the Perl language". But they do sound like strings of pearls.

    Matt

      My intent was to make the rhythms to sound as natural as possible. I love listening to the patterns the rain makes, and I made my best attempt to emulate these patterns. I used a simple chaos equation for choosing rhythms because I think it sounds more natural than the rand function. Chaos is also very motivic.

      If it sounds like jazz, it's probably because I went to jazz school for 4 years. :) Although I studied electronic music instead.
Re: Rain - Musical Composition written with Perl
by Flexx (Pilgrim) on Sep 13, 2002 at 18:23 UTC

    ++jake Way cool! I like the surprise at the final best. This really sound crystal clear on my machine..

    I wonder, did you compose this in a traditional manner ("That's what I want to hear, how will I get it?"), or are parts of this random/formulated/calculated ("Let's see how this sounds?")?

    I'd love to hear some details on the approach you took in composing this (but maybe that does not belong here?

    So long,
    Flexx

      A little of both. When I was designing the instrument, I definately took the "Let's see how this sounds?" approach. I did a lot of experimenting generating csound code with perl. After my experiments, I had a bunch of material that was ready to be made into the piece. Rain was part of this material.

      When I was ready to compose Rain, the instrument had already been developed. I took my Rain instrument and made it a perl sound object (Rain.pm).

      But as for composition goes, it was very much a "That's what I want to hear" type thing. I spent a long time fine tuning the sections of the piece and rewritting code to get it do pseudo-exactly what I wanted to do. I say pseudo-exactly because it doesn't generate the exact same csound score everytime. But it always generates within the limits of where I want everything to be.

      I should also point out that the Rain sound is based on something I call a Harmonic Tree.

      The whole thing took 9 months to complete. But to be fair, I wasn't working on it the entire time.
Re: Rain - Musical Composition written with Perl
by charnos (Friar) on Sep 13, 2002 at 17:01 UTC
    Howdy,

    I'm a CS major still working on an undergrad degree with a minor in music, so this is very intriguing. However, I'm not much up to speed on the science of computer music (Fourier transforms, additive synthesis, etc.). Are there any links you've found useful that could point me (and other curious monks) towards resources in this topic? Also, I'm curious...is additive synthesis the method that was used up till the mid 90's (when ROM's had enough memory to contain samples) by the game industry to recreate voices and such?

      I am a musician myself (voc, perc), but I am not a synthesizer specialist. Howerver, AFAIK, in the early days of sound synthesis, all sounds were derived from simple waveforms (like sine, square, triange, chainsaw (like triangle but with a steep upward/downward flank), and so called envelopes (you could call them amplitude operators), which were "imposed" on those waveforms. This envelope was described by four parameters: attack, decay, sustain, and release (or short ASDR).

      • A (time to reach maximum amplitude from keypress)
      • D (time to drop to sustain amplitude after reaching max amplitude)
      • S (amplitude to keep as long as the key is pressed)
      • R (time to reach zero amplitude from S amplitude after key release)

      AFAIK, A and S were linear, and the D and R parts of the envelope where parabolic.

        A       D       S      R
             o
            o o
           o   o
          o       o
         o           oooooooo
        o                   o
       o                     o
      o                         o
      

      Later 6 or more parameters where usual. Most of the modern soundcards still have ADSR/FM synthesizers build in. A famous specimen of these was the Yamaha OPL-3 chip all SoundBlaster cards had on them.

      I hope this is somewhat interesting, ;)
      so long,
      Flexx

Re: Rain - Musical Composition written with Perl
by zentara (Archbishop) on Sep 13, 2002 at 15:52 UTC
    Hi, I don't want to sound dumb, but how do you actually use this to listen? I'm using the Rain.pl and it runs, with some errors, and produces a Rain.sco file. What do I do with the Rain.sco? The error is : Use of uninitialized value in subtraction (-) at /home/zentara/perl5lib/ComputerMusic.pm line 66.
      The entire process works in three stages:

      Perl -> Csound -> Soundfile

      Perl is the top level in this chain. It's where I compose the piece. Rain.pl generates Rain.sco. Csound is a synthesis language. Csound takes Rain.sco and Rain.orc and generates a soundfile.

      As for the errors, I'm not getting those on my machine. But I take full responsibility for anything broken in my code. :)

        Nothing broken here, the message is just a warning, not an error. The reason it does not occur on your machine might be that you're using differnt perl builds.

        So long,
        Flexx

Re: Rain - Musical Composition written with Perl
by blackadder (Hermit) on Sep 20, 2002 at 08:38 UTC
    Very Good.
Re: Rain - Musical Composition written with Perl
by Mr. Muskrat (Canon) on Feb 16, 2004 at 05:17 UTC
    Did anyone happen to keep the files that jake linked to? The links do not work anymore (you get a search page). jake hasn't been here in 57 weeks as this is being posted and his listed email address is no longer valid.