Android/openslES: some space and indentation to match SDL conventions
authorSylvain Becker <sylvain.becker@gmail.com>
Mon, 14 Jan 2019 10:04:54 +0100
changeset 12538fad97a498ffb
parent 12534 682d9b5ecbed
child 12539 e7282e21da92
Android/openslES: some space and indentation to match SDL conventions
src/audio/openslES/SDL_openslES.c
     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 +    // const SLInterfaceID ids[1] = { SL_IID_ENVIRONMENTALREVERB };
   1.154 +    // const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.155  
   1.156 -  const SLInterfaceID ids[1] = { SL_IID_VOLUME };
   1.157 -  const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.158 -  result = (*engineEngine)->CreateOutputMix( engineEngine, &outputMixObject, 1, ids, req );
   1.159 +    const SLInterfaceID ids[1] = { SL_IID_VOLUME };
   1.160 +    const SLboolean req[1] = { SL_BOOLEAN_FALSE };
   1.161 +    result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 1, ids, req);
   1.162  
   1.163 -	if ( SL_RESULT_SUCCESS != result ) {
   1.164 +    if (SL_RESULT_SUCCESS != result) {
   1.165 +        LOGE("CreateOutputMix failed");
   1.166 +        goto error;
   1.167 +    }
   1.168 +    LOGI("CreateOutputMix OK");
   1.169  
   1.170 -		LOGE( "CreateOutputMix failed" );
   1.171 -		goto error;
   1.172 -	}
   1.173 -	LOGI( "CreateOutputMix OK" );
   1.174 +    // realize the output mix
   1.175 +    result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
   1.176 +    if (SL_RESULT_SUCCESS != result) {
   1.177 +        LOGE("RealizeOutputMix failed");
   1.178 +        goto error;
   1.179 +    }
   1.180 +    return 1;
   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 -
   1.186 -		LOGE( "RealizeOutputMix failed" );
   1.187 -		goto error;
   1.188 -	}
   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 +    LOGI("openslES_DestroyEngine()");
   1.210 +    openslES_DestroyPCMPlayer();
   1.211 +    openslES_DestroyPCMRecorder();
   1.212  
   1.213 -	openslES_DestroyPCMPlayer( );
   1.214 -	openslES_DestroyPCMRecorder( );
   1.215 +    // destroy output mix object, and invalidate all associated interfaces
   1.216 +    if (outputMixObject != NULL) {
   1.217 +        (*outputMixObject)->Destroy(outputMixObject);
   1.218 +        outputMixObject = NULL;
   1.219 +        // outputMixEnvironmentalReverb = NULL;
   1.220 +    }
   1.221  
   1.222 -	// destroy output mix object, and invalidate all associated interfaces
   1.223 -	if ( outputMixObject != NULL ) {
   1.224 +    // destroy engine object, and invalidate all associated interfaces
   1.225 +    if (engineObject != NULL) {
   1.226 +        (*engineObject)->Destroy(engineObject);
   1.227 +        engineObject = NULL;
   1.228 +        engineEngine = NULL;
   1.229 +    }
   1.230  
   1.231 -	    (*outputMixObject)->Destroy( outputMixObject );
   1.232 -	    outputMixObject = NULL;
   1.233 -//	    outputMixEnvironmentalReverb = NULL;
   1.234 -	}
   1.235 -
   1.236 -	// destroy engine object, and invalidate all associated interfaces
   1.237 -	if (engineObject != NULL) {
   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 +    SLresult result;
   1.325 +    int i;
   1.326 +
   1.327 +    /*
   1.328 +      SDL_AudioFormat test_format;
   1.329 +      test_format = SDL_FirstAudioFormat( this->spec.format );
   1.330 +
   1.331 +      while (test_format != 0) {
   1.332 +
   1.333 +          if (SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format)) {
   1.334 +              break;
   1.335 +          }
   1.336 +          test_format = SDL_NextAudioFormat();
   1.337 +      }
   1.338 +
   1.339 +      if ( test_format == 0 ) {
   1.340 +          // Didn't find a compatible format :
   1.341 +          LOGI( "No compatible audio format!" );
   1.342 +          return SDL_SetError("No compatible audio format!");
   1.343 +      }
   1.344 +
   1.345 +      this->spec.format = test_format;
   1.346 +    */
   1.347 +
   1.348 +    // Update the fragment size as size in bytes
   1.349 +    SDL_CalculateAudioSpec(&this->spec);
   1.350 +
   1.351 +    LOGI("Try to open %u hz %u bit chan %u %s samples %u",
   1.352 +          this->spec.freq, SDL_AUDIO_BITSIZE(this->spec.format),
   1.353 +          this->spec.channels, (test_format & 0x1000) ? "BE" : "LE", this->spec.samples);
   1.354 +
   1.355 +    // configure audio source
   1.356 +    SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 };
   1.357 +    // SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS };
   1.358 +
   1.359 +    format_pcm.formatType    = SL_DATAFORMAT_PCM;
   1.360 +    format_pcm.numChannels   = this->spec.channels;
   1.361 +    format_pcm.samplesPerSec = this->spec.freq * 1000;  // / kilo Hz to milli Hz
   1.362 +    format_pcm.bitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
   1.363 +    format_pcm.containerSize = SDL_AUDIO_BITSIZE(this->spec.format);
   1.364 +
   1.365 +    if (SDL_AUDIO_ISBIGENDIAN(this->spec.format)) {
   1.366 +        format_pcm.endianness = SL_BYTEORDER_BIGENDIAN;
   1.367 +    } else {
   1.368 +        format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
   1.369 +    }
   1.370  
   1.371  /*
   1.372 -	test_format = SDL_FirstAudioFormat( this->spec.format );
   1.373 -
   1.374 -	while ( test_format != 0 ) {
   1.375 -
   1.376 -		if ( SDL_AUDIO_ISSIGNED(test_format) && SDL_AUDIO_ISINT(test_format ) ) break;
   1.377 -		test_format = SDL_NextAudioFormat( );
   1.378 -	}
   1.379 -
   1.380 -	if ( test_format == 0 ) {
   1.381 -
   1.382 -		// Didn't find a compatible format :( 
   1.383 -		LOGI( "No compatible audio format!" );
   1.384 -		return SDL_SetError("No compatible audio format!");
   1.385 -	}
   1.386 -
   1.387 -	this->spec.format = test_format;
   1.388 +#define SL_SPEAKER_FRONT_LEFT            ((SLuint32) 0x00000001)
   1.389 +#define SL_SPEAKER_FRONT_RIGHT           ((SLuint32) 0x00000002)
   1.390 +#define SL_SPEAKER_FRONT_CENTER          ((SLuint32) 0x00000004)
   1.391 +#define SL_SPEAKER_LOW_FREQUENCY         ((SLuint32) 0x00000008)
   1.392 +#define SL_SPEAKER_BACK_LEFT             ((SLuint32) 0x00000010)
   1.393 +#define SL_SPEAKER_BACK_RIGHT            ((SLuint32) 0x00000020)
   1.394 +#define SL_SPEAKER_FRONT_LEFT_OF_CENTER  ((SLuint32) 0x00000040)
   1.395 +#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER ((SLuint32) 0x00000080)
   1.396 +#define SL_SPEAKER_BACK_CENTER           ((SLuint32) 0x00000100)
   1.397 +#define SL_SPEAKER_SIDE_LEFT             ((SLuint32) 0x00000200)
   1.398 +#define SL_SPEAKER_SIDE_RIGHT            ((SLuint32) 0x00000400)
   1.399 +#define SL_SPEAKER_TOP_CENTER            ((SLuint32) 0x00000800)
   1.400 +#define SL_SPEAKER_TOP_FRONT_LEFT        ((SLuint32) 0x00001000)
   1.401 +#define SL_SPEAKER_TOP_FRONT_CENTER      ((SLuint32) 0x00002000)
   1.402 +#define SL_SPEAKER_TOP_FRONT_RIGHT       ((SLuint32) 0x00004000)
   1.403 +#define SL_SPEAKER_TOP_BACK_LEFT         ((SLuint32) 0x00008000)
   1.404 +#define SL_SPEAKER_TOP_BACK_CENTER       ((SLuint32) 0x00010000)
   1.405 +#define SL_SPEAKER_TOP_BACK_RIGHT        ((SLuint32) 0x00020000)
   1.406  */
   1.407  
   1.408 - // Update the fragment size as size in bytes 
   1.409 - SDL_CalculateAudioSpec( &this->spec );
   1.410 +    if (this->spec.channels == 1) {
   1.411 +        format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
   1.412 +    } else if (this->spec.channels == 2) {
   1.413 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
   1.414 +    } else if (this->spec.channels == 3) {
   1.415 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.416 +    } else if (this->spec.channels == 4) {
   1.417 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.418 +              SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT;
   1.419 +    } else {
   1.420 +        format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.421 +              SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.422 +    }
   1.423  
   1.424 -	LOGI( "Try to open %u hz %u bit chan %u %s samples %u", 
   1.425 -			this->spec.freq, SDL_AUDIO_BITSIZE( this->spec.format ), 
   1.426 -			this->spec.channels, (test_format&0x1000) ? "BE" : "LE", this->spec.samples 
   1.427 -		);
   1.428 +    SLDataSource audioSrc = { &loc_bufq, &format_pcm };
   1.429  
   1.430 -	// configure audio source
   1.431 -	SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 };
   1.432 -//	SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, OPENSLES_BUFFERS };
   1.433 -
   1.434 -	format_pcm.formatType    = SL_DATAFORMAT_PCM;
   1.435 -	format_pcm.numChannels   = this->spec.channels;
   1.436 -	format_pcm.samplesPerSec = this->spec.freq * 1000;	/// kilo Hz to milli Hz
   1.437 -	format_pcm.bitsPerSample = SDL_AUDIO_BITSIZE( this->spec.format );
   1.438 -	format_pcm.containerSize = SDL_AUDIO_BITSIZE( this->spec.format );
   1.439 -
   1.440 -	if ( SDL_AUDIO_ISBIGENDIAN( this->spec.format ) )
   1.441 -		format_pcm.endianness = SL_BYTEORDER_BIGENDIAN;
   1.442 -	else
   1.443 -		format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
   1.444 -
   1.445 -/*
   1.446 -#define SL_SPEAKER_FRONT_LEFT			((SLuint32) 0x00000001)
   1.447 -#define SL_SPEAKER_FRONT_RIGHT			((SLuint32) 0x00000002)
   1.448 -#define SL_SPEAKER_FRONT_CENTER			((SLuint32) 0x00000004)
   1.449 -#define SL_SPEAKER_LOW_FREQUENCY			((SLuint32) 0x00000008)
   1.450 -#define SL_SPEAKER_BACK_LEFT			((SLuint32) 0x00000010)
   1.451 -#define SL_SPEAKER_BACK_RIGHT			((SLuint32) 0x00000020)
   1.452 -#define SL_SPEAKER_FRONT_LEFT_OF_CENTER	((SLuint32) 0x00000040)
   1.453 -#define SL_SPEAKER_FRONT_RIGHT_OF_CENTER	((SLuint32) 0x00000080)
   1.454 -#define SL_SPEAKER_BACK_CENTER			((SLuint32) 0x00000100)
   1.455 -#define SL_SPEAKER_SIDE_LEFT			((SLuint32) 0x00000200)
   1.456 -#define SL_SPEAKER_SIDE_RIGHT			((SLuint32) 0x00000400)
   1.457 -#define SL_SPEAKER_TOP_CENTER			((SLuint32) 0x00000800)
   1.458 -#define SL_SPEAKER_TOP_FRONT_LEFT		((SLuint32) 0x00001000)
   1.459 -#define SL_SPEAKER_TOP_FRONT_CENTER		((SLuint32) 0x00002000)
   1.460 -#define SL_SPEAKER_TOP_FRONT_RIGHT		((SLuint32) 0x00004000)
   1.461 -#define SL_SPEAKER_TOP_BACK_LEFT			((SLuint32) 0x00008000)
   1.462 -#define SL_SPEAKER_TOP_BACK_CENTER		((SLuint32) 0x00010000)
   1.463 -#define SL_SPEAKER_TOP_BACK_RIGHT		((SLuint32) 0x00020000)
   1.464 -*/
   1.465 -
   1.466 -	if ( this->spec.channels == 1 )
   1.467 -		format_pcm.channelMask = SL_SPEAKER_FRONT_CENTER;
   1.468 -	else if ( this->spec.channels == 2 )
   1.469 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
   1.470 -	else if ( this->spec.channels == 3 )
   1.471 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | SL_SPEAKER_FRONT_CENTER;
   1.472 -	else if ( this->spec.channels == 4 )
   1.473 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.474 -								 SL_SPEAKER_BACK_LEFT  | SL_SPEAKER_BACK_RIGHT;
   1.475 -	else
   1.476 -		format_pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT |
   1.477 -								 SL_SPEAKER_BACK_LEFT  | SL_SPEAKER_BACK_RIGHT |
   1.478 -								 SL_SPEAKER_FRONT_CENTER;
   1.479 -
   1.480 -	SLDataSource audioSrc = { &loc_bufq, &format_pcm };
   1.481 -
   1.482 -	// configure audio sink
   1.483 -	SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, outputMixObject };
   1.484 -	SLDataSink audioSnk = { &loc_outmix, NULL };
   1.485 +    // configure audio sink
   1.486 +    SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, outputMixObject };
   1.487 +    SLDataSink audioSnk = { &loc_outmix, NULL };
   1.488  
   1.489      // create audio player
   1.490 -    const SLInterfaceID ids[2] = { 
   1.491 -			SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
   1.492 -			SL_IID_VOLUME 
   1.493 -			};
   1.494 +    const SLInterfaceID ids[2] = {
   1.495 +        SL_IID_ANDROIDSIMPLEBUFFERQUEUE,
   1.496 +        SL_IID_VOLUME
   1.497 +    };
   1.498  
   1.499 -    const SLboolean req[2] = { 
   1.500 -			SL_BOOLEAN_TRUE, 
   1.501 -			SL_BOOLEAN_FALSE,
   1.502 -			};
   1.503 +    const SLboolean req[2] = {
   1.504 +        SL_BOOLEAN_TRUE,
   1.505 +        SL_BOOLEAN_FALSE,
   1.506 +    };
   1.507  
   1.508 -	result = (*engineEngine)->CreateAudioPlayer( engineEngine, &bqPlayerObject, &audioSrc, &audioSnk,
   1.509 -				2, ids, req );
   1.510 -	if ( SL_RESULT_SUCCESS != result ) {
   1.511 -
   1.512 -		LOGE( "CreateAudioPlayer failed" );
   1.513 -		goto failed;
   1.514 -	}
   1.515 +    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 2, ids, req);
   1.516 +    if (SL_RESULT_SUCCESS != result) {
   1.517 +        LOGE("CreateAudioPlayer failed");
   1.518 +        goto failed;
   1.519 +    }
   1.520  
   1.521      // realize the player
   1.522 -	result = (*bqPlayerObject)->Realize( bqPlayerObject, SL_BOOLEAN_FALSE );
   1.523 -	if ( SL_RESULT_SUCCESS != result ) {
   1.524 +    result = (*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
   1.525 +    if (SL_RESULT_SUCCESS != result) {
   1.526 +        LOGE("RealizeAudioPlayer failed");
   1.527 +        goto failed;
   1.528 +    }
   1.529  
   1.530 -		LOGE( "RealizeAudioPlayer failed" );
   1.531 -		goto failed;
   1.532 -	}
   1.533 -
   1.534 -	// get the play interface
   1.535 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay );
   1.536 -	if ( SL_RESULT_SUCCESS != result ) {
   1.537 -
   1.538 -		LOGE( "SL_IID_PLAY interface get failed" );
   1.539 -		goto failed;
   1.540 -	}
   1.541 +    // get the play interface
   1.542 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
   1.543 +    if (SL_RESULT_SUCCESS != result) {
   1.544 +        LOGE("SL_IID_PLAY interface get failed");
   1.545 +        goto failed;
   1.546 +    }
   1.547  
   1.548      // get the buffer queue interface
   1.549 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue );
   1.550 -	if ( SL_RESULT_SUCCESS != result ) {
   1.551 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue);
   1.552 +    if (SL_RESULT_SUCCESS != result) {
   1.553 +        LOGE("SL_IID_BUFFERQUEUE interface get failed");
   1.554 +        goto failed;
   1.555 +    }
   1.556  
   1.557 -		LOGE( "SL_IID_BUFFERQUEUE interface get failed" );
   1.558 -		goto failed;
   1.559 -	}
   1.560 -
   1.561 -	// register callback on the buffer queue
   1.562 -	result = (*bqPlayerBufferQueue)->RegisterCallback( bqPlayerBufferQueue, bqPlayerCallback, NULL );
   1.563 -	if ( SL_RESULT_SUCCESS != result ) {
   1.564 -
   1.565 -		LOGE( "RegisterCallback failed" );
   1.566 -		goto failed;
   1.567 -	}
   1.568 +    // register callback on the buffer queue
   1.569 +    result = (*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue, bqPlayerCallback, NULL);
   1.570 +    if (SL_RESULT_SUCCESS != result) {
   1.571 +        LOGE("RegisterCallback failed");
   1.572 +        goto failed;
   1.573 +    }
   1.574  
   1.575  #if 0
   1.576      // get the effect send interface
   1.577 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend );
   1.578 -	if ( SL_RESULT_SUCCESS != result ) {
   1.579 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_EFFECTSEND, &bqPlayerEffectSend);
   1.580 +    if (SL_RESULT_SUCCESS != result)
   1.581 +    {
   1.582  
   1.583 -		LOGE( "SL_IID_EFFECTSEND interface get failed" );
   1.584 -		goto failed;
   1.585 -	}
   1.586 +        LOGE("SL_IID_EFFECTSEND interface get failed");
   1.587 +        goto failed;
   1.588 +    }
   1.589  #endif
   1.590  
   1.591  #if 0   // mute/solo is not supported for sources that are known to be mono, as this is
   1.592      // get the mute/solo interface
   1.593      result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_MUTESOLO, &bqPlayerMuteSolo);
   1.594      assert(SL_RESULT_SUCCESS == result);
   1.595 -    (void)result;
   1.596 +    (void) result;
   1.597  #endif
   1.598  
   1.599      // get the volume interface
   1.600 -	result = (*bqPlayerObject)->GetInterface( bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume );
   1.601 -	if ( SL_RESULT_SUCCESS != result ) {
   1.602 +    result = (*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_VOLUME, &bqPlayerVolume);
   1.603 +    if (SL_RESULT_SUCCESS != result) {
   1.604 +        LOGE("SL_IID_VOLUME interface get failed");
   1.605 +        // goto failed;
   1.606 +    }
   1.607  
   1.608 -		LOGE( "SL_IID_VOLUME interface get failed" );
   1.609 -//		goto failed;
   1.610 -	}
   1.611 -
   1.612 -	// set the player's state to playing
   1.613 -	result = (*bqPlayerPlay)->SetPlayState( bqPlayerPlay, SL_PLAYSTATE_PLAYING );
   1.614 -	if ( SL_RESULT_SUCCESS != result ) {
   1.615 -
   1.616 -		LOGE( "Play set state failed" );
   1.617 -		goto failed;
   1.618 -	}
   1.619 +    // set the player's state to playing
   1.620 +    result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
   1.621 +    if (SL_RESULT_SUCCESS != result) {
   1.622 +        LOGE("Play set state failed");
   1.623 +        goto failed;
   1.624 +    }
   1.625  
   1.626      /* Create the audio buffer semaphore */
   1.627 -	playsem = SDL_CreateSemaphore( NUM_BUFFERS - 1 );
   1.628 -	if ( !playsem ) {
   1.629 +    playsem = SDL_CreateSemaphore(NUM_BUFFERS - 1);
   1.630 +    if (!playsem) {
   1.631 +        LOGE("cannot create Semaphore!");
   1.632 +        goto failed;
   1.633 +    }
   1.634  
   1.635 -		LOGE( "cannot create Semaphore!" );
   1.636 -		goto failed;
   1.637 -	}
   1.638 +    /* Create the sound buffers */
   1.639 +    mixbuff = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size);
   1.640 +    if (mixbuff == NULL) {
   1.641 +        LOGE("mixbuffer allocate - out of memory");
   1.642 +        goto failed;
   1.643 +    }
   1.644  
   1.645 -	/* Create the sound buffers */
   1.646 -	mixbuff = (Uint8 *) SDL_malloc( NUM_BUFFERS * this->spec.size );
   1.647 -	if ( mixbuff == NULL) {
   1.648 -
   1.649 -		LOGE( "mixbuffer allocate - out of memory" );
   1.650 -		goto failed;
   1.651 -	}
   1.652 -
   1.653 -	for ( i = 0; i < NUM_BUFFERS; i ++ )
   1.654 -		pmixbuff[i] = mixbuff + i * this->spec.size;
   1.655 +    for (i = 0; i < NUM_BUFFERS; i++) {
   1.656 +        pmixbuff[i] = mixbuff + i * this->spec.size;
   1.657 +    }
   1.658  
   1.659      return 0;
   1.660  
   1.661 -failed:;
   1.662 +failed:
   1.663  
   1.664 -	openslES_DestroyPCMPlayer( );
   1.665 +    openslES_DestroyPCMPlayer();
   1.666  
   1.667 -	return SDL_SetError( "Open device failed!" );
   1.668 +    return SDL_SetError("Open device failed!");
   1.669  }
   1.670  
   1.671 -static void openslES_DestroyPCMPlayer( void )
   1.672 +static void
   1.673 +openslES_DestroyPCMPlayer(void)
   1.674  {
   1.675 -	// destroy buffer queue audio player object, and invalidate all associated interfaces
   1.676 -	if ( bqPlayerObject != NULL ) {
   1.677 +    // destroy buffer queue audio player object, and invalidate all associated interfaces
   1.678 +    if (bqPlayerObject != NULL) {
   1.679  
   1.680 -        (*bqPlayerObject)->Destroy( bqPlayerObject );
   1.681 +        (*bqPlayerObject)->Destroy(bqPlayerObject);
   1.682  
   1.683 -        bqPlayerObject		= NULL;
   1.684 -        bqPlayerPlay		= NULL;
   1.685 +        bqPlayerObject = NULL;
   1.686 +        bqPlayerPlay = NULL;
   1.687          bqPlayerBufferQueue = NULL;
   1.688 -//        bqPlayerEffectSend	= NULL;
   1.689 -        bqPlayerMuteSolo	= NULL;
   1.690 -        bqPlayerVolume		= NULL;
   1.691 +        // bqPlayerEffectSend = NULL;
   1.692 +        bqPlayerMuteSolo = NULL;
   1.693 +        bqPlayerVolume = NULL;
   1.694      }
   1.695  
   1.696 -	if ( playsem ) {
   1.697 +    if (playsem) {
   1.698 +        SDL_DestroySemaphore(playsem);
   1.699 +        playsem = NULL;
   1.700 +    }
   1.701  
   1.702 -		SDL_DestroySemaphore( playsem );
   1.703 -		playsem = NULL;
   1.704 -	}
   1.705 +    if (mixbuff) {
   1.706 +        SDL_free(mixbuff);
   1.707 +    }
   1.708  
   1.709 -	if ( mixbuff )
   1.710 -		SDL_free( mixbuff );
   1.711 -
   1.712 -	return;
   1.713 +    return;
   1.714  }
   1.715  
   1.716 -static int openslES_OpenDevice( _THIS, void *handle, const char *devname, int iscapture )
   1.717 +static int
   1.718 +openslES_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
   1.719  {
   1.720 -	if ( iscapture ) {
   1.721 -		LOGI( "openslES_OpenDevice( ) %s for capture", devname );
   1.722 -		return openslES_CreatePCMRecorder( this );
   1.723 -	}
   1.724 -
   1.725 -	LOGI( "openslES_OpenDevice( ) %s for playing", devname );
   1.726 -
   1.727 -	return openslES_CreatePCMPlayer( this );
   1.728 +    if (iscapture) {
   1.729 +        LOGI("openslES_OpenDevice( ) %s for capture", devname);
   1.730 +        return openslES_CreatePCMRecorder(this);
   1.731 +    } else {
   1.732 +        LOGI("openslES_OpenDevice( ) %s for playing", devname);
   1.733 +        return openslES_CreatePCMPlayer(this);
   1.734 +    }
   1.735  }
   1.736  
   1.737 -static void openslES_CloseDevice( _THIS )
   1.738 +static void
   1.739 +openslES_CloseDevice(_THIS)
   1.740  {
   1.741 -	if ( this->iscapture ) {
   1.742 -		LOGI( "openslES_CloseDevice( ) for capture" );
   1.743 -		return openslES_DestroyPCMRecorder( );
   1.744 -	}
   1.745 +    if (this->iscapture) {
   1.746 +        LOGI("openslES_CloseDevice( ) for capture");
   1.747 +        openslES_DestroyPCMRecorder();
   1.748 +    } else {
   1.749 +        LOGI("openslES_CloseDevice( ) for playing");
   1.750 +        openslES_DestroyPCMPlayer();
   1.751 +    }
   1.752  
   1.753 -	LOGI( "openslES_CloseDevice( ) for playing" );
   1.754 -	openslES_DestroyPCMPlayer( );
   1.755 -
   1.756 -	return;
   1.757 +    return;
   1.758  }
   1.759  
   1.760 -static void openslES_WaitDevice( _THIS )
   1.761 +static void
   1.762 +openslES_WaitDevice(_THIS)
   1.763  {
   1.764 -	LOGI( "openslES_WaitDevice( )" );
   1.765 +    LOGI("openslES_WaitDevice( )");
   1.766  
   1.767      /* Wait for an audio chunk to finish */
   1.768 -//    WaitForSingleObject(this->hidden->audio_sem, INFINITE);
   1.769 -	SDL_SemWait( playsem );
   1.770 +    // WaitForSingleObject(this->hidden->audio_sem, INFINITE);
   1.771 +    SDL_SemWait(playsem);
   1.772  
   1.773 -	return;
   1.774 +    return;
   1.775  }
   1.776  
   1.777  ///           n   playn sem
   1.778 @@ -507,65 +506,71 @@
   1.779  // getbuf     1   0     0
   1.780  // fill buff  1   0     0
   1.781  // play       0   0     0
   1.782 -// wait       
   1.783 +// wait
   1.784  //
   1.785  // okay..
   1.786  
   1.787 -
   1.788 -static Uint8 *openslES_GetDeviceBuf( _THIS )
   1.789 +static Uint8 *
   1.790 +openslES_GetDeviceBuf(_THIS)
   1.791  {
   1.792 -	LOGI( "openslES_GetDeviceBuf( )" );
   1.793 -
   1.794 +    LOGI("openslES_GetDeviceBuf( )");
   1.795      return pmixbuff[next_buffer];
   1.796  }
   1.797  
   1.798 -static void openslES_PlayDevice( _THIS )
   1.799 +static void
   1.800 +openslES_PlayDevice(_THIS)
   1.801  {
   1.802 -	SLresult result;
   1.803 +    SLresult result;
   1.804  
   1.805 -	LOGI( "======openslES_PlayDevice( )======" );
   1.806 +    LOGI("======openslES_PlayDevice( )======");
   1.807      /* Queue it up */
   1.808  
   1.809 -	result = (*bqPlayerBufferQueue)->Enqueue( bqPlayerBufferQueue, pmixbuff[next_buffer], this->spec.size );
   1.810 -	if ( SL_RESULT_SUCCESS != result ) { 
   1.811 -		// just puk here
   1.812 -		// next !
   1.813 -	}
   1.814 +    result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, pmixbuff[next_buffer], this->spec.size);
   1.815 +    if (SL_RESULT_SUCCESS != result) {
   1.816 +        // just puk here
   1.817 +        // next !
   1.818 +    }
   1.819  
   1.820 -	next_buffer ++;
   1.821 -	if ( next_buffer >= NUM_BUFFERS ) next_buffer = 0;
   1.822 +    next_buffer++;
   1.823 +    if (next_buffer >= NUM_BUFFERS) {
   1.824 +        next_buffer = 0;
   1.825 +    }
   1.826  
   1.827 -	return;
   1.828 +    return;
   1.829  }
   1.830  
   1.831 -static int openslES_Init( SDL_AudioDriverImpl * impl )
   1.832 +static int
   1.833 +openslES_Init(SDL_AudioDriverImpl * impl)
   1.834  {
   1.835 -	LOGI( "openslES_Init() called" );
   1.836 +    LOGI("openslES_Init() called");
   1.837  
   1.838 -	if ( !openslES_CreateEngine() ) return 0;
   1.839 +    if (!openslES_CreateEngine()) {
   1.840 +        return 0;
   1.841 +    }
   1.842  
   1.843 -	LOGI( "openslES_Init() - set pointers" );
   1.844 +    LOGI("openslES_Init() - set pointers");
   1.845  
   1.846 -	/* Set the function pointers */
   1.847 -//	impl->DetectDevices = openslES_DetectDevices;
   1.848 -	impl->OpenDevice    = openslES_OpenDevice;
   1.849 -   impl->PlayDevice	= openslES_PlayDevice;
   1.850 -   impl->GetDeviceBuf	= openslES_GetDeviceBuf;
   1.851 -	impl->Deinitialize  = openslES_DestroyEngine;
   1.852 -   impl->WaitDevice	= openslES_WaitDevice;
   1.853 +    /* Set the function pointers */
   1.854 +    // impl->DetectDevices = openslES_DetectDevices;
   1.855 +    impl->OpenDevice    = openslES_OpenDevice;
   1.856 +    impl->PlayDevice    = openslES_PlayDevice;
   1.857 +    impl->GetDeviceBuf  = openslES_GetDeviceBuf;
   1.858 +    impl->Deinitialize  = openslES_DestroyEngine;
   1.859 +    impl->WaitDevice    = openslES_WaitDevice;
   1.860  
   1.861 -	/* and the capabilities */
   1.862 -	impl->HasCaptureSupport = 0; /* TODO */
   1.863 -	impl->OnlyHasDefaultOutputDevice = 1;
   1.864 -//	impl->OnlyHasDefaultInputDevice  = 1;
   1.865 +    /* and the capabilities */
   1.866 +    impl->HasCaptureSupport             = 0;        /* TODO */
   1.867 +    impl->OnlyHasDefaultOutputDevice    = 1;
   1.868 +    // impl->OnlyHasDefaultInputDevice  = 1;
   1.869  
   1.870 -	LOGI( "openslES_Init() - succes" );
   1.871 +    LOGI("openslES_Init() - succes");
   1.872  
   1.873 -	return 1;   /* this audio target is available. */
   1.874 +    /* this audio target is available. */
   1.875 +    return 1;
   1.876  }
   1.877  
   1.878  AudioBootStrap openslES_bootstrap = {
   1.879 -	"openslES", "opensl ES audio driver", openslES_Init, 0
   1.880 +    "openslES", "opensl ES audio driver", openslES_Init, 0
   1.881  };
   1.882  
   1.883  #endif /* SDL_AUDIO_DRIVER_OPENSLES */