masad
masad

Reputation: 1567

how to make android beep in only one ear?

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?

Upvotes: 3

Views: 819

Answers (2)

Rune Andersen
Rune Andersen

Reputation: 1705

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

Upvotes: 1

ian.shaun.thomas
ian.shaun.thomas

Reputation: 3488

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

Upvotes: 1

Related Questions