Android OpenSL ES, how to choose speaker

1

Does anyone know how to play the sound through the speaker that we normally use during the phone conversation (not the loud speaker, but the ear speaker)? I have developed the app similar to Skype and my only problem is that when the sound is played through the loud speakers, mic picks it up and there is a lot of nose generated... In my code this is the line that I figured controls which speaker is used...

SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 1, SL_SAMPLINGRATE_8,
                                   SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
                                   SL_SPEAKER_FRONT_CENTER, SL_BYTEORDER_LITTLEENDIAN};

There are other options instead of SL_SPEAKER_FRONT_CENTER namely:

#define SL_SPEAKER_FRONT_LEFT           ((SLuint32) 0x00000001)
#define SL_SPEAKER_FRONT_RIGHT          ((SLuint32) 0x00000002)
#define SL_SPEAKER_LOW_FREQUENCY        ((SLuint32) 0x00000008)
#define SL_SPEAKER_BACK_LEFT            ((SLuint32) 0x00000010)
#define SL_SPEAKER_BACK_RIGHT           ((SLuint32) 0x00000020)
#define SL_SPEAKER_FRONT_LEFT_OF_CENTER ((SLuint32) 0x00000040)
#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER    ((SLuint32) 0x00000080)
#define SL_SPEAKER_BACK_CENTER          ((SLuint32) 0x00000100)
#define SL_SPEAKER_SIDE_LEFT            ((SLuint32) 0x00000200)
#define SL_SPEAKER_SIDE_RIGHT           ((SLuint32) 0x00000400)
#define SL_SPEAKER_TOP_CENTER           ((SLuint32) 0x00000800)
#define SL_SPEAKER_TOP_FRONT_LEFT       ((SLuint32) 0x00001000)
#define SL_SPEAKER_TOP_FRONT_CENTER     ((SLuint32) 0x00002000)
#define SL_SPEAKER_TOP_FRONT_RIGHT      ((SLuint32) 0x00004000)
#define SL_SPEAKER_TOP_BACK_LEFT            ((SLuint32) 0x00008000)
#define SL_SPEAKER_TOP_BACK_CENTER      ((SLuint32) 0x00010000)
#define SL_SPEAKER_TOP_BACK_RIGHT       ((SLuint32) 0x00020000)

I have tried all of them and none work. Thanks Alex.

android
opensl
asked on Stack Overflow May 30, 2017 by Alex Joly

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0