Showing posts with label polyphonic. Show all posts
Showing posts with label polyphonic. Show all posts

Sunday, May 6, 2012

Sampling


So far I've been learning synthesizers, directly "inventing" sound from known, easily-made mathematical waveforms.  Today I've got some recipes for sampling with the microphone (or other audio equipment).

First, basic sampling.  With an array called loop01 stuffed into its own patch (better for various performance reasons), I set up a bang to trigger the tabwrite~ function and put half a second of data into the array.

This streams straight in from the ADC and into the array, which I've made 22000 samples long to store half a second of 44000Hz data.  (Working on a more sophisticated version of this patch that'd have adjustable length, but one thing at a time.)

Next, playback.  I had a lot of fun hooking up a phasor~ object to the tabread4~ block and sliding it around, but for simple sampling, just feed it a vline~ that goes to near the end of the array based on an input argument.

My input argument here has been hacked up a little so that middle C on my nanoKey leaves the pitch unaltered.  This creates the (wrong, but useful) impression that the sample is taken at "normal" and the MIDI keyboard slows it down and speeds it up depending on how high or low you go.  I wired the "mod" button on my keyboard to take samples, but the bang is accessible in case you don't have that particular feature.  I also put a slider in so that if you're using this without a keyboard, everything will still work.

Before I go to the more sophisticated sampler with polyphonic MIDI control, I want to thank GuitarExtended for this excellent patch for detecting sounds at the input.  I appropriated this into a patch called threshbang which I used to give the next version of the sampler the ability to detect things like claps or vocalizations and trigger the sampler.  (Its details are currently beyond the scope of the blog, but I've included it so the whole polyphonic sampler patch works.)

Packing the note interpreter, pitch shifting part, line generator and tabread4~ object all into a subpatch and then duplicating it up for polyphony works about the same as for any other sound effect, but now the keyboard can play chords of whatever sound you've put into the half-second memory space of this simple patch.

Sampling and pitch-shifting sounds from around the desk quickly yields a lot of rich sound, and I can't wait to store all the funky audio I'm getting from this!

Today's Files:
Simple Sampler
Polyphonic Sampler
"Bang on Threshold" generator

Sunday, April 29, 2012

MIDI Basics

So basic MIDI capability. This is a picture of roughly the simplest polyphonic MIDI patch that will work and play multiple notes, plus a little side demo that shows off how this also can be used with "ordinary" generated notes.

The nice thing about this is that this gives you general polyphony for your projects-- not just if you happen to plug in a MIDI keyboard. (By the way, I'll be using the Korg nanoKey, which for the money is about the best damn keyboard I can imagine getting. It's utterly miniscule but has two octaves worth of velocity sensitive(!) keys and a pair of shifter buttons to allow 10 octaves total from one little keyboard, and that's before you do anything with PD.

So, quick breakdown of functionality.  First we have a notein object, which is how you get MIDI messages into PD.  The 1 in the argument list is a channel select I think-- so far I've just left that filled in.  From there, into the poly object, which does the tricky work of polyphonic splitting.  In Pure Data this is handled in a pretty straightforward manner: the poly object just passes the message along, adding an integer indicating which of the N voices it's directed to, where N is the first argument.  (Here I used 3 to save visual space, but I usually use six so I can play two simultaneous chords.)

Everything up to this point has been ordinary, single-element messages, but as of the pack block, we now have a single wire sending ordered triplets, whose pattern is: [voice, note, velocity].  The route block uses the first element in the message (the "voice" element) to select to which of the three voices the note message will be sent.

In this way, if I hit three notes simultaneously on my keyboard, they'll show up at the notein block in (very) rapid succession, where the poly block assigns them a voice, and then the route block sends each of the three messages to its own unique player below.

The players are identical.  Each consists of an unpack statement to split apart the message back into note and velocity, a square wave generator fed by the note message, and an ead~ envelope generator set to trigger only on non-zero velocities.  (This is because zero velocity is MIDI for "shut off the note" and is triggered by releasing the key.)

The results are summed at the output and you get polyphonic square waves.  This configuration isn't hard to feed with your own data either-- just make sure you provide a nonzero velocity message simultaneously with your note, or as shown earlier, nothing will play.

Download the patch

Saturday, April 14, 2012

MIDI: Polyphony Is Hard, Deal With It

This part's just fundamental, if you do polyphonic MIDI in PD, it's gonna look like this:



And that's if you don't have arguments on that oscillator. That's why I'm learning how to use route, select, etc for message handling, and so far, it ain't pretty...