Splice and Stutter

Splice and StutterToday on The Csound Blog, we’re going to learn how to build a loop-based sampler out of common household ingredients.

Listen: mp3

Download: splice_and_stutter.csdBT Sample Pack (13.2 MB)

Here’s a brief rundown of today’s example. A drum loop is loaded into an f-table with the instrument LoadSample. The instrument SampleEngine plays back selective parts of the loop. Instruments Basic, Stutter and Random are interface instruments that simplify the process of triggering samples.

The LoadSample instrument loads a sample into an f-table, while storing information about the sample into an ad hoc data structure created from chn busses. Here isn’t the place to go into detail. I will say that it is akin to a C struct, and stores the file name, sample rate, length of file (in samples), the tempo, and the number of beats (quarter notes) in the loop. All the user-defined opcodes are support opcodes for the data structure.

SampleEngine is the heart of this piece. It works by triggering discreet notes from within the loop, with the loop offset being determined by input it receives via p-field 7. The offset unit is in beats. Let’s say the loop is 16 beats long. A passed value of 0 plays the first quarter note. A value of 1 plays the second quarter note of the loop, etc.

This instrument is designed to be played by other instruments, rather than being triggered directly by a score i-event. That is…

Instead of having multiple samplers that do various things, I created a single complex sampler engine that is capable of a wider range of tricks. The problem with complex instruments in Csound is that writing score events can be cumbersome to write and certainly hard to read, especially when dealing with several parameters. This is where the interface instruments come into play.

The interface instruments Basic, Stutter and Random help us tame the complexity of SampleEngine by reducing the number of p-fields needed by the score, and by defining clear behaviors.  Basic is a no thrills controller that simply triggers part of the loop. Stutter, well, stutters. Random randomly picks a beat and plays it.

A greatly added benefit to this approach is that the score is much easier to read. Instead of trying to figure out if a particular i-event stutters or not by scanning a row of numbers, one can just casually look at the name of the instrument used. To put it another way, does this stutter?

i 5 7 1 0.25 0.5 100 12 0.083 1 0

How about this?

i $Stutter 7 1 0.25 0.5 100 12 [1 / 12]

There are a lots of ins and outs to today’s example. And I admit, I skipped over most of them. If there is a particular issue or issues you wish for me to expand on, comment below, and I’ll make it a priority to blog about it in the future.

This sampler is a derivitive work based on an instrument co-developed by Jean-Luc Sinclair (aka Jean-Luc Cohen) and myself back in 2006. The loop in today’s example is by BT (aka Brian Transeau), released under a Creative Commons attribution license, and released as part of the OLPC Sample Library. You can obtain this sample and others here. (13.2 MB) You will need the loop “105 Blanketed Lama.wav” in order to run the csd file.

Update: There is an issue with the CSD file not running on Windows Windows Me (or earlier). There is now a fix. Download the new splice_and_stutter.csd, and see line 269 for details. This only applies to users of Windows Windows Me (or earlier versions).

Thanks to everyone on the Csound Mailing List who helped straighten this out.

Csound Music mp3 Pack

Dr. Boulanger has put up a wondeful collection of Csound mp3s at Csounds.com.

Download 4csoundCompositions.zip (99.1 MB)

The pack comes with 20 songs, with everything from ambient to minimal to cheesy techno (that would be my piece) to synth-generated halloween sound fx.  All of the original source code is included in case you are curious to see what these compositions look like in their original state.

Coding in Processing Explained in Five Minutes

I’m relatively new to Processing, having spent only one solid month with the language. Within this time frame, I was able to write a complete GUI interface for Cobosoda styled after 80s vector arcade games. I don’t attribute this to my “mad programming skillz,” because I’m mediocre at best. Instead, I place the blame squarely where it belongs; On Processing.

Now that I’m a fan of the language, it is my duty to promote it on my blog, and try to get others to hop on the Processing bandwagon. For those completely new to Processing, this slideshare by Peter Kirn will quickly get you up to speed.

Processing: It’s the new Logo, except très cool and super powerful.

kindercrasher


kindercrasher from Inigo Quilez on Vimeo.

This is my contribution to the realtime 4 kilobytes visuals (usually known as “4k intro”) competition for Inspire 2008 (held in Spain). It is a set of spheres with radious controlled by the Fourier Transform (without the “fast”) of the music. it contains some realtime ambient occlusion and depth of field. It’s done in C, using shaders (GLSL). Once again, it all fits in a 4 kilobytes executable (music, animation, rendering engine and effects).

Wicked awesome! Via Create Digital Motion.

Introducing Slipmat for Java and Csound

Yesterday, I released the first public version of Slipmat, a Java-based modular computer music library built on top of the Csound API. You can download it at Sourceforge.

Let me back up a bit…

Ever since I started Csounding about a decade ago, I’ve heard people refer to the syntax of the Csound language as being very similar to that of Assembly on numerous occasions. I certainly see their point. Let’s face it, Csound is a Frankenstein of language, stitched together with duct tape and bubble gum. And like Frankenstein, it is both powerful, yet scary to those who judge it solely on its facade. Those who turn a blind eye to Csound’s frightening nature and learn to understand it for what it is are rewarded with an amazingly expressive computer music environment. Unfortunately, most people equate their first experience with ladling hot soup onto their laps. Did I mention Csound is afraid of fire?

