2

I am trying to play a mono sound through a single channel, the only thing I can think of is interweaving a second channel into the byte array, changing AudioFormat to stereo then calling audioTrack.setStereoVolume(leftVolume, rightVolume); to set one channel's volume to zero. Is there a simpler way?

Playback:

        AudioTrack audioTrack = null;                                   // Get audio track
        try {
            audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                    sampleRate, AudioFormat.CHANNEL_OUT_MONO,
                    AudioFormat.ENCODING_PCM_16BIT, (int)numSamples*2,
                    AudioTrack.MODE_STATIC);
            audioTrack.write(generatedSnd, 0, generatedSnd.length);     // Load the track
            audioTrack.play();                                          // Play the track
        }
        catch (Exception e){ }
meeeee
  • 2,929
  • 3
  • 22
  • 25
  • its unlikely that there is another way to do it. – JoxTraex Oct 11 '13 at 05:11
  • Maybe I'm missing something, but I don't get the question? Why would you use a stereo `AudioTrack` for mono playback? Are you getting some kind of error when using a mono `AudioTrack`..? – Michael Oct 11 '13 at 08:05
  • @Michael I followed http://stackoverflow.com/questions/2413426/playing-an-arbitrary-tone-with-android to generate a tone but it plays from both channels. I want it to play from one channel only – meeeee Oct 11 '13 at 08:37
  • I'm trying to do the same thing, single channel for mono audio but I've found it is now done by public int setVolume (float gain) Added in API level 21 Sets the specified output gain value on all channels of this track. This API is preferred over setStereoVolume(float, float), as it more gracefully scales down to mono, and up to multi-channel content beyond stereo. So how would I controll it now? – VMMF Apr 28 '16 at 03:16

0 Answers0