OpenAL:
- Only show empty buffer warning for debug builds - Code cleanup
This commit is contained in:
parent
f135b6f28a
commit
ee3e7a5e75
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#define ASSERT_SUCCESS assert( AL_NO_ERROR == ALFunction.alGetError() )
|
||||||
|
|
||||||
#ifndef LOGALL
|
#ifndef LOGALL
|
||||||
// replace logging functions with comments
|
// replace logging functions with comments
|
||||||
|
@ -95,27 +96,27 @@ OpenAL::~OpenAL()
|
||||||
if( !initialized ) return;
|
if( !initialized ) return;
|
||||||
|
|
||||||
ALFunction.alSourceStop( source );
|
ALFunction.alSourceStop( source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alSourcei( source, AL_BUFFER, 0 );
|
ALFunction.alSourcei( source, AL_BUFFER, 0 );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alDeleteSources( 1, &source );
|
ALFunction.alDeleteSources( 1, &source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alDeleteBuffers( theApp.oalBufferCount, buffer );
|
ALFunction.alDeleteBuffers( theApp.oalBufferCount, buffer );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
free( buffer );
|
free( buffer );
|
||||||
|
|
||||||
ALFunction.alcMakeContextCurrent( NULL );
|
ALFunction.alcMakeContextCurrent( NULL );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alcDestroyContext( context );
|
ALFunction.alcDestroyContext( context );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alcCloseDevice( device );
|
ALFunction.alcCloseDevice( device );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LOGALL
|
#ifdef LOGALL
|
||||||
|
@ -124,7 +125,7 @@ void OpenAL::debugState()
|
||||||
|
|
||||||
ALint value = 0;
|
ALint value = 0;
|
||||||
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &value );
|
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &value );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
winlog( " soundPaused = %i\n", soundPaused );
|
winlog( " soundPaused = %i\n", soundPaused );
|
||||||
winlog( " Source:\n" );
|
winlog( " Source:\n" );
|
||||||
|
@ -150,11 +151,11 @@ void OpenAL::debugState()
|
||||||
|
|
||||||
|
|
||||||
ALFunction.alGetSourcei( source, AL_BUFFERS_QUEUED, &value );
|
ALFunction.alGetSourcei( source, AL_BUFFERS_QUEUED, &value );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
winlog( " Buffers in queue: %i\n", value );
|
winlog( " Buffers in queue: %i\n", value );
|
||||||
|
|
||||||
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &value );
|
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &value );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
winlog( " Buffers processed: %i\n", value );
|
winlog( " Buffers processed: %i\n", value );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -184,10 +185,10 @@ bool OpenAL::init()
|
||||||
assert( ALC_TRUE == retVal );
|
assert( ALC_TRUE == retVal );
|
||||||
|
|
||||||
ALFunction.alGenBuffers( theApp.oalBufferCount, buffer );
|
ALFunction.alGenBuffers( theApp.oalBufferCount, buffer );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alGenSources( 1, &source );
|
ALFunction.alGenSources( 1, &source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
freq = 44100 / soundQuality;
|
freq = 44100 / soundQuality;
|
||||||
|
|
||||||
|
@ -212,10 +213,10 @@ void OpenAL::resume()
|
||||||
|
|
||||||
ALint sourceState = 0;
|
ALint sourceState = 0;
|
||||||
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
if( sourceState != AL_PLAYING ) {
|
if( sourceState != AL_PLAYING ) {
|
||||||
ALFunction.alSourcePlay( source );
|
ALFunction.alSourcePlay( source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
debugState();
|
debugState();
|
||||||
}
|
}
|
||||||
|
@ -231,10 +232,10 @@ void OpenAL::pause()
|
||||||
|
|
||||||
ALint sourceState = 0;
|
ALint sourceState = 0;
|
||||||
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
if( sourceState == AL_PLAYING ) {
|
if( sourceState == AL_PLAYING ) {
|
||||||
ALFunction.alSourcePause( source );
|
ALFunction.alSourcePause( source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
debugState();
|
debugState();
|
||||||
}
|
}
|
||||||
|
@ -249,10 +250,10 @@ void OpenAL::reset()
|
||||||
|
|
||||||
ALint sourceState = 0;
|
ALint sourceState = 0;
|
||||||
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
if( sourceState != AL_STOPPED ) {
|
if( sourceState != AL_STOPPED ) {
|
||||||
ALFunction.alSourceStop( source );
|
ALFunction.alSourceStop( source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
debugState();
|
debugState();
|
||||||
}
|
}
|
||||||
|
@ -275,19 +276,20 @@ void OpenAL::write()
|
||||||
// Filling the buffers explicitly with silence would be cleaner,
|
// Filling the buffers explicitly with silence would be cleaner,
|
||||||
// but the very first sample is usually silence anyway.
|
// but the very first sample is usually silence anyway.
|
||||||
ALFunction.alBufferData( buffer[i], AL_FORMAT_STEREO16, soundFinalWave, soundBufferLen, freq );
|
ALFunction.alBufferData( buffer[i], AL_FORMAT_STEREO16, soundFinalWave, soundBufferLen, freq );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALFunction.alSourceQueueBuffers( source, theApp.oalBufferCount, buffer );
|
ALFunction.alSourceQueueBuffers( source, theApp.oalBufferCount, buffer );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
buffersLoaded = true;
|
buffersLoaded = true;
|
||||||
} else {
|
} else {
|
||||||
// ==normal buffer refreshing==
|
// ==normal buffer refreshing==
|
||||||
nBuffersProcessed = 0;
|
nBuffersProcessed = 0;
|
||||||
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &nBuffersProcessed );
|
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &nBuffersProcessed );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
if( nBuffersProcessed == theApp.oalBufferCount ) {
|
if( nBuffersProcessed == theApp.oalBufferCount ) {
|
||||||
if( ( theApp.throttle >= 100 ) || ( theApp.throttle == 0 ) ) {
|
if( ( theApp.throttle >= 100 ) || ( theApp.throttle == 0 ) ) {
|
||||||
// we only want to know about it when we are emulating at full speed (or faster)
|
// we only want to know about it when we are emulating at full speed (or faster)
|
||||||
|
@ -295,6 +297,7 @@ void OpenAL::write()
|
||||||
log( "OpenAL: Buffers were not refilled fast enough (%i)\n", i++ );
|
log( "OpenAL: Buffers were not refilled fast enough (%i)\n", i++ );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if( !speedup && synchronize && !theApp.throttle ) {
|
if( !speedup && synchronize && !theApp.throttle ) {
|
||||||
// wait until at least one buffer has finished
|
// wait until at least one buffer has finished
|
||||||
|
@ -304,7 +307,7 @@ void OpenAL::write()
|
||||||
// unoptimized: ( sourceBufferLen * 1000 ) / ( freq * 2 * 2 ) * 1/2
|
// unoptimized: ( sourceBufferLen * 1000 ) / ( freq * 2 * 2 ) * 1/2
|
||||||
Sleep( soundBufferLen / ( freq >> 7 ) );
|
Sleep( soundBufferLen / ( freq >> 7 ) );
|
||||||
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &nBuffersProcessed );
|
ALFunction.alGetSourcei( source, AL_BUFFERS_PROCESSED, &nBuffersProcessed );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if( nBuffersProcessed == 0 ) return;
|
if( nBuffersProcessed == 0 ) return;
|
||||||
|
@ -312,25 +315,26 @@ void OpenAL::write()
|
||||||
|
|
||||||
assert( nBuffersProcessed > 0 );
|
assert( nBuffersProcessed > 0 );
|
||||||
|
|
||||||
// tempBuffer contains the Buffer ID for the unqueued Buffer
|
// unqueue buffer
|
||||||
tempBuffer = 0;
|
tempBuffer = 0;
|
||||||
ALFunction.alSourceUnqueueBuffers( source, 1, &tempBuffer );
|
ALFunction.alSourceUnqueueBuffers( source, 1, &tempBuffer );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
ALFunction.alBufferData( tempBuffer, AL_FORMAT_STEREO16, soundFinalWave, soundBufferLen, freq );
|
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
|
||||||
|
|
||||||
// refill buffer
|
// refill buffer
|
||||||
|
ALFunction.alBufferData( tempBuffer, AL_FORMAT_STEREO16, soundFinalWave, soundBufferLen, freq );
|
||||||
|
ASSERT_SUCCESS;
|
||||||
|
|
||||||
|
// requeue buffer
|
||||||
ALFunction.alSourceQueueBuffers( source, 1, &tempBuffer );
|
ALFunction.alSourceQueueBuffers( source, 1, &tempBuffer );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start playing the source if necessary
|
// start playing the source if necessary
|
||||||
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
ALFunction.alGetSourcei( source, AL_SOURCE_STATE, &sourceState );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
if( !soundPaused && ( sourceState != AL_PLAYING ) ) {
|
if( !soundPaused && ( sourceState != AL_PLAYING ) ) {
|
||||||
ALFunction.alSourcePlay( source );
|
ALFunction.alSourcePlay( source );
|
||||||
assert( AL_NO_ERROR == ALFunction.alGetError() );
|
ASSERT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue