×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Question Receive data via the headphone jack (not send)?

    I have seen several Android and iOS software projects that use the headphone jack to receive signal, instead of only outputting signal as is the usual purpose of the jack. For example:

    http://stackoverflow.com/questions/7...k-read-in-data

    I need to know how to do the same on a Lumia phone. Does anyone know of any code samples or documentation on how to capture an audio signal coming in to the headphone jack?

    Note, I am not talking about the typical use of playing signal (music, sounds, etc.) out the headphone jack. I want to receive signals from the device connected to the headphone jack, which is the opposite direction of the usual signal flow for the jack. I have seen Android and iOS remote control apps that use the headphone jack in a bi-directional manner, and I want to do the same on a Windows 8 Phone. I need to be able to capture an audio signal coming in to the phone. I will then decode the pulses in the audio signal to extract the data I am looking for from that signal.

    The fact that Square now has an app on Windows phone indicates that what I want to do is possible since their card reader attaches to the phone's headphone jack:

    http://wmpoweruser.com/windows-phone...t-card-reader/

    I just need to know the technique involved.

    -- roschler

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: Receive data via the headphone jack (not send)?

    Most likely they are simply using the microphone signal in some way. Easiest way to try out would be to connect the headset and check wether the microphone recordings are then coming from the headsets microphone or the one inside the device (I'm assuming the former). In the end you would start recording from the microphone and analyze the signal that's coming in for the data you want to transmit:

    e.g.: binary coding using a carrier frequency of 8 kHz so you read the silence/signal periods (detection using a FFT) to gather the bits and then convert those to the information you need. But there would be lots of different ways to encode this and I don't know how Square are doing it.

    Ordinarilly I would say that using Bluetooth and NFC would be the better way compared to misappropriating the headphone jack though. What exactlly is your use case?

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,765

    Re: Receive data via the headphone jack (not send)?

    Indeed, there is no magic, if you check specs for a phone (say https://developer.nokia.com/Devices/...ons/Lumia_520/), and open Connectivity, you will see that "headphone jack" is actually called "3.5mm Audio Connector". And if you search for it with Google, you will see that it is not just a name, it is a 4-pin socket, having a microphone signal. See http://www.phonearena.com/reviews/No...s?image=130799 for example.

  4. #4
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Receive data via the headphone jack (not send)?

    Thanks wizard_hu_ and SB Dev,

    Excellent. So the headphone jack is an audio jack as you say and is bi-directional. Therefore:

    1) Is it full duplex? That is, can I record audio from the jack while also simultaneously sending audio to the jack? Or can I only do one or the other at any time?
    2) Is there a known source code sample that shows me how to do this in a processor efficient way?

    @SB Dev - I'm stuck with the headphone jack because the external device I'm communicating with over the headphone jack only sends/receives communications over the headphone (audio) jack using its built-in headphone cable.

    -- roschler

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: Receive data via the headphone jack (not send)?

    I fear you will have to try that out but I would assume that it's Full Duplex given that you have one connection for each device (left speaker, right speaker, mic) + ground connector. Without knowing what the device actually does send using that connection it's hard to tell what will be necessary to decode the signal.

    Is there any documentation on the protocol the device uses?

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,765

    Re: Receive data via the headphone jack (not send)?

    The hardware part is certainly full duplex, for the API side, it has to be checked, I am not familiar with WP audio API-s.

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: Receive data via the headphone jack (not send)?

    This article: http://developer.nokia.com/Community..._Windows_Phone might be a good starting point for looking into the basics of audio on WP.

  8. #8
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: Receive data via the headphone jack (not send)?

    Quote Originally Posted by SB Dev View Post
    This article: http://developer.nokia.com/Community..._Windows_Phone might be a good starting point for looking into the basics of audio on WP.
    And knowing nothing about the topic at all, knowing whether the headphones are connected might be useful: How_to_detect_if_an_headset_is_plugged

  9. #9
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Receive data via the headphone jack (not send)?

    Thank you everyone for your answers. I will use them as a starting point for my efforts.

    @SB Dev,

    I am still waiting for the documentation on the protocol. However, by looking at their SDK for Android which includes the WAV files that execute each device command, I have already deduced the format. They are using pulses of sound for the command data encoding/decoding. It is not the frequency that matters but the timing between the pulses. A short pause (~ 400 samples between pulses) for 0 or a long pause (~800 samples between pulses) for 1. I'm pretty sure a simple FFT or Goertzel operation will allow me to pull out the commands, even if they are embedded with other audio in the signal. Note, I'm using samples here because I am being lazy and not converting the samples back to time using the sample rate.

    -- roschler

  10. #10
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    526

    Re: Receive data via the headphone jack (not send)?

    The amount of samples might be different on WP given that as far as I remember the Microphone will always have a sample rate of 32 kHz. So you might have to adapt that in your detection logic. As for FFT on WP this sample shows how to do it: http://developer.nokia.com/Community..._Windows_Phone

    It does a lot more than what you need but all the necessary information should be there as well.

  11. #11
    Regular Contributor
    Join Date
    Mar 2013
    Posts
    65

    Re: Receive data via the headphone jack (not send)?

    @SB Dev

    Thanks!

    -- roschler

Similar Threads

  1. send/receive data
    By suneethapuchakayala in forum Mobile Java General
    Replies: 2
    Last Post: 2010-05-17, 14:08
  2. Help. My n85 keeps on freezing/restarting when plugging in headphone jack.
    By illapino83 in forum General Development Questions
    Replies: 1
    Last Post: 2009-11-11, 06:59
  3. send and receive data
    By widetech1 in forum Symbian
    Replies: 1
    Last Post: 2009-01-27, 00:26
  4. how to send WAP data and receive its' response
    By Shen Tianping in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-03-17, 05:40
  5. Http send and receive data
    By white_dragon in forum Symbian
    Replies: 1
    Last Post: 2005-02-02, 11:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×