5

I was hoping some super electronics expert dude could give me some advice. How do I get this http://www.amazon.co.uk/Cherub-WTB-004-Keyboard-Sustain-Pedal/dp/B000UDVV6E to work with my computer? I basically want to use it to replace/emulate a keystroke or something in my games. Anyone with some experience with something like this got any advice? I'm willing to try simple software related hacks... or more advanced software stuff if there are resources online for it.

Edit:

Pedal Waveform

I tried plugging it into my microphone jack and lo and behold, whenever I activate (step on) the pedal, I get a signal - this is the recording (on audacity).

The first "thick" one is from holding down on the pedal, the rest were just taps.

Dois
  • 191
  • 1
  • 2
  • 10

4 Answers4

3

Why go through all the trouble, when you can just buy exactly what you are looking for? A USB Foot Pedal made for PCs, like this:

enter image description here

They are cheap and does exactly what you are looking to do.

Keltari
  • 75,447
3

Well it's been 7 months or so and I totally forgot about this... came back and tried it again today and I managed to get it working.

Here's a simple Java program that works for my pedal. It converts the presses into keyboard "V"s (it's for me to activate +voice_record in cS GO)

    package pedal2keyboard;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import javax.sound.sampled.*;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

/***
 * Author: Dois Koh
 * Date: 27th October 2015
 * 
 * Gets your microphone signal and you can go do whatever you want with it.
 * Right now, it takes signals from my Cherub WTB-004 Keyboard Sustain Pedal, plugged into
 * my microphone jack, and converts it into key presses (holds down V when depressed,
 * releases V when released)
 */
public class PedalToKeyboard {

    // Robot for performing keyboard actions (pressing V)
    public static Robot robot = null;

    // Currently 8KHz, 16 bit signal (2 bytes), single channel, signed (+ and -) and BIG ENDIAN format
    public static AudioFormat format = new AudioFormat(8000.0f, 16, 1, true, true);

    public static TargetDataLine microphone = null;
    public static boolean pedalPressed = false;

    public static void main(String[] args) {

        try {
            // Initialize robot for later use
            robot = new Robot();

            // Retrieve the line to from which to read in the audio signal
            microphone = AudioSystem.getTargetDataLine(format);

            // Open the line in the specified format -
            // Currently 8KHz, 16 bit signal (2 bytes), single channel, signed (+ and -) and BIG ENDIAN format      
            microphone.open(new AudioFormat(8000.0f, 16, 1, true, true));

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] data = new byte[microphone.getBufferSize()/8];

            // Begin audio capture.
            microphone.start();

            int numBytesRead = 0;
            short previousShort = 0;

            // Continue until program is manually terminated
            while (true) {

                // Read the next chunk of data from the TargetDataLine.
                numBytesRead = microphone.read(data, 0, data.length);

                // Reset the buffer (get rid of previous data)
                out.reset();

                // Save this chunk of data.
                out.write(data, 0, numBytesRead);

                byte[] bytes = out.toByteArray();
                short[] shorts = new short[bytes.length/2];

                // to turn bytes to shorts as either big endian or little endian. 
                ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(shorts);

                // Iterate through retrieved 16 bit data (shorts)
                for (short s : shorts) {

                    // Check if descending or ascending (pedal press is descending, release is ascending)
                    if (s < 0) { // descending                  
                        // make sure drop is large instantaneous drop
                        if (Math.abs(previousShort - s) > 200 && s < -32700) {
                            if (!pedalPressed) {
                                PedalPressedAction();
                                previousShort = s;
                                break;
                            }
                        }
                    } else if (s > 0) { // ascending
                        // make sure increase is large instantaneous increase
                        if (Math.abs(previousShort - s) > 200 && s > 32700) {
                            if (pedalPressed) {
                                PedalReleasedAction();
                                previousShort = s;
                                break;
                            }
                        }
                    }

                    previousShort = s;
                }
            }    

        } catch (LineUnavailableException | AWTException e) {
            e.printStackTrace();
        } finally {
            if (microphone != null)
                microphone.close();
        }
    }

    /***
     * The action to perform when the pedal is depressed
     */
    public static void PedalPressedAction() {
        pedalPressed = true;
        robot.keyPress(KeyEvent.VK_V);
    }

    /***
     * The action to perform when the pedal is released
     */
    public static void PedalReleasedAction(){
        pedalPressed = false;
        robot.keyRelease(KeyEvent.VK_V);        
    }
}

Dominik
  • 198
Dois
  • 191
  • 1
  • 2
  • 10
1

To actually do this. All you really need is keyboard. Something small like this. Gut the pedal and the keyboard. You might even be able to fit the keyboard inside the pedal with the USB cable to replace the audio wire. The pedal probably has 3 leads, + & - and the resistor lead. Just find the + and - leads through trial and error (only 6 possible choices). Wire one of the keys to the leads in the pedal. When you press the pedal and close the circuit... keypress!

Keltari
  • 75,447
-2

As you discovered, this pedal is just a momentary switch.

You need a midi "head" device to read the switch state and convert to midi; a way to plug that head unit into your computer; and then software to make use of the midi input.

Alternatively, you can look into devices which convert to joystick inputs. People who make cockpit simulators use real switches to interface with their sim software. If you go this route, you would use a simple joystick-to-midi driver and then again, software suitable for use with the inputs.

Note that you can get a 10$ gamepad and hack leads onto the circuit board and connect 1$ Radio Shack switches mounted on a board for a whole bank of foot pedals. You would use the joy-midi driver to route the signals to a DAW or Amp Simulator.

Usually, for music interface and recording integration, you want a DAW application (Digital Audio Workstation).

There are also wah-wah pedal style audio intrerfaces which have ports for expression pedals. These are usually for guitar, but there is no reason you can't use them as general audio interfaces, and the midi signals can be routed to ANY function, so the rocker pedal can be used for e.g. crossfade, volume, wah, toggle switch etc etc

Even with an appropriate device to get the button push to register on your PC, you cannot use Audacity for this. You can try the free "vsthost" and some VST effect proccessors (try "simuanalog" also free). The VSTHost is a host to load amp sims and can route midi and joystick input signals to any exposed function/button/dial on a VST application. It has a built-in recorder, and you can then edit the files with audacity.

Anything that generates voltage can be plugged into the microphone jack and generate a recordable signal so long as it doesn't set the computer on fire and even then...

So: to recap. You need to hack your two wires (1/4-1/8 inch cable stripped and soldered to a joypad) or otherwise get the signal onto the computer in joystick or midi form. Then you can translate that signal to anything that handles it. Joy2midi, Midi translator, midi2joy.

Yorik
  • 4,988