Sound Design Project

In this project, we’ll load a recorded sound file into Csound and then process it in various ways. Rather than generate notes, we’ll look at a few of Csound’s many sound design techniques.

Load a Sound File into a Table

Create a new file in CsoundQt and add the same header used in the first tutorial in this chapter. Your starter file should look like this:


  <CsoundSynthesizer>
  <CsOptions>
  </CsOptions>
  <CsInstruments>
  sr = 44100
  ksmps = 4
  nchnls = 2
  0dbfs = 1
  </CsInstruments>
  <CsScore>

  </CsScore>
  </CsoundSynthesizer>

Csound will look for an audio file to load in the directory you’ve specified using the environment variable SSDIR or SFDIR. These variables can and should be set in the Environment tab of CsoundQt’s Configuration box. Set them to the directory where you have your audio source files stored.


image

Note In the version 0.6 release (called QuteCsound), the Configurations fields for SSDIR and SFDIR don’t work. If you’re using this version, you’ll have to specify the entire path to the sound file within your .csd code. In CsoundQt 0.7, this bug has been fixed.


This time, instead of using a ftgen opcode, we’ll create a table using Csound’s original method, using an f-statement in the score. These two methods are entirely equivalent and interchangeable. To load the file into a Csound table (a RAM memory area), add the following line to the start of the score (after <CsScore>), substituting your filename for olive.aiff:


  f 1 0 0 1 “olive.aiff” 0 4 0

If you’re using version 0.6, or if for some reason Csound is unable to find the settings for SSDIR and SFDIR, you can specify the entire directory structure, from the root of the hard drive, like this:


  f 1 0 0 1 “C:/Users/Jim Aikin/Documents/csound
  scores/samples/olive.aiff” 0 4 0

This f-statement uses a Csound routine called GEN 01 to load the audio data. For more information on the parameters you might need to change, look up GEN 01 in The Canonical Csound Reference Manual.

Create an Instrument and a Score

The easiest way to play a sampled sound is with Csound’s loscil opcode. Here is a basic instrument:


  instr 1
  audio loscil p4, 1, 1, 1
  outs audio, audio
  endin

The third input to loscil is the number of the table we want to use. We created this in the score with f 1, so we use a 1 here to access the table. In complex Csound scores, we might pass different f-table numbers to the instrument using p-fields, in which case a single audio playback instrument could make many different sounds, just like any other sample playback module.

The output of loscil can have any name we like, as long as it begins with the letter a-. Here I’ve used “audio” as it makes the code easier to read. My file is mono, so I gave loscil only one output. If the file were stereo, the left end of the loscil line would need to say something like aL, aR, and these same values would be used with outs.

In order to play the instrument, we need to add an event to the score. But how long should the event be? That depends on how long your source file is. Mine is a little more than 16 seconds, so my score event looks like this:


  i1 0 17 0.5

The value in the third field (p3) is the length of the note, and p4 is used by the instrument to control the amplitude. The length of the note has no direct relation to the length of the audio file; the two are independent. If you only want to hear the beginning of the file, create a short note.


image

Caution In versions 5.13 and older of Csound, loscil is limited to files of less than a minute in length. The exact maximum length depends on whether the file is stereo or mono, on the sampling rate, and on other factors. If your code seems to be correct, but loscil produces no sound when trying to play a longish file, you’ll need to use poscil or tablei instead.


Change the Playback Speed

The second argument to loscil is the sample playback speed. Instead of setting this to a fixed value of 1, as above, we might want to create a ramp so that the playback speed starts slow and then speeds up. Replace the loscil line with these two lines:


  kramp line 0.5, p3, 1.5
  audio loscil p4, kramp, 1, 1

The line opcode creates a ramp signal. Here, it starts at 0.5, and during the duration of the note (p3) it increases to 1.5. The output of line, which I’ve named kramp, is sent to loscil. Play the file to hear the result.

Here’s another possibility. Before entering the code into your project, see if you can guess what the sound will do.


  klfo lfo 0.2, 7, 1
  audio loscil p4, klfo + 1, 1, 1

The lfo opcode is set to play a triangle wave at 7 Hz, with a fairly shallow amplitude of ±0.2. We add this to the playback speed parameter of loscil to produce a warbling effect.

These audio effects are fairly trivial, though. Let’s try something more interesting.

Add Ring Modulation

Get rid of the LFO and add an ordinary oscil. The new instrument should look like this:


  instr 1
  audio loscil p4, 1, 1, 1
  asine oscil 1, 200, 2
  audio = audio * asine
  outs audio, audio
  endin

In order to use this instrument, we need a second table containing audio data. We’ll create the same sine wave as in the first tutorial, but this time we’ll do it in the score:


  f2 0 8192 10 1

This is f-table number 2, so we use 2 as the final input to the oscil.

