Looper Prototype

I built a performable looper prototype this past Sunday night. At this point, all it can do is start and stop two loops and a metronome. Rough around the edges is an understatement, though there are a few points of interest worth mentioning.

Rather than use Csound’s built-in tempo engine, I built one from a phasor. Players can trigger, retrigger and stop loops from the ascii keyboard. Triggering is also quantized to the beat, similar to how clips in Ableton Live are handled.

All in all, the whole thing came together in about two hours, plus another hour to tidy things up. Sure, there are some glaring flaws to the current design, but these things will improve with revision. For example, only two loops are supported, and they are hardwired into the engine. Samples and their mappings need greater levels of flexibility if this thing is going to be useful to anyone.

If you’re curious to try it out, download looper_prototype.csd. You will also need two samples from the OLPC sound library. The first is “110 Kool Skool II.wav” by BT, included in BT44.zip. The second is “BNGABetterArpeggio01.wav” by Flavio Gaete, included in FlavioGaete44.zip. Just drop these two samples into the same folder as the csd before running. You can replace these with your own loops, just make sure that you also update the values of the tempo loop macros, right above where the samples are loaded in the orchestra.

Here are the keys (lowercase only):

a – trigger loop a
z – stop loop a
s – trigger loop s
x – stop loop s
d – turn on metronome
c – turn off metronome

I’ll post a newer version once improvements to the design have been made.

Deep Synth — Dynamically Generated Oscillators

The situation — You want an instrument that can play any number of oscillators, determined by a p-field value in the score. The problem — Unit generators cannot be dynamically created in an instrument with a simple loop. One possible solution — Multiple events can be generated in a loop, with each event triggering an oscillator-based instrument.

Download: Deep_Synth.csd
Listen: Deep_Synth.mp3

The Csound file Deep_Synth.csd provides an example of how to dynamically generate oscillators using the compound instrument technique. A compound instrument is two or more instruments that operate as a single functioning unit. This particular compound instrument is built from two instruments: DeepSynth and SynthEngine. SynthEngine is, you guessed it, the synth engine, while DeepSynth is a player instrument that generates multiple events for SynthEngine using the opcodes loop_lt and event_i:

i_index = 0
loop_start:
    ...
    event_i "i", $SynthEngine, 0, idur, iamp, ipch, iattack, idecay, ipan,
            irange, icps_min, icps_max, ifn
loop_lt i_index, 1, ivoices, loop_start

If you are wondering why we can’t just place a unit generator, such as oscil, inside of a loop, read Steven Yi’s articles Control Flow Pt I and Pt II. Pay special attention to the section IV. Recursion – Tecnical Explanation near the end of Pt. II. Not only does Mr. Yi do an excellent job explaining these technical reasons, but he also provides another applicable solution for creating multiple unit generator instances utilizing recursion and user-defined opcodes.

Sound Design

The instrument SynthEngine uses a single wavetable oscillator, an amplitude envelope and the jitter opcode to randomly modulate frequency. A single instance of DeepSynth can generate multiple instances of SynthEngine. DeepSynth can generate a single instance, or 10,000+. Users have control over the depth of frequency modulation, as well as the rate in which jitter ramps from one random value to the next. Panning between instances of SynthEngine is evenly distributed.

“Turn it up!” – Abe Simpson

The name DeepSynth is a homage to Dr. James A. Moorer‘s piece Deep Note, also known as the infamous THX Logo Theme. Very early in the design, it became evident that DeepSynth is capable of making very Deep Note like drones. This is due to the fact that it does utilize some of the defining techniques used in Dr. Moorer’s piece.

I highly recommend reading Recreating the THX Deep Note by Batuhan Bozkurt at EarSlap. The author conveniently walks readers through each step of the process, providing both audio and Supercollider code examples. If you have ever yearned to create that amazing sound for yourself, here’s your opportunity.

Sensing Angels

Sensing Angels

by Charles Gran
in three movements
for solo clarinet and electronics with improvisation

Performed by Jesse Krebs
Recorded Sunday, November 8, 2009

