src/audio/openslES/SDL_openslES.c
changeset 12538 fad97a498ffb
parent 12534 682d9b5ecbed
child 12539 e7282e21da92
     1.1 --- a/src/audio/openslES/SDL_openslES.c	Sat Jan 12 12:18:44 2019 -0800
     1.2 +++ b/src/audio/openslES/SDL_openslES.c	Mon Jan 14 10:04:54 2019 +0100
     1.3 @@ -50,453 +50,452 @@
     1.4  //static SLEnvironmentalReverbItf outputMixEnvironmentalReverb = NULL;
     1.5  
     1.6  // aux effect on the output mix, used by the buffer queue player
     1.7 -static const SLEnvironmentalReverbSettings reverbSettings =
     1.8 -    SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
     1.9 +// static const SLEnvironmentalReverbSettings reverbSettings = SL_I3DL2_ENVIRONMENT_PRESET_STONECORRIDOR;
    1.10  
    1.11  // buffer queue player interfaces
    1.12 -static SLObjectItf						bqPlayerObject = NULL;
    1.13 -static SLPlayItf 						bqPlayerPlay;
    1.14 -static SLAndroidSimpleBufferQueueItf	bqPlayerBufferQueue;
    1.15 -//static SLEffectSendItf					bqPlayerEffectSend;
    1.16 -static SLMuteSoloItf					bqPlayerMuteSolo;
    1.17 -static SLVolumeItf						bqPlayerVolume;
    1.18 +static SLObjectItf                   bqPlayerObject = NULL;
    1.19 +static SLPlayItf                     bqPlayerPlay;
    1.20 +static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
    1.21 +//static SLEffectSendItf          bqPlayerEffectSend;
    1.22 +static SLMuteSoloItf                 bqPlayerMuteSolo;
    1.23 +static SLVolumeItf                   bqPlayerVolume;
    1.24  
    1.25 +#if 0
    1.26  // recorder interfaces TODO
    1.27 -static SLObjectItf						recorderObject = NULL;
    1.28 -static SLRecordItf						recorderRecord;
    1.29 -static SLAndroidSimpleBufferQueueItf	recorderBufferQueue;
    1.30 +static SLObjectItf                   recorderObject = NULL;
    1.31 +static SLRecordItf                   recorderRecord;
    1.32 +static SLAndroidSimpleBufferQueueItf recorderBufferQueue;
    1.33 +#endif
    1.34  
    1.35  // pointer and size of the next player buffer to enqueue, and number of remaining buffers
    1.36 -static short 	*nextBuffer;
    1.37 -static unsigned	nextSize;
    1.38 -static int 		nextCount;
    1.39 -
    1.40 -static const char	*sldevaudiorecorderstr	= "SLES Audio Recorder";
    1.41 -static const char	*sldevaudioplayerstr 	= "SLES Audio Player";
    1.42 -
    1.43 -#define	SLES_DEV_AUDIO_RECORDER	sldevaudiorecorderstr
    1.44 -#define	SLES_DEV_AUDIO_PLAYER	sldevaudioplayerstr
    1.45 +#if 0
    1.46 +static short      *nextBuffer;
    1.47 +static unsigned    nextSize;
    1.48 +static int         nextCount;
    1.49 +#endif
    1.50  
    1.51  #define NUM_BUFFERS 2           /* -- Don't lower this! */
    1.52  
    1.53 -static	Uint8	*mixbuff = NULL;
    1.54 -static	int		next_buffer = 0;
    1.55 -static	Uint8	*pmixbuff[NUM_BUFFERS];
    1.56 +static Uint8   *mixbuff               = NULL;
    1.57 +static int      next_buffer           = 0;
    1.58 +static Uint8   *pmixbuff[NUM_BUFFERS];
    1.59  
    1.60 -static SDL_sem *playsem = NULL, *recsem = NULL;
    1.61 +static SDL_sem *playsem               = NULL;
    1.62 +#if 0
    1.63 +static SDL_sem *recsem                = NULL;
    1.64 +#endif
    1.65  
    1.66  //static SDL_AudioDevice* audioDevice = NULL;
    1.67  
    1.68  #if 0
    1.69 +static const char *sldevaudiorecorderstr = "SLES Audio Recorder";
    1.70 +static const char *sldevaudioplayerstr   = "SLES Audio Player";
    1.71 +
    1.72 +#define  SLES_DEV_AUDIO_RECORDER  sldevaudiorecorderstr
    1.73 +#define  SLES_DEV_AUDIO_PLAYER  sldevaudioplayerstr
    1.74  static void openslES_DetectDevices( int iscapture )
    1.75  {
    1.76 -	LOGI( "openSLES_DetectDevices()" );
    1.77 +  LOGI( "openSLES_DetectDevices()" );
    1.78      if ( iscapture )
    1.79              addfn( SLES_DEV_AUDIO_RECORDER );
    1.80 -	else
    1.81 +  else
    1.82              addfn( SLES_DEV_AUDIO_PLAYER );
    1.83 -	return;
    1.84 +  return;
    1.85  }
    1.86  #endif
    1.87  
    1.88 -static void openslES_DestroyEngine( void );
    1.89 +static void openslES_DestroyEngine(void);
    1.90  
    1.91 -static int	openslES_CreateEngine( void )
    1.92 +static int
    1.93 +openslES_CreateEngine(void)
    1.94  {
    1.95 -	SLresult result;
    1.96 +    SLresult result;
    1.97  
    1.98 -	LOGI( "openSLES_CreateEngine()" );
    1.99 +    LOGI("openSLES_CreateEngine()");
   1.100  
   1.101 -	// create engine
   1.102 -	result = slCreateEngine( &engineObject, 0, NULL, 0, NULL, NULL );
   1.103 -	if ( SL_RESULT_SUCCESS != result ) {
   1.104 +    // create engine
   1.105 +    result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
   1.106 +    if (SL_RESULT_SUCCESS != result) {
   1.107 +        LOGE("slCreateEngine failed");
   1.108 +        goto error;
   1.109 +    }
   1.110  
   1.111 -		LOGE( "slCreateEngine failed" );
   1.112 -		goto error;
   1.113 -	}
   1.114 -
   1.115 -	LOGI( "slCreateEngine OK" );
   1.116 +    LOGI("slCreateEngine OK");
   1.117  
   1.118      // realize the engine
   1.119 -    result = (*engineObject)->Realize( engineObject, SL_BOOLEAN_FALSE );
   1.120 -	if ( SL_RESULT_SUCCESS != result ) {
   1.121 +    result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
   1.122 +    if (SL_RESULT_SUCCESS != result) {
   1.123 +        LOGE("RealizeEngine failed");
   1.124 +        goto error;
   1.125 +    }
   1.126  
   1.127 -		LOGE( "RealizeEngine failed" );
   1.128 -		goto error;
   1.129 -	}
   1.130 -
   1.131 -	LOGI( "RealizeEngine OK" );
   1.132 +    LOGI("RealizeEngine OK");
   1.133  
   1.134      // get the engine interface, which is needed in order to create other objects
   1.135 -    result = (*engineObject)->GetInterface( engineObject, SL_IID_ENGINE, &engineEngine );
   1.136 -	if ( SL_RESULT_SUCCESS != result ) {
   1.137 +    result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
   1.138 +    if (SL_RESULT_SUCCESS != result) {
   1.139 +        LOGE("EngineGetInterface failed");
   1.140 +        goto error;
   1.141 +    }
   1.142  
   1.143 -		LOGE( "EngineGetInterface failed" );
   1.144 -		goto error;
   1.145 -	}
   1.146 -
   1.147 -	LOGI( "EngineGetInterface OK" );
   1.148 +    LOGI("EngineGetInterface OK");
   1.149  
   1.150      // create output mix, with environmental reverb specified as a non-required interface
   1.151 -//  const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
   1.152 -//  const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.153 -
   1.154 -  const SLInterfaceID ids[1] = { SL_IID_VOLUME };
   1.155 -  const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.156 -  result = (*engineEngine)->CreateOutputMix( engineEngine, &outputMixObject, 1, ids, req );
   1.157 +    // const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
   1.158 +    // const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.159  
   1.160 -	if ( SL_RESULT_SUCCESS != result ) {
   1.161 -
   1.162 -		LOGE( "CreateOutputMix failed" );
   1.163 -		goto error;
   1.164 -	}
   1.165 -	LOGI( "CreateOutputMix OK" );
   1.166 +    const SLInterfaceID ids[1] = { SL_IID_VOLUME };
   1.167 +    const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.168 +    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 1, ids, req);
   1.169  
   1.170 -  // realize the output mix
   1.171 -  result = (*outputMixObject)->Realize( outputMixObject, SL_BOOLEAN_FALSE );
   1.172 -	if ( SL_RESULT_SUCCESS != result ) {
   1.173 +    if (SL_RESULT_SUCCESS != result) {
   1.174 +        LOGE("CreateOutputMix failed");
   1.175 +        goto error;
   1.176 +    }
   1.177 +    LOGI("CreateOutputMix OK");
   1.178  
   1.179 -		LOGE( "RealizeOutputMix failed" );
   1.180 -		goto error;
   1.181 -	}
   1.182 +    // realize the output mix
   1.183 +    result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
   1.184 +    if (SL_RESULT_SUCCESS != result) {
   1.185 +        LOGE("RealizeOutputMix failed");
   1.186 +        goto error;
   1.187 +    }
   1.188 +    return 1;
   1.189  
   1.190 -	return 1;
   1.191 -
   1.192 -error:;
   1.193 -	openslES_DestroyEngine( );
   1.194 -	return 0;
   1.195 +error:
   1.196 +    openslES_DestroyEngine();
   1.197 +    return 0;
   1.198  }
   1.199  
   1.200 -static	void	openslES_DestroyPCMPlayer( void );
   1.201 -static	void	openslES_DestroyPCMRecorder( void );
   1.202 +static void openslES_DestroyPCMPlayer(void);
   1.203 +static void openslES_DestroyPCMRecorder(void);
   1.204  
   1.205 -static void openslES_DestroyEngine( void )
   1.206 +static void openslES_DestroyEngine(void)
   1.207  {
   1.208 -	LOGI( "openslES_DestroyEngine()" );
   1.209 -
   1.210 -	openslES_DestroyPCMPlayer( );
   1.211 -	openslES_DestroyPCMRecorder( );
   1.212 -
   1.213 -	// destroy output mix object, and invalidate all associated interfaces
   1.214 -	if ( outputMixObject != NULL ) {
   1.215 +    LOGI("openslES_DestroyEngine()");
   1.216 +    openslES_DestroyPCMPlayer();
   1.217 +    openslES_DestroyPCMRecorder();
   1.218  
   1.219 -	    (*outputMixObject)->Destroy( outputMixObject );
   1.220 -	    outputMixObject = NULL;
   1.221 -//	    outputMixEnvironmentalReverb = NULL;
   1.222 -	}
   1.223 +    // destroy output mix object, and invalidate all associated interfaces
   1.224 +    if (outputMixObject != NULL) {
   1.225 +        (*outputMixObject)->Destroy(outputMixObject);
   1.226 +        outputMixObject = NULL;
   1.227 +        // outputMixEnvironmentalReverb = NULL;
   1.228 +    }
   1.229  
   1.230 -	// destroy engine object, and invalidate all associated interfaces
   1.231 -	if (engineObject != NULL) {
   1.232 +    // destroy engine object, and invalidate all associated interfaces
   1.233 +    if (engineObject != NULL) {
   1.234 +        (*engineObject)->Destroy(engineObject);
   1.235 +        engineObject = NULL;
   1.236 +        engineEngine = NULL;
   1.237 +    }
   1.238  
   1.239 -	    (*engineObject)->Destroy( engineObject );
   1.240 -	    engineObject = NULL;
   1.241 -	    engineEngine = NULL;
   1.242 -	}
   1.243 -
   1.244 -	return;
   1.245 +    return;
   1.246  }
   1.247  
   1.248  // this callback handler is called every time a buffer finishes playing
   1.249 -static void bqPlayerCallback( SLAndroidSimpleBufferQueueItf bq, void *context )
   1.250 +static void
   1.251 +bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
   1.252  {
   1.253 -	static int	t = 0;
   1.254 -//    assert(bq == bqPlayerBufferQueue);
   1.255 -//    assert(NULL == context);
   1.256 +    static int t = 0;
   1.257 +
   1.258 +    // assert(bq == bqPlayerBufferQueue);
   1.259 +    // assert(NULL == context);
   1.260  
   1.261      // for streaming playback, replace this test by logic to find and fill the next buffer
   1.262  #if 0
   1.263 -	if (--nextCount > 0 && NULL != nextBuffer && 0 != nextSize) {
   1.264 -		SLresult result;
   1.265 -		// enqueue another buffer
   1.266 -		result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize);
   1.267 -		// the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
   1.268 -		// which for this code example would indicate a programming error
   1.269 -		assert(SL_RESULT_SUCCESS == result);
   1.270 -		(void)result;
   1.271 -	}
   1.272 +    if (--nextCount > 0 && NULL != nextBuffer && 0 != nextSize)
   1.273 +    {
   1.274 +        SLresult result;
   1.275 +
   1.276 +        // enqueue another buffer
   1.277 +        result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, nextBuffer, nextSize);
   1.278 +        // the most likely other result is SL_RESULT_BUFFER_INSUFFICIENT,
   1.279 +        // which for this code example would indicate a programming error
   1.280 +        assert(SL_RESULT_SUCCESS == result);
   1.281 +        (void) result;
   1.282 +    }
   1.283  #endif
   1.284 -
   1.285 -	LOGI( "SLES: Playback Callmeback %u", t++ );
   1.286 -
   1.287 -	SDL_SemPost( playsem );
   1.288 -
   1.289 -	return;
   1.290 +    LOGI("SLES: Playback Callmeback %u", t++);
   1.291 +    SDL_SemPost(playsem);
   1.292 +    return;
   1.293  }
   1.294  
   1.295 -static int openslES_CreatePCMRecorder( _THIS )
   1.296 +static int
   1.297 +openslES_CreatePCMRecorder(_THIS)
   1.298  {
   1.299 -	LOGE( "openslES_CreatePCMRecorder not implimented yet!" );
   1.300 -	return SDL_SetError( "openslES_CreatePCMRecorder not implimented yet!" );
   1.301 +    LOGE("openslES_CreatePCMRecorder not implimented yet!");
   1.302 +    return SDL_SetError("openslES_CreatePCMRecorder not implimented yet!");
   1.303  }
   1.304  
   1.305 -static void openslES_DestroyPCMRecorder( void )
   1.306 +static void
   1.307 +openslES_DestroyPCMRecorder(void)
   1.308  {
   1.309 -	return;
   1.310 +    return;
   1.311  }
   1.312  
   1.313 -static int openslES_CreatePCMPlayer( _THIS )
   1.314 +static int
   1.315 +openslES_CreatePCMPlayer(
   1.316 +      _THIS)
   1.317  {
   1.318 -	SLDataFormat_PCM format_pcm;
   1.319 -  SDL_AudioFormat	test_format;
   1.320 -	SLresult result;
   1.321 -	int	i;
   1.322 +    SLDataFormat_PCM format_pcm;
   1.323  
   1.324 -/*
   1.325 -	test_format = SDL_FirstAudioFormat( this->spec.format );
   1.326 +    SLresult result;
   1.327 +    int i;
   1.328  
   1.329 -	while ( test_format != 0 ) {
   1.330 +    /*
   1.331 +      SDL_AudioFormat test_format;
   1.332 +      test_format = SDL_FirstAudioFormat( this->spec.format );
   1.333  
   1.334 -		if ( SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format ) ) break;
   1.335 -		test_format = SDL_NextAudioFormat( );
   1.336 -	}
   1.337 +      while (test_format != 0) {
   1.338  
   1.339 -	if ( test_format == 0 ) {
   1.340 -
   1.341 -		// Didn't find a compatible format :( 
   1.342 -		LOGI( "No compatible audio format!" );
   1.343 -		return SDL_SetError("No compatible audio format!");
   1.344 -	}
   1.345 +          if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) {
   1.346 +              break;
   1.347 +          }
   1.348 +          test_format = SDL_NextAudioFormat();
   1.349 +      }
   1.350  
   1.351 -	this->spec.format = test_format;
   1.352 -*/
   1.353 +      if ( test_format == 0 ) {
   1.354 +          // Didn't find a compatible format :
   1.355 +          LOGI( "No compatible audio format!" );
   1.356 +          return SDL_SetError("No compatible audio format!");
   1.357 +      }
   1.358  
   1.359 - // Update the fragment size as size in bytes 
   1.360 - SDL_CalculateAudioSpec( &this->spec );
   1.361 +      this->spec.format = test_format;
   1.362 +    */
   1.363  
   1.364 -	LOGI( "Try to open %u hz %u bit chan %u %s samples %u", 
   1.365 -			this->spec.freq, SDL_AUDIO_BITSIZE( this->spec.format ), 
   1.366 -			this->spec.channels, (test_format&0x1000) ? "BE" : "LE", this->spec.samples 
   1.367 -		);
   1.368 +    // Update the fragment size as size in bytes
   1.369 +    SDL_CalculateAudioSpec(&this->spec);
   1.370 +
   1.371 +    LOGI("Try to open %u hz %u bit chan %u %s samples %u",
   1.372 +          this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
   1.373 +          this->spec.channels, (test_format & 0x1000) ? "BE" : "LE", this->spec.samples);
   1.374  
   1.375 -	// configure audio source
   1.376 -	SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 };
   1.377 -//	SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS };
   1.378 +    // configure audio source
   1.379 +    SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 };
   1.380 +    // SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS };
   1.381  
   1.382 -	format_pcm.formatType    = SL_DATAFORMAT_PCM;
   1.383 -	format_pcm.numChannels   = this->spec.channels;
   1.384 -	format_pcm.samplesPerSec = this->spec.freq * 1000;	/// kilo Hz to milli Hz
   1.385 -	format_pcm.bitsPerSample = SDL_AUDIO_BITSIZE( this->spec.format );
   1.386 -	format_pcm.containerSize = SDL_AUDIO_BITSIZE( this->spec.format );
   1.387 +    format_pcm.formatType    = SL_DATAFORMAT_PCM;
   1.388 +    format_pcm.numChannels   = this->spec.channels;
   1.389 +    format_pcm.samplesPerSec = this->spec.freq * 1000;  // / kilo Hz to milli Hz
   1.390 +    format_pcm.bitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
   1.391 +    format_pcm.containerSize = SDL_AUDIO_BITSIZE(this->spec.format);
   1.392  
   1.393 -	if ( SDL_AUDIO_ISBIGENDIAN( this->spec.format ) )
   1.394 -		format_pcm.endianness = SL_BYTEORDER_BIGENDIAN;
   1.395 -	else
   1.396 -		format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
   1.397 +    if (SDL_AUDIO_ISBIGENDIAN(this->spec.format)) {
   1.398 +        format_pcm.endianness = SL_BYTEORDER_BIGENDIAN;
   1.399 +    } else {
   1.400 +        format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
   1.401 +    }
   1.402  
   1.403  /*
   1.404 -#define SL_SPEAKER_FRONT_LEFT			((SLuint32) 0x00000001)
   1.405 -#define SL_SPEAKER_FRONT_RIGHT			((SLuint32) 0x00000002)
   1.406 -#define SL_SPEAKER_FRONT_CENTER			((SLuint32) 0x00000004)
   1.407 -#define SL_SPEAKER_LOW_FREQUENCY			((SLuint32) 0x00000008)
   1.408 -#define SL_SPEAKER_BACK_LEFT			((SLuint32) 0x00000010)
   1.409 -#define SL_SPEAKER_BACK_RIGHT			((SLuint32) 0x00000020)
   1.410 -#define SL_SPEAKER_FRONT_LEFT_OF_CENTER	((SLuint32) 0x00000040)
   1.411 -#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER	((SLuint32) 0x00000080)
   1.412 -#define SL_SPEAKER_BACK_CENTER			((SLuint32) 0x00000100)
   1.413 -#define SL_SPEAKER_SIDE_LEFT			((SLuint32) 0x00000200)
   1.414 -#define SL_SPEAKER_SIDE_RIGHT			((SLuint32) 0x00000400)
   1.415 -#define SL_SPEAKER_TOP_CENTER			((SLuint32) 0x00000800)
   1.416 -#define SL_SPEAKER_TOP_FRONT_LEFT		((SLuint32) 0x00001000)
   1.417 -#define SL_SPEAKER_TOP_FRONT_CENTER		((SLuint32) 0x00002000)
   1.418 -#define SL_SPEAKER_TOP_FRONT_RIGHT		((SLuint32) 0x00004000)
   1.419 -#define SL_SPEAKER_TOP_BACK_LEFT			((SLuint32) 0x00008000)
   1.420 -#define SL_SPEAKER_TOP_BACK_CENTER		((SLuint32) 0x00010000)
   1.421 -#define SL_SPEAKER_TOP_BACK_RIGHT		((SLuint32) 0x00020000)
   1.422 +#define SL_SPEAKER_FRONT_LEFT            ((SLuint32) 0x00000001)
   1.423 +#define SL_SPEAKER_FRONT_RIGHT           ((SLuint32) 0x00000002)
   1.424 +#define SL_SPEAKER_FRONT_CENTER          ((SLuint32) 0x00000004)
   1.425 +#define SL_SPEAKER_LOW_FREQUENCY         ((SLuint32) 0x00000008)
   1.426 +#define SL_SPEAKER_BACK_LEFT             ((SLuint32) 0x00000010)
   1.427 +#define SL_SPEAKER_BACK_RIGHT            ((SLuint32) 0x00000020)
   1.428 +#define SL_SPEAKER_FRONT_LEFT_OF_CENTER  ((SLuint32) 0x00000040)
   1.429 +#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER ((SLuint32) 0x00000080)
   1.430 +#define SL_SPEAKER_BACK_CENTER           ((SLuint32) 0x00000100)
   1.431 +#define SL_SPEAKER_SIDE_LEFT             ((SLuint32) 0x00000200)
   1.432 +#define SL_SPEAKER_SIDE_RIGHT            ((SLuint32) 0x00000400)
   1.433 +#define SL_SPEAKER_TOP_CENTER            ((SLuint32) 0x00000800)
   1.434 +#define SL_SPEAKER_TOP_FRONT_LEFT        ((SLuint32) 0x00001000)
   1.435 +#define SL_SPEAKER_TOP_FRONT_CENTER      ((SLuint32) 0x00002000)
   1.436 +#define SL_SPEAKER_TOP_FRONT_RIGHT       ((SLuint32) 0x00004000)
   1.437 +#define SL_SPEAKER_TOP_BACK_LEFT         ((SLuint32) 0x00008000)
   1.438 +#define SL_SPEAKER_TOP_BACK_CENTER       ((SLuint32) 0x00010000)
   1.439 +#define SL_SPEAKER_TOP_BACK_RIGHT        ((SLuint32) 0x00020000)
   1.440  */
   1.441  
   1.442 -	if ( this->spec.channels == 1 )
   1.443 -		format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
   1.444 -	else if ( this->spec.channels == 2 )
   1.445 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
   1.446 -	else if ( this->spec.channels == 3 )
   1.447 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.448 -	else if ( this->spec.channels == 4 )
   1.449 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.450 -								 SL_SPEAKER_BACK_LEFT  | SL_SPEAKER_BACK_RIGHT;
   1.451 -	else
   1.452 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.453 -								 SL_SPEAKER_BACK_LEFT  | SL_SPEAKER_BACK_RIGHT |
   1.454 -								 SL_SPEAKER_FRONT_CENTER;
   1.455 +    if (this->spec.channels == 1) {
   1.456 +        format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
   1.457 +    } else if (this->spec.channels == 2) {
   1.458 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
   1.459 +    } else if (this->spec.channels == 3) {
   1.460 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.461 +    } else if (this->spec.channels == 4) {
   1.462 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.463 +              SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT;
   1.464 +    } else {
   1.465 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.466 +              SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.467 +    }
   1.468  
   1.469 -	SLDataSource audioSrc = { &loc_bufq, &format_pcm };
   1.470 +    SLDataSource audioSrc = { &loc_bufq, &format_pcm };
   1.471  
   1.472 -	// configure audio sink
   1.473 -	SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, outputMixObject };
   1.474 -	SLDataSink audioSnk = { &loc_outmix, NULL };
   1.475 +    // configure audio sink
   1.476 +    SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, outputMixObject };
   1.477 +    SLDataSink audioSnk = { &loc_outmix, NULL };
   1.478  
   1.479      // create audio player
   1.480 -    const SLInterfaceID ids[2] = { 
   1.481 -			SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
   1.482 -			SL_IID_VOLUME 
   1.483 -			};
   1.484 +    const SLInterfaceID ids[2] = {
   1.485 +        SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
   1.486 +        SL_IID_VOLUME
   1.487 +    };
   1.488  
   1.489 -    const SLboolean req[2] = { 
   1.490 -			SL_BOOLEAN_TRUE, 
   1.491 -			SL_BOOLEAN_FALSE,
   1.492 -			};
   1.493 +    const SLboolean req[2] = {
   1.494 +        SL_BOOLEAN_TRUE,
   1.495 +        SL_BOOLEAN_FALSE,
   1.496 +    };
   1.497  
   1.498 -	result = (*engineEngine)->CreateAudioPlayer( engineEngine, &bqPlayerObject, &audioSrc, &audioSnk,
   1.499 -				2, ids, req );
   1.500 -	if ( SL_RESULT_SUCCESS != result ) {
   1.501 -
   1.502 -		LOGE( "CreateAudioPlayer failed" );
   1.503 -		goto failed;
   1.504 -	}
   1.505 +    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 2, ids, req);
   1.506 +    if (SL_RESULT_SUCCESS != result) {
   1.507 +        LOGE("CreateAudioPlayer failed");
   1.508 +        goto failed;
   1.509 +    }
   1.510  
   1.511      // realize the player
   1.512 -	result = (*bqPlayerObject)->Realize( bqPlayerObject, SL_BOOLEAN_FALSE );
   1.513 -	if ( SL_RESULT_SUCCESS != result ) {
   1.514 -
   1.515 -		LOGE( "RealizeAudioPlayer failed" );
   1.516 -		goto failed;
   1.517 -	}
   1.518 +    result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
   1.519 +    if (SL_RESULT_SUCCESS != result) {
   1.520 +        LOGE("RealizeAudioPlayer failed");
   1.521 +        goto failed;
   1.522 +    }
   1.523  
   1.524 -	// get the play interface
   1.525 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay );
   1.526 -	if ( SL_RESULT_SUCCESS != result ) {
   1.527 -
   1.528 -		LOGE( "SL_IID_PLAY interface get failed" );
   1.529 -		goto failed;
   1.530 -	}
   1.531 +    // get the play interface
   1.532 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
   1.533 +    if (SL_RESULT_SUCCESS != result) {
   1.534 +        LOGE("SL_IID_PLAY interface get failed");
   1.535 +        goto failed;
   1.536 +    }
   1.537  
   1.538      // get the buffer queue interface
   1.539 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue );
   1.540 -	if ( SL_RESULT_SUCCESS != result ) {
   1.541 -
   1.542 -		LOGE( "SL_IID_BUFFERQUEUE interface get failed" );
   1.543 -		goto failed;
   1.544 -	}
   1.545 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue);
   1.546 +    if (SL_RESULT_SUCCESS != result) {
   1.547 +        LOGE("SL_IID_BUFFERQUEUE interface get failed");
   1.548 +        goto failed;
   1.549 +    }
   1.550  
   1.551 -	// register callback on the buffer queue
   1.552 -	result = (*bqPlayerBufferQueue)->RegisterCallback( bqPlayerBufferQueue, bqPlayerCallback, NULL );
   1.553 -	if ( SL_RESULT_SUCCESS != result ) {
   1.554 -
   1.555 -		LOGE( "RegisterCallback failed" );
   1.556 -		goto failed;
   1.557 -	}
   1.558 +    // register callback on the buffer queue
   1.559 +    result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);
   1.560 +    if (SL_RESULT_SUCCESS != result) {
   1.561 +        LOGE("RegisterCallback failed");
   1.562 +        goto failed;
   1.563 +    }
   1.564  
   1.565  #if 0
   1.566      // get the effect send interface
   1.567 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend );
   1.568 -	if ( SL_RESULT_SUCCESS != result ) {
   1.569 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend);
   1.570 +    if (SL_RESULT_SUCCESS != result)
   1.571 +    {
   1.572  
   1.573 -		LOGE( "SL_IID_EFFECTSEND interface get failed" );
   1.574 -		goto failed;
   1.575 -	}
   1.576 +        LOGE("SL_IID_EFFECTSEND interface get failed");
   1.577 +        goto failed;
   1.578 +    }
   1.579  #endif
   1.580  
   1.581  #if 0   // mute/solo is not supported for sources that are known to be mono, as this is
   1.582      // get the mute/solo interface
   1.583      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_MUTESOLO, &bqPlayerMuteSolo);
   1.584      assert(SL_RESULT_SUCCESS == result);
   1.585 -    (void)result;
   1.586 +    (void) result;
   1.587  #endif
   1.588  
   1.589      // get the volume interface
   1.590 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume );
   1.591 -	if ( SL_RESULT_SUCCESS != result ) {
   1.592 -
   1.593 -		LOGE( "SL_IID_VOLUME interface get failed" );
   1.594 -//		goto failed;
   1.595 -	}
   1.596 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume);
   1.597 +    if (SL_RESULT_SUCCESS != result) {
   1.598 +        LOGE("SL_IID_VOLUME interface get failed");
   1.599 +        // goto failed;
   1.600 +    }
   1.601  
   1.602 -	// set the player's state to playing
   1.603 -	result = (*bqPlayerPlay)->SetPlayState( bqPlayerPlay, SL_PLAYSTATE_PLAYING );
   1.604 -	if ( SL_RESULT_SUCCESS != result ) {
   1.605 -
   1.606 -		LOGE( "Play set state failed" );
   1.607 -		goto failed;
   1.608 -	}
   1.609 +    // set the player's state to playing
   1.610 +    result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
   1.611 +    if (SL_RESULT_SUCCESS != result) {
   1.612 +        LOGE("Play set state failed");
   1.613 +        goto failed;
   1.614 +    }
   1.615  
   1.616      /* Create the audio buffer semaphore */
   1.617 -	playsem = SDL_CreateSemaphore( NUM_BUFFERS - 1 );
   1.618 -	if ( !playsem ) {
   1.619 -
   1.620 -		LOGE( "cannot create Semaphore!" );
   1.621 -		goto failed;
   1.622 -	}
   1.623 +    playsem = SDL_CreateSemaphore(NUM_BUFFERS - 1);
   1.624 +    if (!playsem) {
   1.625 +        LOGE("cannot create Semaphore!");
   1.626 +        goto failed;
   1.627 +    }
   1.628  
   1.629 -	/* Create the sound buffers */
   1.630 -	mixbuff = (Uint8 *) SDL_malloc( NUM_BUFFERS * this->spec.size );
   1.631 -	if ( mixbuff == NULL) {
   1.632 +    /* Create the sound buffers */
   1.633 +    mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
   1.634 +    if (mixbuff == NULL) {
   1.635 +        LOGE("mixbuffer allocate - out of memory");
   1.636 +        goto failed;
   1.637 +    }
   1.638  
   1.639 -		LOGE( "mixbuffer allocate - out of memory" );
   1.640 -		goto failed;
   1.641 -	}
   1.642 -
   1.643 -	for ( i = 0; i < NUM_BUFFERS; i ++ )
   1.644 -		pmixbuff[i] = mixbuff + i * this->spec.size;
   1.645 +    for (i = 0; i < NUM_BUFFERS; i++) {
   1.646 +        pmixbuff[i] = mixbuff + i * this->spec.size;
   1.647 +    }
   1.648  
   1.649      return 0;
   1.650  
   1.651 -failed:;
   1.652 +failed:
   1.653  
   1.654 -	openslES_DestroyPCMPlayer( );
   1.655 +    openslES_DestroyPCMPlayer();
   1.656  
   1.657 -	return SDL_SetError( "Open device failed!" );
   1.658 +    return SDL_SetError("Open device failed!");
   1.659  }
   1.660  
   1.661 -static void openslES_DestroyPCMPlayer( void )
   1.662 +static void
   1.663 +openslES_DestroyPCMPlayer(void)
   1.664  {
   1.665 -	// destroy buffer queue audio player object, and invalidate all associated interfaces
   1.666 -	if ( bqPlayerObject != NULL ) {
   1.667 -
   1.668 -        (*bqPlayerObject)->Destroy( bqPlayerObject );
   1.669 +    // destroy buffer queue audio player object, and invalidate all associated interfaces
   1.670 +    if (bqPlayerObject != NULL) {
   1.671  
   1.672 -        bqPlayerObject		= NULL;
   1.673 -        bqPlayerPlay		= NULL;
   1.674 +        (*bqPlayerObject)->Destroy(bqPlayerObject);
   1.675 +
   1.676 +        bqPlayerObject = NULL;
   1.677 +        bqPlayerPlay = NULL;
   1.678          bqPlayerBufferQueue = NULL;
   1.679 -//        bqPlayerEffectSend	= NULL;
   1.680 -        bqPlayerMuteSolo	= NULL;
   1.681 -        bqPlayerVolume		= NULL;
   1.682 +        // bqPlayerEffectSend = NULL;
   1.683 +        bqPlayerMuteSolo = NULL;
   1.684 +        bqPlayerVolume = NULL;
   1.685      }
   1.686  
   1.687 -	if ( playsem ) {
   1.688 +    if (playsem) {
   1.689 +        SDL_DestroySemaphore(playsem);
   1.690 +        playsem = NULL;
   1.691 +    }
   1.692  
   1.693 -		SDL_DestroySemaphore( playsem );
   1.694 -		playsem = NULL;
   1.695 -	}
   1.696 +    if (mixbuff) {
   1.697 +        SDL_free(mixbuff);
   1.698 +    }
   1.699  
   1.700 -	if ( mixbuff )
   1.701 -		SDL_free( mixbuff );
   1.702 -
   1.703 -	return;
   1.704 +    return;
   1.705  }
   1.706  
   1.707 -static int openslES_OpenDevice( _THIS, void *handle, const char *devname, int iscapture )
   1.708 +static int
   1.709 +openslES_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
   1.710  {
   1.711 -	if ( iscapture ) {
   1.712 -		LOGI( "openslES_OpenDevice( ) %s for capture", devname );
   1.713 -		return openslES_CreatePCMRecorder( this );
   1.714 -	}
   1.715 -
   1.716 -	LOGI( "openslES_OpenDevice( ) %s for playing", devname );
   1.717 -
   1.718 -	return openslES_CreatePCMPlayer( this );
   1.719 +    if (iscapture) {
   1.720 +        LOGI("openslES_OpenDevice( ) %s for capture", devname);
   1.721 +        return openslES_CreatePCMRecorder(this);
   1.722 +    } else {
   1.723 +        LOGI("openslES_OpenDevice( ) %s for playing", devname);
   1.724 +        return openslES_CreatePCMPlayer(this);
   1.725 +    }
   1.726  }
   1.727  
   1.728 -static void openslES_CloseDevice( _THIS )
   1.729 +static void
   1.730 +openslES_CloseDevice(_THIS)
   1.731  {
   1.732 -	if ( this->iscapture ) {
   1.733 -		LOGI( "openslES_CloseDevice( ) for capture" );
   1.734 -		return openslES_DestroyPCMRecorder( );
   1.735 -	}
   1.736 +    if (this->iscapture) {
   1.737 +        LOGI("openslES_CloseDevice( ) for capture");
   1.738 +        openslES_DestroyPCMRecorder();
   1.739 +    } else {
   1.740 +        LOGI("openslES_CloseDevice( ) for playing");
   1.741 +        openslES_DestroyPCMPlayer();
   1.742 +    }
   1.743  
   1.744 -	LOGI( "openslES_CloseDevice( ) for playing" );
   1.745 -	openslES_DestroyPCMPlayer( );
   1.746 -
   1.747 -	return;
   1.748 +    return;
   1.749  }
   1.750  
   1.751 -static void openslES_WaitDevice( _THIS )
   1.752 +static void
   1.753 +openslES_WaitDevice(_THIS)
   1.754  {
   1.755 -	LOGI( "openslES_WaitDevice( )" );
   1.756 +    LOGI("openslES_WaitDevice( )");
   1.757  
   1.758      /* Wait for an audio chunk to finish */
   1.759 -//    WaitForSingleObject(this->hidden->audio_sem, INFINITE);
   1.760 -	SDL_SemWait( playsem );
   1.761 +    // WaitForSingleObject(this->hidden->audio_sem, INFINITE);
   1.762 +    SDL_SemWait(playsem);
   1.763  
   1.764 -	return;
   1.765 +    return;
   1.766  }
   1.767  
   1.768  ///           n   playn sem
   1.769 @@ -507,65 +506,71 @@
   1.770  // getbuf     1   0     0
   1.771  // fill buff  1   0     0
   1.772  // play       0   0     0
   1.773 -// wait       
   1.774 +// wait
   1.775  //
   1.776  // okay..
   1.777  
   1.778 -
   1.779 -static Uint8 *openslES_GetDeviceBuf( _THIS )
   1.780 +static Uint8 *
   1.781 +openslES_GetDeviceBuf(_THIS)
   1.782  {
   1.783 -	LOGI( "openslES_GetDeviceBuf( )" );
   1.784 -
   1.785 +    LOGI("openslES_GetDeviceBuf( )");
   1.786      return pmixbuff[next_buffer];
   1.787  }
   1.788  
   1.789 -static void openslES_PlayDevice( _THIS )
   1.790 +static void
   1.791 +openslES_PlayDevice(_THIS)
   1.792  {
   1.793 -	SLresult result;
   1.794 +    SLresult result;
   1.795  
   1.796 -	LOGI( "======openslES_PlayDevice( )======" );
   1.797 +    LOGI("======openslES_PlayDevice( )======");
   1.798      /* Queue it up */
   1.799  
   1.800 -	result = (*bqPlayerBufferQueue)->Enqueue( bqPlayerBufferQueue, pmixbuff[next_buffer], this->spec.size );
   1.801 -	if ( SL_RESULT_SUCCESS != result ) { 
   1.802 -		// just puk here
   1.803 -		// next !
   1.804 -	}
   1.805 +    result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, pmixbuff[next_buffer], this->spec.size);
   1.806 +    if (SL_RESULT_SUCCESS != result) {
   1.807 +        // just puk here
   1.808 +        // next !
   1.809 +    }
   1.810  
   1.811 -	next_buffer ++;
   1.812 -	if ( next_buffer >= NUM_BUFFERS ) next_buffer = 0;
   1.813 +    next_buffer++;
   1.814 +    if (next_buffer >= NUM_BUFFERS) {
   1.815 +        next_buffer = 0;
   1.816 +    }
   1.817  
   1.818 -	return;
   1.819 +    return;
   1.820  }
   1.821  
   1.822 -static int openslES_Init( SDL_AudioDriverImpl * impl )
   1.823 +static int
   1.824 +openslES_Init(SDL_AudioDriverImpl * impl)
   1.825  {
   1.826 -	LOGI( "openslES_Init() called" );
   1.827 +    LOGI("openslES_Init() called");
   1.828  
   1.829 -	if ( !openslES_CreateEngine() ) return 0;
   1.830 +    if (!openslES_CreateEngine()) {
   1.831 +        return 0;
   1.832 +    }
   1.833  
   1.834 -	LOGI( "openslES_Init() - set pointers" );
   1.835 +    LOGI("openslES_Init() - set pointers");
   1.836  
   1.837 -	/* Set the function pointers */
   1.838 -//	impl->DetectDevices = openslES_DetectDevices;
   1.839 -	impl->OpenDevice    = openslES_OpenDevice;
   1.840 -   impl->PlayDevice	= openslES_PlayDevice;
   1.841 -   impl->GetDeviceBuf	= openslES_GetDeviceBuf;
   1.842 -	impl->Deinitialize  = openslES_DestroyEngine;
   1.843 -   impl->WaitDevice	= openslES_WaitDevice;
   1.844 +    /* Set the function pointers */
   1.845 +    // impl->DetectDevices = openslES_DetectDevices;
   1.846 +    impl->OpenDevice    = openslES_OpenDevice;
   1.847 +    impl->PlayDevice    = openslES_PlayDevice;
   1.848 +    impl->GetDeviceBuf  = openslES_GetDeviceBuf;
   1.849 +    impl->Deinitialize  = openslES_DestroyEngine;
   1.850 +    impl->WaitDevice    = openslES_WaitDevice;
   1.851  
   1.852 -	/* and the capabilities */
   1.853 -	impl->HasCaptureSupport = 0; /* TODO */
   1.854 -	impl->OnlyHasDefaultOutputDevice = 1;
   1.855 -//	impl->OnlyHasDefaultInputDevice  = 1;
   1.856 +    /* and the capabilities */
   1.857 +    impl->HasCaptureSupport             = 0;        /* TODO */
   1.858 +    impl->OnlyHasDefaultOutputDevice    = 1;
   1.859 +    // impl->OnlyHasDefaultInputDevice  = 1;
   1.860  
   1.861 -	LOGI( "openslES_Init() - succes" );
   1.862 +    LOGI("openslES_Init() - succes");
   1.863  
   1.864 -	return 1;   /* this audio target is available. */
   1.865 +    /* this audio target is available. */
   1.866 +    return 1;
   1.867  }
   1.868  
   1.869  AudioBootStrap openslES_bootstrap = {
   1.870 -	"openslES", "opensl ES audio driver", openslES_Init, 0
   1.871 +    "openslES", "opensl ES audio driver", openslES_Init, 0
   1.872  };
   1.873  
   1.874  #endif /* SDL_AUDIO_DRIVER_OPENSLES */