Ring modulation is a very simple, yet exotic-sounding effect. It’s created by multiplying one audio signal by another. The only danger to be aware of is that we don’t want the two signals to have an amplitude greater than 1. If each of them hits a peak level of 2, for instance, at any point in the waveform, the output will have peak levels of 4. Assuming that your orchestra header specifies 0dbfs=1, a peak level of 4 will certainly cause drastic clipping. That’s why the sine wave above is created with an amplitude of 1.

Play this instrument and listen to the sound quality. I find ring modulation especially useful with vocal samples. Try different values for the frequency of the oscil by replacing 200 with a higher or lower number.

Instead of using a fixed frequency for the sine wave, we can restore the ramp generator we were using before and modulate the frequency of the sine wave with it. Replace the oscil line with these two lines:


  kramp line 200, p3, 1000
  asine oscil 1, kramp, 2

Now the frequency of the modulating oscillator will rise from 200 Hz to 1000 Hz during the course of the event.

Modulate the Playback Speed

In order to play with the audio source file more flexibly, we need to replace loscil with a phasor and a table. In place of the loscil line, insert these four lines:


  aphas phasor 1/p3
  ifilelength = 709288
  aphas = aphas * ifilelength
  audio table aphas, 1

You should use the actual length of your source file in samples as ifilelength. In addition, you’ll need to make a minor change in the score. We created table f1 with a length of 0. Obviously, the length of the sound file isn’t 0; using 0 for this parameter is simply a way of letting Csound set the length of the table based on the actual length of the file. But this strategy isn’t compatible with the table opcode. We need to create a table whose length is a power of 2— the next power of 2 greater than the size of the audio file we’re using. The exact value you use will depend on your source file.


  f1 0 1048576 1 “olive.aiff” 0 4 0

The instrument should sound pretty much the way it did before. The advantage of using phasor is that we can mess with its output, thereby scanning the sound file in various ways. We can make it back up, for instance. Add an LFO to the input of the phasor, like this:


  klfo lfo 1, 0.25, 1
  aphas phasor (klfo + 0.1)/p3

Depending on your source material, you might want to adjust any of these values. Here’s a slightly more complex instrument, in which the audio file is being scanned by two table opcodes, each under the control of its own phasor. The outputs are sent to the left and right speakers.


  instr 1
  kphasramp line 0.1, p3, 1.5
  klfo lfo 1, (0.1 + kphasramp), 2
  aphas phasor (klfo - kphasramp)/20
  aphas2 phasor (klfo + kphasramp)/20
  ifilelength = 709288
  aphas = aphas * ifilelength
  aphas2 = aphas2 * ifilelength
  audioL table aphas, 1
  audioR table aphas2, 1
  outs audioL, audioR
  endin

The lfo opcode is set to produce a square wave (the 2 at the end of the line), so the sound plays forward and backward alternately.

Add a Delay

To make the sound a little more complex and interesting, we’ll finish this tutorial by adding a stereo delay. As with the first tutorial in this chapter, we’ll start by creating a stereo send bus in the orchestra header area (directly below the line 0dbfs=1):


  gaDelaySendL init 0
  gaDelaySendR init 0

Next, we send the left and right signals from the sample player to this bus. Let’s reverse the sends, sending the right channel to the left bus and vice versa. Put this code near the end of instrument 1, just before the line with the outs opcode:


  gaDelaySendL = audioR
  gaDelaySendR = audioL

Because we’re using only one instance of the sample playback instrument, we don’t need to add audioL and audioR to whatever signal is in the bus; we can just copy them into the bus using the equals sign.

One odd thing about Csound’s implementation of delay lines is that we have to read from the output of the delay before we write (send a signal) to it. For our delay instrument, we’ll create two delay lines, one each for the left and right channels, and we’ll use cross-feedback. Because we’re going to send the signal in adeloutR to the input of the left delay line, we have to create this signal using the init opcode before using it. Here is the complete instrument:


  instr 100
  ilevel = p4
  ifeedback = p5
  itimeL = p6
  itimeR = p7
  ainL = gaDelaySendL
  ainR = gaDelaySendR
  gaDelaySendL = 0
  gaDelaySendR = 0
  adeloutR init 0
  adeloutL delayr itimeL
          delayw ainL + (adeloutR * ifeedback)
  adeloutL dcblock2 adeloutL
  adeloutR delayr itimeR
          delayw ainR + (adeloutL * ifeedback)
  adeloutR dcblock2 adeloutR
  adeloutL = adeloutL * ilevel
  adeloutR = adeloutR * ilevel
  outs adeloutL, adeloutR
  endin

Note the use of dcblock2 here. This is a safety precaution, to prevent the possible buildup of DC (direct current) offset in the delay line’s feedback loop. Another safety precaution is setting the level of the send bus signals back to zero after the signals have been received by the delay line.

This instrument will need seven p-fields in the score—for duration, output level, feedback level, and the left and right delay times. Here are the two events in my final score:


  i1 0 26
  i100 0 30 0.5 0.3 0.5 0.75

The exact numerical values you choose for the parameters sent to instruments of this sort will depend heavily on your source material. The best way to discover what sounds good is usually to try out a bunch of things until you start to develop a feel for what works.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.35.58