Don't use any idAudioHardware implementations

OpenAL for everyone.
This commit is contained in:
dhewg 2011-12-14 17:16:30 +01:00
parent 4e26e1ac6f
commit 93e5345fbc
4 changed files with 37 additions and 170 deletions

View file

@ -3058,7 +3058,6 @@ void idCommonLocal::ShutdownGame( bool reloading ) {
if ( sw ) { if ( sw ) {
sw->StopAllSounds(); sw->StopAllSounds();
} }
soundSystem->ClearBuffer();
// shutdown the script debugger // shutdown the script debugger
// DebuggerServerShutdown(); // DebuggerServerShutdown();

View file

@ -606,7 +606,6 @@ public:
void Shutdown( void ); void Shutdown( void );
void Init( idRenderWorld *rw ); void Init( idRenderWorld *rw );
void ClearBuffer( void );
// update // update
void ForegroundUpdate( int currentTime ); void ForegroundUpdate( int currentTime );
@ -683,7 +682,6 @@ public:
// shutdown routine // shutdown routine
virtual void Shutdown( void ); virtual void Shutdown( void );
virtual void ClearBuffer( void );
// sound is attached to the window, and must be recreated when the window is changed // sound is attached to the window, and must be recreated when the window is changed
virtual bool ShutdownHW( void ); virtual bool ShutdownHW( void );
@ -731,7 +729,6 @@ public:
ALuint AllocOpenALSource( idSoundChannel *chan, bool looping, bool stereo ); ALuint AllocOpenALSource( idSoundChannel *chan, bool looping, bool stereo );
void FreeOpenALSource( ALuint handle ); void FreeOpenALSource( ALuint handle );
idAudioHardware * snd_audio_hw;
idSoundCache * soundCache; idSoundCache * soundCache;
idSoundWorldLocal * currentSoundWorld; // the one to mix each async tic idSoundWorldLocal * currentSoundWorld; // the one to mix each async tic

View file

@ -426,30 +426,25 @@ void idSoundSystemLocal::Shutdown() {
// EAX or not, the list needs to be cleared // EAX or not, the list needs to be cleared
EFXDatabase.Clear(); EFXDatabase.Clear();
// destroy openal sources efxloaded = false;
if ( useOpenAL ) {
efxloaded = false; // adjust source count back up to allow for freeing of all resources
openalSourceCount += 8;
// adjust source count back up to allow for freeing of all resources for ( ALsizei i = 0; i < openalSourceCount; i++ ) {
openalSourceCount += 8; // stop source
alSourceStop( openalSources[i].handle );
alSourcei( openalSources[i].handle, AL_BUFFER, 0 );
for ( ALsizei i = 0; i < openalSourceCount; i++ ) { // delete source
// stop source alDeleteSources( 1, &openalSources[i].handle );
alSourceStop( openalSources[i].handle );
alSourcei( openalSources[i].handle, AL_BUFFER, 0 );
// delete source // clear entry in source array
alDeleteSources( 1, &openalSources[i].handle ); openalSources[i].handle = 0;
openalSources[i].startTime = 0;
// clear entry in source array openalSources[i].chan = NULL;
openalSources[i].handle = 0; openalSources[i].inUse = false;
openalSources[i].startTime = 0; openalSources[i].looping = false;
openalSources[i].chan = NULL;
openalSources[i].inUse = false;
openalSources[i].looping = false;
}
} }
// destroy all the sounds (hardware buffers as well) // destroy all the sounds (hardware buffers as well)
@ -457,15 +452,13 @@ void idSoundSystemLocal::Shutdown() {
soundCache = NULL; soundCache = NULL;
// destroy openal device and context // destroy openal device and context
if ( useOpenAL ) { alcMakeContextCurrent( NULL );
alcMakeContextCurrent( NULL );
alcDestroyContext( openalContext ); alcDestroyContext( openalContext );
openalContext = NULL; openalContext = NULL;
alcCloseDevice( openalDevice ); alcCloseDevice( openalDevice );
openalDevice = NULL; openalDevice = NULL;
}
idSampleDecoder::Shutdown(); idSampleDecoder::Shutdown();
} }
@ -488,26 +481,6 @@ bool idSoundSystemLocal::InitHW() {
return false; return false;
} }
delete snd_audio_hw;
snd_audio_hw = idAudioHardware::Alloc();
if ( snd_audio_hw == NULL ) {
return false;
}
if ( !useOpenAL ) {
if ( !snd_audio_hw->Initialize() ) {
delete snd_audio_hw;
snd_audio_hw = NULL;
return false;
}
if ( snd_audio_hw->GetNumberOfSpeakers() == 0 ) {
return false;
}
numSpeakers = snd_audio_hw->GetNumberOfSpeakers();
}
// put the real number in there // put the real number in there
s_numberOfSpeakers.SetInteger(numSpeakers); s_numberOfSpeakers.SetInteger(numSpeakers);
@ -532,9 +505,6 @@ bool idSoundSystemLocal::ShutdownHW() {
common->Printf( "Shutting down sound hardware\n" ); common->Printf( "Shutting down sound hardware\n" );
delete snd_audio_hw;
snd_audio_hw = NULL;
isInitialized = false; isInitialized = false;
if ( graph ) { if ( graph ) {
@ -551,40 +521,15 @@ idSoundSystemLocal::GetCurrent44kHzTime
=============== ===============
*/ */
int idSoundSystemLocal::GetCurrent44kHzTime( void ) const { int idSoundSystemLocal::GetCurrent44kHzTime( void ) const {
if ( snd_audio_hw ) { if ( isInitialized ) {
return CurrentSoundTime; return CurrentSoundTime;
} else { } else {
// NOTE: this would overflow 31bits within about 1h20 ( not that important since we get a snd_audio_hw right away pbly ) // NOTE: this would overflow 31bits within about 1h20
//return ( ( Sys_Milliseconds()*441 ) / 10 ) * 4; //return ( ( Sys_Milliseconds()*441 ) / 10 ) * 4;
return idMath::FtoiFast( (float)Sys_Milliseconds() * 176.4f ); return idMath::FtoiFast( (float)Sys_Milliseconds() * 176.4f );
} }
} }
/*
===================
idSoundSystemLocal::ClearBuffer
===================
*/
void idSoundSystemLocal::ClearBuffer( void ) {
// check to make sure hardware actually exists
if ( !snd_audio_hw ) {
return;
}
short *fBlock;
ulong fBlockLen;
if ( !snd_audio_hw->Lock( (void **)&fBlock, &fBlockLen ) ) {
return;
}
if ( fBlock ) {
SIMDProcessor->Memset( fBlock, 0, fBlockLen );
snd_audio_hw->Unlock( fBlock, fBlockLen );
}
}
/* /*
=================== ===================
idSoundSystemLocal::AsyncMix idSoundSystemLocal::AsyncMix
@ -594,7 +539,7 @@ Mac OSX version. The system uses it's own thread and an IOProc callback
int idSoundSystemLocal::AsyncMix( int soundTime, float *mixBuffer ) { int idSoundSystemLocal::AsyncMix( int soundTime, float *mixBuffer ) {
int inTime, numSpeakers; int inTime, numSpeakers;
if ( !isInitialized || shutdown || !snd_audio_hw ) { if ( !isInitialized || shutdown ) {
return 0; return 0;
} }
@ -619,27 +564,16 @@ called from async sound thread when com_asyncSound == 1 ( Windows )
*/ */
int idSoundSystemLocal::AsyncUpdate( int inTime ) { int idSoundSystemLocal::AsyncUpdate( int inTime ) {
if ( !isInitialized || shutdown || !snd_audio_hw ) { if ( !isInitialized || shutdown ) {
return 0; return 0;
} }
ulong dwCurrentWritePos; ulong dwCurrentWritePos;
dword dwCurrentBlock; dword dwCurrentBlock;
// If not using openal, get actual playback position from sound hardware // here we do it in samples ( overflows in 27 hours or so )
if ( useOpenAL ) { dwCurrentWritePos = idMath::Ftol( (float)Sys_Milliseconds() * 44.1f ) % ( MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER );
// here we do it in samples ( overflows in 27 hours or so ) dwCurrentBlock = dwCurrentWritePos / MIXBUFFER_SAMPLES;
dwCurrentWritePos = idMath::Ftol( (float)Sys_Milliseconds() * 44.1f ) % ( MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER );
dwCurrentBlock = dwCurrentWritePos / MIXBUFFER_SAMPLES;
} else {
// and here in bytes
// get the current byte position in the buffer where the sound hardware is currently reading
if ( !snd_audio_hw->GetCurrentPosition( &dwCurrentWritePos ) ) {
return 0;
}
// mixBufferSize is in bytes
dwCurrentBlock = dwCurrentWritePos / snd_audio_hw->GetMixBufferSize();
}
if ( nextWriteBlock == 0xffffffff ) { if ( nextWriteBlock == 0xffffffff ) {
nextWriteBlock = dwCurrentBlock; nextWriteBlock = dwCurrentBlock;
@ -649,17 +583,6 @@ int idSoundSystemLocal::AsyncUpdate( int inTime ) {
return 0; return 0;
} }
// lock the buffer so we can actually write to it
short *fBlock = NULL;
ulong fBlockLen = 0;
if ( !useOpenAL ) {
snd_audio_hw->Lock( (void **)&fBlock, &fBlockLen );
if ( !fBlock ) {
return 0;
}
}
int j;
soundStats.runs++; soundStats.runs++;
soundStats.activeSounds = 0; soundStats.activeSounds = 0;
@ -692,37 +615,16 @@ int idSoundSystemLocal::AsyncUpdate( int inTime ) {
soundStats.missedWindow++; soundStats.missedWindow++;
} }
if ( useOpenAL ) { // enable audio hardware caching
// enable audio hardware caching alcSuspendContext( openalContext );
alcSuspendContext( openalContext );
} else {
// clear the buffer for all the mixing output
SIMDProcessor->Memset( finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers );
}
// let the active sound world mix all the channels in unless muted or avi demo recording // let the active sound world mix all the channels in unless muted or avi demo recording
if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) {
currentSoundWorld->MixLoop( newSoundTime, numSpeakers, finalMixBuffer ); currentSoundWorld->MixLoop( newSoundTime, numSpeakers, finalMixBuffer );
} }
if ( useOpenAL ) { // disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext) alcProcessContext( openalContext );
alcProcessContext( openalContext );
} else {
short *dest = fBlock + nextWriteSamples * numSpeakers;
SIMDProcessor->MixedSoundToSamples( dest, finalMixBuffer, MIXBUFFER_SAMPLES * numSpeakers );
// allow swapping the left / right speaker channels for people with miswired systems
if ( numSpeakers == 2 && s_reverse.GetBool() ) {
for( j = 0; j < MIXBUFFER_SAMPLES; j++ ) {
short temp = dest[j*2];
dest[j*2] = dest[j*2+1];
dest[j*2+1] = temp;
}
}
snd_audio_hw->Unlock( fBlock, fBlockLen );
}
CurrentSoundTime = newSoundTime; CurrentSoundTime = newSoundTime;
@ -741,14 +643,10 @@ called by the sound thread when com_asyncSound is 3 ( Linux )
*/ */
int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) { int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) {
if ( !isInitialized || shutdown || !snd_audio_hw ) { if ( !isInitialized || shutdown ) {
return 0; return 0;
} }
if ( !useOpenAL ) {
snd_audio_hw->Flush();
}
unsigned int dwCurrentBlock = (unsigned int)( inTime * 44.1f / MIXBUFFER_SAMPLES ); unsigned int dwCurrentBlock = (unsigned int)( inTime * 44.1f / MIXBUFFER_SAMPLES );
if ( nextWriteBlock == 0xffffffff ) { if ( nextWriteBlock == 0xffffffff ) {
@ -766,38 +664,16 @@ int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) {
int sampleTime = dwCurrentBlock * MIXBUFFER_SAMPLES; int sampleTime = dwCurrentBlock * MIXBUFFER_SAMPLES;
int numSpeakers = s_numberOfSpeakers.GetInteger(); int numSpeakers = s_numberOfSpeakers.GetInteger();
if ( useOpenAL ) { // enable audio hardware caching
// enable audio hardware caching alcSuspendContext( openalContext );
alcSuspendContext( openalContext );
} else {
// clear the buffer for all the mixing output
SIMDProcessor->Memset( finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers );
}
// let the active sound world mix all the channels in unless muted or avi demo recording // let the active sound world mix all the channels in unless muted or avi demo recording
if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) { if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) {
currentSoundWorld->MixLoop( sampleTime, numSpeakers, finalMixBuffer ); currentSoundWorld->MixLoop( sampleTime, numSpeakers, finalMixBuffer );
} }
if ( useOpenAL ) { // disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext) alcProcessContext( openalContext );
alcProcessContext( openalContext );
} else {
short *dest = snd_audio_hw->GetMixBuffer();
SIMDProcessor->MixedSoundToSamples( dest, finalMixBuffer, MIXBUFFER_SAMPLES * numSpeakers );
// allow swapping the left / right speaker channels for people with miswired systems
if ( numSpeakers == 2 && s_reverse.GetBool() ) {
int j;
for( j = 0; j < MIXBUFFER_SAMPLES; j++ ) {
short temp = dest[j*2];
dest[j*2] = dest[j*2+1];
dest[j*2+1] = temp;
}
}
snd_audio_hw->Write( false );
}
// only move to the next block if the write was successful // only move to the next block if the write was successful
nextWriteBlock = dwCurrentBlock + 1; nextWriteBlock = dwCurrentBlock + 1;
@ -832,7 +708,7 @@ cinData_t idSoundSystemLocal::ImageForTime( const int milliseconds, const bool w
cinData_t ret; cinData_t ret;
int i, j; int i, j;
if ( !isInitialized || !snd_audio_hw ) { if ( !isInitialized ) {
memset( &ret, 0, sizeof( ret ) ); memset( &ret, 0, sizeof( ret ) );
return ret; return ret;
} }

View file

@ -290,11 +290,6 @@ public:
// shutdown routine // shutdown routine
virtual void Shutdown( void ) = 0; virtual void Shutdown( void ) = 0;
// call ClearBuffer if there is a chance that the AsyncUpdate won't get called
// for 20+ msec, which would cause a stuttering repeat of the current
// buffer contents
virtual void ClearBuffer( void ) = 0;
// sound is attached to the window, and must be recreated when the window is changed // sound is attached to the window, and must be recreated when the window is changed
virtual bool InitHW( void ) = 0; virtual bool InitHW( void ) = 0;
virtual bool ShutdownHW( void ) = 0; virtual bool ShutdownHW( void ) = 0;