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.

Step and Funny Talk for the OLPC

I spent my spare time last week developing two audio-based activity prototypes for the OLPC: Step and Funny Talk. The whole process was surprisingly quick and easy. I attribute this to Victor Lazzarini’s Csound Sugar GUI toolkit. I do a lot of Csound programming, but I’ve never actually done any GUI work for it. Using the toolkit was as simple as defining widgets and mapping them in Csound.


OLPC Step Activity

Flickr photo be me

Step is the first activitiy I’m developing for the XO. It’s a straight forward eight note step sequencer with synth notes, snare and kick parts. So far, I’ve probably put in about 8 hours on this. Once a user has a pattern they like, they can render the loop to an audio file, which can then be loaded in other activities. It still needs a lot of work, especially the synth engine. Though you can still take a listen if you would like: StepDemo1.mp3.

Funny Talk

OLPC Funny Talk Activity

Flickr photo be me

This is my favorite of the two, as my inspiration for this activity comes from my childhood memories of the Yamaha VSS-30 keyboard. My friends and I used to spend hours playing with that keyboard. Often in a very juvenile manner. I figured if we had such a great time playing with our voices, then perhaps the target audience of the OLPC will as well. Here is “the sound of my voice” being processed with Funny Talk: FunnyTalkDemo1.mp3.