Monday, 15 April 2013

Pure Data and BACON (Part 1)

Well, it's been a busy weekend, week, month and year. I've not been able to blog in ages. I've been rushed off my feet for the last couple of months with work and preparing to speak at the most awesome conference (per head of population) in the world, BACON. It happened, I survived two early (and I mean EARLY) starts and late nights and, heck, my talk went down incredibly well. Text to music is going to get a burst of activity, when I get a moment to myself to sort through the pull requests. What's more, a handful of people actually told me I had their favourite talk! Overall not a bad first experience of public speaking. Even got a mention in this Tech City review of the event.

But enough about me, down to some actual content. The inimitable @jongold asked for a demo of my generative patch from the talk, but I flatly refuse to hand code out to a potential Pd coder, so here's something a tiny bit better, how to make it yourself. (Also, a it leads on quite well from my last post, back in the day).

Step 1: Install Pure Data, yadda, yadda, yadda

Step 2: Open Pd, Start a patch, Place some objects, join them up. Click the button:

Create objects with Put > Object or ctrl + 1 then just type in their name. Success results in a solid border.

That button is a 'bang' which sends an activation message, create it with Put > Bang or ctrl + shift + b

You may have to switch in and out of edit mode with a ctrl + e

The result is a little clicking sound. Not very impressive, I know, your mouse probably clicks whenever you click your mouse, but it's an important staging post on the way to step 3.

If you're not hearing it, make sure your volume is up, and the DSP checkbox is checked on your Pd terminal, you may also have to select your sound card under the Media menu (Audio Options on Windows or Mac, on Linux select an audio driver and experiment until that button makes a click)

Step 3: Assume you want to hear that click, save your fingers and automate it.

That empty box is a toggle, if you click it when you're not in edit mode it sends an 'on' message, or, of course, an 'off' message.

metro outputs a bang (the same message as the button) at a given interval, once you've turned it on. In this case it's 1000 milliseconds. So, if you click the toggle, you guessed it, you'll hear a click every second. It's like a clock.

But that's a bit dull...

Step 4: Take control of your metronome.

Okay, nothing much has changed here. I've added a number box and connected it to the right-hand inlet of the metro. This will override the number in the metro and change it's speed dynamically. Drag your number up and down (when you're not in edit mode, so it changes the number) and you'll hear the regularity of your metronome change.

Psycho-acoustics alert! The human ear can only interpret around 30 separate sounds a second. So if we divide 1000 by 30 we'll get a figure at which we'll stop hearing separate clicks, and start to hear something continuous. As a rule of thumb, I just use 30 milliseconds or lower. Feel free to demonstrate this to yourself.

Well, there's some interesting sounds, when that click gets really fast, so let's save ourselves the effort of  choosing:

Step 5: Randomize AND automate it

So, random accepts our old friend, the bang, and outputs, you guessed it, a random number. This one will be somewhere between 0 and 99 (don't be confused, this is 100 options, just that none of them are the number 100).

You'll also notice that I've skipped a step, and added a metro above the random, so once both toggles are checked, you'll see the number change every quarter of a second, and hear a difference in the sound, too. So this is a flat rhythm of changes to a harsh, imprecise kind of sound. Let's refine it...

Step 6:  Not just a beat, rhythm...

Okay, it may be time to take a step back. That box labelled 'length' is an array. If you're not much of a techy, you'll need to know that it's basically a list of numbers, and this one has 4 numbers in it. Creating it is a tiny bit less simple, so here's a step-by-step:

  1. Put > Array
  2. Name it length, and set it's size to 4
  3. Right click, choose properties and set it's Y range from 1000 to -1 
  4. Put > Message
  5. fill the message in as you see above ("; length 0 1000 500 250 125"), that semicolon sends it to an object by name, so you don't need to connect it to anything.
  6. Read it with tabread (which reads a table, predictably enough) 
  7. hook up random and metro above it, which you're already familiar with.
Now, when all the metronomes are started, it'll decide every second whether to change the regularity of the sound once, twice, four or eight times every second. This is actually a fairly common way of dividing time in music, we've taken a common beat (1 second) and divided it by 2 repeatedly. 

I realise that the rhythm here is a bit obscured by the nasty click-tones, so lets simplify...

Step 7: Delete most of it, listen to the result

All we've done here is cut out the middle bit of the chain and driven a click directly from that second metronome. Instead of deciding each second how many times to change the regularity of the click, it's just going to decide how many times to click. The result is something like a rhythm exercise, which most musicians will have done some form of, in which you change between note lengths whilst keeping a steady rhythm. 

Phew! That's it! 

This has become something of a whopper of a blog post, I guess it's time for a cliff-hanger. As ever, if you have some difficulty, feel free to bother me about it by contacting @MarmiteJunction 

In the next exciting episode! We'll start to move from clicks to tones, some recognisable pitches, and a generative duet. 

No comments:

Post a Comment