The official web-log of Matt Meshulam is what you are currently viewing.

20Jan/09Off

Passive Footswitch to MIDI Using Your Soundcard

So a few months ago I scavenged some footswitches from the secret electrical engineering department free stuff room. I didn't really have a plan for them, so I terminated them with 1/4" plugs forgot about them.

Footswitch

Then the other day I read about some software that MOTU is coming out with called Volta. It converts digital (MIDI, etc) control signals to analog control voltage for interfacing computers with analog synth gear. The cool, elegant part about it is that it does this by using your existing hardware. If you have a multichannel audio interface, which MOTU just happens to sell, the audio outputs become general voltage outputs using Volta.

This got me thinking that it would be pretty easy to do the opposite: I could use the inputs on my (coincidentally MOTU-brand) audio interface to hook up a footswitch to my (Windows) computer. Since the switch is just a passive momentary switch (short circuit when pressed down, open otherwise) I would need a voltage source in series with the switch to provide a signal that could be detected by the sound card. Most audio interfaces have a DC-blocking highpass filter on the input to protect it from stupidity-based damage. Because of this filtering, the digital signal doesn't look how one might expect. A back-of-the-envelope sketch illustrates:

The effect of the DC blocking filter

The effect of the DC blocking filter

The first step was to install a battery inside the footswitch. Since there would be virtually no current drawn from the battery, I elected to install the battery in a moderately permanent fashion, soldering wires directly to the terminals and hot gluing the battery in place. Note to potential future employers: this is not representative of my overall regard for safety, it's just a weekend project and I didn't have any battery clips around.

Don't try this at home, kids

Don't try this at home, kids

Inside the case with battery installed

Inside the case with battery installed

I reattached the top half of the case and plugged it into one of the line inputs on my sound card. I tested it out and it worked exactly as expected. Note that I installed the battery backwards so the 'on' pulse is negative instead of positive:

fullscreen-capture-1172009-41841-pm

Switch depressed for ~2 seconds, then for a fraction of a second

With the hardware side finished, I had to decide the best way to control music software with the footswitch. I settled upon converting it to a MIDI note event. I installed Maple Virtual Midi Cable, a tiny piece of software for Windows which provides virtual MIDI ports for sending data between programs. Then, I built up a patch in PD to convert the positive and negative pulses to MIDI. This was my first foray into PD, so I'm sure there's some trivial way to implement this that I didn't know about.

PD code to convert analog data to MIDI

Convert soundcard input to MIDI. Links to pd file.

And that's it. As I implemented it, it takes the input from the third channel of the sound card and outputs a MIDI note on when the switch is depressed and a note off when it's released. Note that a velocity of zero is the same as a note off message. This patch could be easily parallelized by duplicating it and changing the ADC channel and MIDI note numbers.

The only downside to this simple method is that you can't generalize it to continuous controllers like a knob or expression pedal. You would need to send an AC signal through the controller since the highpass filter doesn't allow you to see small or slow variations in level, just impulses or quick steps. So I'll leave that modification for another day.

Filed under: Tech Comments Off
Comments (3) Trackbacks (1)
  1. Cheapest kick drum trigger ever. You could probably do a whole drum kit like this.

  2. You are a genius! I was surfing in the net looking for a kick midi or pc keyboard to midi in second plan but not find nothing… I was using a joystick accelerator, but together a steering wheel (imagine the scene…), Your project is amazing! Tomorrow i will make this. Do Not problem with voltage damage the PC?
    Thank you very much.
    Rodrigo (from Brasil)

  3. very nice web site, i enjoyed reading


Trackbacks are disabled.