3

I am still new to android and currently I am working on a project, where I have to guide a person using audio signals. What I actually want to do is beep at a frequency only in one ear to tell the person to either turn left or turn right. When directing straight both ears will be beeping.

I found a number of examples here on how to generate the beep sound on android.

Here is an example of how to generate an arbitrary beep sound: Playing an arbitrary tone with Android

All I want is to play it only in one ear and shift between playback in either ears. Anybody has an idea of how this can be done?

Community
  • 1
  • 1
masad
  • 1,547
  • 1
  • 18
  • 40
  • 2
    so you would have to use CHANNEL_OUT_STEREO for the format and encode three arrays one for the left ear, one for the right, and both ears – L7ColWinters Jun 04 '12 at 19:11
  • 1
    http://stackoverflow.com/questions/6458780/sending-a-buzz-sound-to-ear-bud-left-or-right duplicate – L7ColWinters Jun 04 '12 at 19:13
  • What exactly do you mean by encoding for different ears? I have tried switching the level of volume between ears, but it does not work. Can you please explain how to encode for different ears? – masad Jun 16 '12 at 01:30
  • send me your current code via email and ill test and see what I can do . – L7ColWinters Jun 16 '12 at 06:02

2 Answers2

1

Looking at the docs you can control the output with AudioFormat. Not sure if this gives you the precision you need though.

final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT, numSamples,
                AudioTrack.MODE_STATIC);

Change to this for left channel output:

final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                sampleRate, AudioFormat.CHANNEL_OUT_FRONT_LEFT,
                AudioFormat.ENCODING_PCM_16BIT, numSamples,
                AudioTrack.MODE_STATIC);

Docs: http://developer.android.com/reference/android/media/AudioFormat.html

ian.shaun.thomas
  • 3,468
  • 25
  • 40
  • using CHANNEL_OUT_FRONT_LEFT and CHANNEL_OUT_FRONT_RIGHT I am not able to play tone in one ear. There is no apparent effect of this. All the tones sound same, and they are coming from both earphones. I only want one earphone to work in the situation where I have to guide a person in either direction. – masad Jun 16 '12 at 01:33
1

You could make three different stereo soundclips where you have sound in left, right and both channels and then play them with SoundPool

Rune Andersen
  • 1,650
  • 12
  • 15
  • So far I have not had success with generating tones. I guess I will have to use your method. Can you please tell me if you know how to generate these soundclips on pc? – masad Jun 16 '12 at 01:35
  • I used audacity as well in the end. Its a pretty handy tool to create sound, using android I have not had any success in generating the beeps on the fly. – masad Jul 21 '13 at 15:49