11

I know that some devices headphone ports (maybe all of them? any reference here would be good) have 3 channels, for stereo sound and microphone. So I was wondering if it's possible to detect something like this pedal on these devices.

If it's possible, using the audio recorder would be enough? I'm studying possibilities for an app here, and this sounds promising if possible.

Thanks

EDIT

I was searching more about it and I was wondering if the pedal would have the same effect as those headsets with buttons. It's deadly easy to override their effects, I created a simple app that does it and now I'm waiting for my pedal to try. Any thoughts about it ?

UPDATE

I just tried it in the pedal and it doesn't work. Although we managed to use the pedal to pause a music app. The device was running Cyanogen though. The voice recorder also didn't detect anything on the key press. Need suggestions on how to detect it :).

UPDATE

AS the bounty is about to expire, a minor update. The last link provided by @Nick.T got some helpful info but I'm still not able to create a sample to detect the pedal. So I made a small change on the title question, and any guidance on that direction would be very much appreciated!

Community
  • 1
  • 1
caiocpricci2
  • 7,714
  • 10
  • 56
  • 88
  • Interesting question (I haven't a clue but would like to know myself). I could see a garage band style app that would allow manual input such as turn tables or other electronic inputs (instruments). – jon_shep Nov 27 '12 at 22:16
  • Considering that the [square reader](https://squareup.com/reader) is based on using the audio port, I imagine what you are asking for is also possible. – Ehtesh Choudhury Dec 05 '12 at 07:27
  • That pedal seems to have a potentiometer inside and nothing else. The connector is a 3-pin jack (use the zoom on the picture) so it probably has one end of the pot attached to the ground pin of the jack, and thus the other end and the slider of the pot connected to the other two pins. Samsung jack pinout at http://pinoutsguide.com/CellularPhones-P-W/samsung_galaxy_headset_pinout.shtml . So the pot is connected to the left and right audio outputs, not the mic. Not promising. – emrys57 Dec 06 '12 at 19:39

4 Answers4

3

It's not clear if this will work without having the actual hardware in my hands, but... Don't plug the jack all the way into the socket. The tip of the jack should then connect to pin 2, left audio out, of this diagram: http://pinoutsguide.com/CellularPhones-P-W/samsung_galaxy_headset_pinout.shtml and the ring should connect to pin 3, microphone in. If you push the jack all the way in, the ground pin on the jack shorts out the microphone input and you won't detect anything - pictures at https://en.wikipedia.org/wiki/File:Photo-audiojacks.jpg show how the connections will mate.

Play some audio out the Left channel, record it on the mic channel, and measure the amplitude. That may - if it's all wired up right - tell you the pedal position. If the far end of the potentiometer is connected to the ring of the jack, that's not going to work.

That all sounds rather Heath Robinson. You could buy an inline 3-pin female jack socket and a 4-pin male jack plug and wire the two together to get whatever pinout you need. No electronics; just connectors and bits of wire! Or use a cable like this one: http://www.ebay.co.uk/itm/1mt-3-5mm-4-Pin-Jack-Male-Plug-4-Pole-Jack-female-Socket-Extension-Lead-Cable-/251172651017?pt=UK_Computing_Sound_Vision_Audio_Cables_Adapters&hash=item3a7b0e8009&_uhb=1 and a sharp knife and some stickytape.

The other problem would come if the phone refuses to send audio to the jack when the jack isn't plugged fully home - there's an extra contact in the socket that detects that mechanically. But it would work if you made 3-pin to 4-pin adapter.

Or, just cut the 3.5mm jack off your (shiny new) expression pedal. Replace it with the 4-pin connector off one of those broken phone headsets you have lying around.

emrys57
  • 6,679
  • 3
  • 39
  • 49
2

According to your last update, it looks like the pedal reacts like the button on a hands free headset. So as to say, to play, pause and skip music or pickup/hangup a call. If the basics on the API don't give you a way to get hold of it (which I doubt) then you could move down to the NDK and see if it can be catched by the native level.

I looked it up and thought this might help you find your way :

Never know...

Nick.T
  • 587
  • 4
  • 20
  • It's the opposite, it doesn't react to my overridden key detection. I've completely forgotten the NDK. I'll take a look on it tonight! Thanks for the suggestion! – caiocpricci2 Dec 04 '12 at 16:30
1

There are two potential paths of possibility here.

  • One would be to use the headset (or perhaps more specifically microphone) presence detection circuitry, and read that status via the appropriate API. This would be fairly simple (just have to figure out what property of a real headset is being measured). However, there is a good chance that the response may be fairly slow, as the phone is likely to go through some audio configuration changes and will not want to do that until it is "sure" that the headset has been connected or disconnected. Also the simplest non-microphone headset detection may be via a mechanical mechanism in the jack which could be difficult to electrically actuate across models.

  • A more complicated idea would be to couple some sound into the microphone input, and detect that in software. However, it will have to be an oscillating signal, as the microphone bandwidth typically does not range down to DC. If you just apply a steady voltage, you would get a "click" transient when it changes, but not otherwise. Injecting an audio frequency signal would require a power source - with careful design you may be able to steal enough power from the microphone bias supply to run a small oscillator. But perhaps simpler would be to have software output an audio tone on the speaker, and have your pedal switch couple this back into the microphone through a small capacitor.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • To be more accurate, i need this to work only on a galaxy tab. I can detect the microphone usage with the audio recorder class. I also don't need anything very precise. A simple is tapped or isn't tapped works. The problem is I can't get my hands on one of those pedals yet. – caiocpricci2 Nov 27 '12 at 22:39
  • And i'd appreciate any suggestion on as you set it, how to find out which of the properties of the real headset is being measured. I have no idea how to find that out without a pedal to test. – caiocpricci2 Nov 27 '12 at 22:41
  • You might be better posting this on electronics.stackexchange.com. Also see this discussion http://electronics.stackexchange.com/questions/20731/is-there-any-way-to-feed-a-signal-line-in-into-a-mobile-phone. It would be easy to build a simple circuit with a push button switch that you could use as a proof of concept. – Simon Nov 27 '12 at 22:48
  • Well, my knowledge in electronics is 0. They will provide me with a pedal it just will take a couple days. I wanted to go further and have a snippet ready to test when I get the pedal, but it's really hard to go forward wit my dumb skills in electronics :). – caiocpricci2 Nov 27 '12 at 22:57
1

I finally managed to read the pedal input. @emrys57 is right, replacing the jack with the 4-pin connector, triggered the input the same way microphones with a hook button do. However occasionally it seems to trigger the volume up and the volume down keys as well. I suppose this is related to me replacing the 4-pin jack with a knife and tape.

It was fairly simple to override onKeyUp. Be aware that you also have to override onKeyDown to prevent the default behavior:

@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
    int action = event.getAction();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
            || keyCode == KeyEvent.KEYCODE_HEADSETHOOK) {

        if (action == KeyEvent.ACTION_UP) {
            Log.d(TAG, "action_up");
            clickStart(null);
            return true;
        } else if (action == KeyEvent.ACTION_DOWN) {
            Log.d(TAG, "action_down");
            return true;
        } else {
            Log.d(TAG, "action:" + action);
            return true;
        }
    }
    return false;
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    int action = event.getAction();
    Log.d(TAG, "onKeyDown!");
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
            || keyCode == KeyEvent.KEYCODE_HEADSETHOOK) {

        if (action == KeyEvent.ACTION_UP) {
            Log.d(TAG, "action_up");
            clickStart(null);
            return true;
        } else if (action == KeyEvent.ACTION_DOWN) {
            Log.d(TAG, "action_down");
            return false;
        } else {
            Log.d(TAG, "action:" + action);
            return true;
        }
    }
    if (keyCode == KeyEvent.KEYCODE_BACK) {         
        finish();
        return true;
    }
    Log.d(TAG, "returning false");
    return false;
}
caiocpricci2
  • 7,714
  • 10
  • 56
  • 88