Tuesday, October 9, 2012

Csound Mini-Lesson 3: Kicks in Csound

Kicks are the heartbeat in music. A wonderful pulse that gives music liveliness. In electronic dance music, it is the most important aspect of a track.

There is more than one way to make a kick synthetically. I'm going to show you the way I make my kicks.

By the end of this tutorial, you'll be able to make kicks that sound like this:



So, let's get started!

PART 1: the "boom"

The first part of our kick will be what I call the "boom" of the kick. This is the main part of our kick. To make this, we will start of by putting a 60hz sine wave through an exponential envelope:

gisine ftgen 0, 0, 4096, 10, 1
instr 1   
kenv expseg 1, .6, 0.0001
a1 oscil .9*kenv, 60, gisine
outs a1, a1
endin

This is known in the industry as an "808" kick (though I highly doubt this is how it actually was done on a tr-808.) Useful for layering, but there isn't enough body for a main kick. What I do is create a line which goes from a little over 60hz to a little bit under 60hz. If done very quickly (under 500ms), this can be perceived as a percussive sound:

gisine ftgen 0, 0, 4096, 10, 1
instr 1   
kdrop linseg 120, .2, 40
kenv expseg 1, .6, 0.0001
a1 oscil .9, kdrop, gisine
outs a1*kenv, a1*kenv
endin

This sounds a lot better! If your music is a sparse, this might be a good stopping point. If not, you may need to add a some click. You may also notice that instead of applying the amp envelope at the oscil opcode, I applied right at the output. Since all we are doing is scaling a signals frequency, both places work!

PART 2: the "click"

Another aspect of a kick is it's click. This high frequency content will define the attack of the instrument. To make this, we will take a white noise generator and put it through a very fast envelope. I played around a little bit with balance and changed some routing:

gisine ftgen 0, 0, 4096, 10, 1
instr 1   
kdrop linseg 120, .2, 40
kenv expseg 1, .6, 0.0001
arand rand .05
kclik linseg 1, 0.004, 1, 0, 0
a1 oscil .9, kdrop, gisine
aOut = (a1 + (arand*kclik))*kenv
outs aOut, aOut
endin

Here is a line-by-line play of our final kick, bottom to top:

"endin": the instrument end tag.

"outs aOut, aOut": send the audio signal aOut to our left and right speakers.

"aOut = (a1 + (arand*kclik))*kenv": Mixing our click and boom together. Order of operations matter here. (arand*kclik) is our click. we are taking our white noise and multiplying it by our fast envelope. a1 is our boom. We are combining our boom and click together and then multiplying that by one envelope. This makes it sound more unified.

"a1 oscil .9, kdrop, gisine": Our oscillator creating our "boom." Amplitude of 9, linear envelope modulating pitch, f-table referencing sine.

"kclik linseg 1, 0.004, 1, 0, 0": This is our very fast envelope (4ms) that will make our click.

"arand rand .05": white noise generator.

"kenv expseg 1, .6, 0.0001": exponential envelope which will shape the amplitude of our kick.

"kdrop linseg 120, .2, 40":  linear envelope which quickly jumps from 120 to 40 hz.

"instr 1": instrument begins. it has an ID of 1

"gisine ftgen 0, 0, 4096, 10, 1": our generated sine wave in an f-table. has a global i-rate variable called "gisine."




And there you have it!

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
endin

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.







https://github.com/zebproj/csdfiles/blob/master/snare.csd