Monday, October 1, 2012

Envelopes, Noise, and "Snares"

 Tutorial 2: Making simple EDM snares.

If your song has a beat, your song is going to have a snare. Why not try to make one yourself? Lets make some ridiculously simple snare sounds in Csound!

The concept of our synthesized snare is quite simple: take a noise source and put it through an envelope with a fast transient. You can do this on just about any synthesizer. With Csound, you can get a little bit more specific what the noise source is and what kind of envelope it is. For this example, we will be showing two different sounding envelopes and noise sources, with a total of 4 combinations.

Envelopes: Linear vs. Exponential

Envelopes are huge, especially when you are dealing with times that are smaller than half a second. An envelope with an attack time of 10ms is going to have completely different character than that of of a sound with an attack time of 100ms.

Even more drastic than the time it takes to move from point to point is how it moves to that point. In Csound, envelopes can either be linear or exponential.

A linear envelope for our snare could look like this:

    aenv linseg 1, .2, 0

The opcode called linseg is producing an envelope that linearly goes from 1 to 0 in .2 seconds. The output of this opcode is going to the audio-rate variable aenv.

An exponential envelope for our snare could look like this:

    aenv expseg 1, .2, 0.0001

The opcode called expseg is producing an envelope that exponentially goes from 1 to 0.0001 in .2 seconds. Note that 0 can’t be used in an exponential curve.

Csound’s white noise generator:
    Csound has many random number opcodes. One of these opcodes can produce random numbers at an audio rate and produce white noise:

    anoise rand .8

The opcode called rand is creating random numbers between the values .8 and -.8 to anoise. If we send anoise to our speakers, we will get white noise at 80% full scale (assuming 0dbfs=1.)

Using FM aliasing as a noise source:
    We can create very unusual sounding aliasing sounds with an FM oscillator with an absurdly high modulation index. The result is noise. But it is meaningful noise:
    gisine ftgen 1, 0, 4096, 10, 1
    afm foscil .5, 100, 1, 1, 100000, gisine
Instead of wasting space explaining what each opcode does, I suggest you check out the entry in the Csound Manual. It is a resource should never be without when working in a language as vast as Csound. Learning how to read from this manual will help you learn Csound on your own. If you are lost on what exactly a carrier or modulator or modulation index is, you can read up about it here.

It’s quite simple to put the sound and the envelope together in an orchestra file:

instr 1
iamp = p4
a1 rand iamp
aenv expseg 1, p3, 0.001
outs a1*aenv, a1*aenv

This produces a pretty common snare patch. You’ll notice I’ve made the amplitude and length parameter values so I can control them from the score like this:

i1 0 .4 .6

The duration is .4 seconds and the amplitude is 60%. Play around with duration and see how the exponential envelop shapes the sound.

Offline vs. Realtime rendering:

Csound was originally intended for offline rendering, as computers at the time had the computing power of a 10 calculator you’d buy at CVS. You’d write your Csound patch run it, and come back the next day to hear what it sounded like. Offline rendering is very useful for generating samples that you can then import into a DAW. Simply running csound from the commandline with no flags will give you a file called test.wav (or test.aif on a mac):

csound filename.csd

You can specify the output file you want with -o

csound -osnare.aif filename.csd

If you are on a Mac, files will be rendered as an AIFF file regardless of extension (unless you specify the kind of audio file you want.) Conversly, PC and Linux files will render to wav files, regardless of the extension they have on it.

For the sake of brevity, I have put the rest of today’s files onto github. You can download the file here. You’ll find 4 separate instruments, each utilizing a different envelope and noise source.

Next week, we will be building a supersaw lead sound in Csound.

No comments:

Post a Comment