…Sensing Angeles was conceived as a solo piece in which the acoustic sound of the clarinet would be manipulated in real-time by a computer. Today, this isn’t so remarkable and can be achieved by a variety of means. For the project I chose to use Csound primarily as a challenge, but also for a certain kind of historical connection.

If the clarinet is an instrument with history so is Csound. A direct descendant of software created at Bell Labs in the 1950s[2], many would consider it antique in the same way the clarinet might be seen. Of course, it turns out they are both quite modern. Like most things, modernity is about use. Today, the use of a command-line interface and computer code for the creation of music is as much a point-of-view as a practicality…

Listen

Normalize Your Render

Here’s a somewhat controversial hack that let’s you normalize a Csound composition during the rendering process, scaling the amplitudes using Csound’s 32-bit or 64-bit resolutions.

This hack requires two renders. The first time you render a composition, look for the overall amps value at the end of the output message. It will look something similar to this:

end of score.           overall amps:  0.64963

Next, you need to calculate the +3dB value above the overall amps value. Here is a function that does the trick, where x is overall amps:

f(x) = 10 ** (3.0 / 20.0) * x

Or if you want to skip most of the math involved:

f(x) = 1.4125375446227544 * x

Plug 0.64963 into x, and you get 0.91762676511328001. Set 0dbfs to this:

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
;0dbfs = 1.0
0dbfs = 0.91762676511328001  ; 3dB normalization

Render again. Done.

This is a Hack

Though I do love this technique, I highly recommend that you use it only for a few situations, and certainly advise that you don’t make a habit of it.

I like to use this when I’m finished with a composition, and I’m ready to make a master audio file. This allows me to squeeze out a tiny bit of extra sound quality by scaling the audio inside csound64′s internal 64-bit float resolution. Which in theory, will do a better job that if I did the same process to a rendered sample of a lower bit resolution.

This can also be a last ditch effort for fixing problems with a final project that is due in 15 minutes. You have some minor clipping, and no time to globally adjust all your amplitudes? This could save you in a pinch.

Warning!!

This only works with absolute amplitudes. If there are any relative values or opcodes in play, then this technique will fail. For example, these two lines of instrument code will not work:

a1 oscils p4 * 0dbfs, 440, 0  ; Scales the amplitude relative to 0dbfs
a2 diskin2 "foo.wav", 1       ; Scales the sample relative to 0dbfs

There are some other risks involved. If random elements exist in the composition, then the overall amps may vary between renders, which could lead to innaccurate normalization. I also highly suspect that the overall amps value at the end of the render is truncated, thus, it not pinpoint accurate — close enough for most situations.

Are you setting 0dbfs to 1.0?

Csound’s default output range is +/- 32767. Setting amplitudes with these numbers is, more or less, the hard way. The easy way is to use a normalized range of +/- 1. You can alter Csound’s output range with the 0dbfs header statement by placing it beneath the standard orchestra header, like this:

sr = 44100
kr = 4410
ksmps = 10
nchnls = 1
0dbfs = 1.0

The issue with the default 16-bit range is that it makes little sense to do so in a world of multiple bit depths (8, 16, 24, 32, 64, etc). If one is rendering a 16-bit file, the argument could be made in favor of the default range since there is a one-to-one mapping of input to output values. However, once one leaves the realm of 16-bit, values of +/- 32767 become arbitrary. On the other hand, a normalized range is not married to any single bit-depth, and translates well to other resolutions.

Besides being easier to compose and design instruments with, there are other practical reasons to adopt this good programming practice. The Csound manual says, “Using 0dbfs=1 is in accordance to industry practice, as ranges from -1 to 1 are used in most commercial plugin formats and in most other synthesis systems like Pure Data.” If you are ever to use Csound in conjunction with PD, MaxMSP, etc, this is the range you will use.

Make it habit. Start every new orchestra as if 0dbfs is every bit as important as sr, kr, ksmps and nchnls. And always set it to 1 (there are exceptions).

In case you are wondering why more orchestras out in the wild haven’t adopted this practice… 0dbfs first came into play in Csound version 4.10 in 2002. Most of existing knowledge base, such as books and tutorials, were written prior to this.