Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Rain - Musical Composition written with Perl

by jake (Monk)
on Sep 13, 2002 at 08:29 UTC ( #197478=CUFP: print w/replies, xml ) Need Help??

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

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.


  • 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?


      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.


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.


      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,

      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 (

      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

    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 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           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,

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 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/ 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. 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,

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://197478]
Approved by rob_au
Front-paged by ignatz
LanX but Decryptulus understands him perfectly ;D

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-05-22 16:11 GMT
Find Nodes?
    Voting Booth?