Continuing with the Frankenstein metaphor a little longer, Slipmat is a Java abstraction layer that attempts to tame the monster. To teach it some manners and civility. If all goes well, Csound will be putting on the ritz in no time.

Let’s take a look at a simple Slipmat java program (included with the download.) The following plays every note in a 12 note octave between 440 and 880:

import com.thumbuki.slipmat.*;
import com.thumbuki.slipmat.module.*;

public class SimpleExample {
    public static void main(String[] args) {
        SynthRack synthRack = new SynthRack(false);
        SinePerc sinePerc = new SinePerc();
        Output output = new Output();

        synthRack.addModule(sinePerc);
        synthRack.addModule(output);
        output.setInput(sinePerc.getOutput());
        
        for (int i = 0; i <= 12; i++)             sinePerc.playNote(i * 0.25, 0.9, 440 * Math.pow(2, i / 12.0));         synthRack.startCsound();                  try {             Thread.sleep(4000); /* Keep java running for four seconds */         }         catch(Exception ex) { }     } }

If we think of Slipmat as a high-level abstraction of Csound, which it is, then what happens behind the scenes is that Slipmat "compiles" Csound code, and then this code is fed to the Csound engine. This is sorta how Java produces bytecode that is executed by a Java Virtual Machine. The following is the code that is produced by the previous example:

<CsoundSynthesizer>
<CsOptions>
csound -d -A -odevaudio null.csd
</CsOptions>
<CsInstruments>
sr = 44100
kr = 4410
ksmps = 10
nchnls = 2

0dbfs = 1.0

gitable1 ftgen 1, 0, 8192, 10, 1.0

chn_a "chna0", 3

instr 1
aclear = 0.0
chnset aclear, "chna0"
endin

instr 2
a1 oscil p4, p5, gitable1
aenv linseg 0, p3 * 0.05, 1, p3 * 0.95, 0
a1 = a1 * aenv
chnmix a1, "chna0"
endin

instr 3
a1 chnget "chna0"
outs a1, a1
endin

</CsInstruments>
<CsScore>
i 2 0.0 0.125 0.9 440.0
i 2 0.25 0.125 0.9 466.1637615180899
i 2 0.5 0.125 0.9 493.8833012561241
i 2 0.75 0.125 0.9 523.2511306011972
i 2 1.0 0.125 0.9 554.3652619537442
i 2 1.25 0.125 0.9 587.3295358348151
i 2 1.5 0.125 0.9 622.2539674441618
i 2 1.75 0.125 0.9 659.2551138257398
i 2 2.0 0.125 0.9 698.4564628660078
i 2 2.25 0.125 0.9 739.9888454232689
i 2 2.5 0.125 0.9 783.9908719634986
i 2 2.75 0.125 0.9 830.6093951598903
i 2 3.0 0.125 0.9 880.0
i 1 0 -1.0
i 3 0.0 -1.0

</CsScore>
</CsoundSynthesizer>

I know what you're thinking... What the hell am I looking at? Truth is, this code is not meant for human consumption. A person who regularly writes Csound code can write code that is more clear than this. Even then, compared to Java-Slipmat code, it can look like chicken scratch. Or my handwriting.

Since Slipmat is more or less a Java library built on top of the Java-Csound API, this means all of Java's and whistles are now available to use in conjunction with Csound. Want a reliable cross-platform GUI? Give swing a try. Want to integrate Processing with you Csound? You can. Want a tool that automagically hides all the grunt work from you, such as assigning instr numbers, tables, chn software busses, etc? More than anything else in life (personally speaking.)

I should warn you... Slipmat is currently pre-alpha. Which means everything is in a state of flux, and there isn't anything that resembles a specification at this point. Methods and classes are guaranteed to change drastically over the next few months. Tutorials on the way...

Csound and the OLPC

OLPC

Flickr photo by me

Since friday, I’ve been learning the ins and outs of my XO computer. I finally got to a point this morning where I can start writing csound-based activities for it.

Using the csndsugui toolkit, I slapped together a primitive step-sequencer in about five hours. It features: An 8-step pitch slider array, two oscillators for notes, AD envelope for amplitude, tempo control, volume control, 8-step kick row and an 8-step snare row. So while it might not do much at the moment, I can certainly see myself fixing it up to a point where it’ll be a fun musical toy in the near future. I’ll post a pic in a few days, once it shapes up a bit.

Nine Inch Nails Decoder Ring

OS X:

1. Open Terminal.app located in Applications->Utilities.
2. Copy the following line of code to the terminal window. DO NOT press enter.

pbpaste | perl -pe 'foreach $Parepin ( <STDIN> ){ while( $Parepin =~ m/(fe7b02;"><em>|fe7b02;">)(.+?)</g ){ $nin = $2; $nin =~ s/s//; print $nin } }'

3. Read Secret Websites, Coded Messages: The New World of Immersive Games
4. View the source. (apple-option-u)
5. Copy the html source. (mouse click html source window, apple-a, apple-c)
6. Go back to to terminal window and hit enter.
7. Type decoded message here.