mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-23 12:53:09 +00:00
Don't use any idAudioHardware implementations
OpenAL for everyone.
This commit is contained in:
parent
4e26e1ac6f
commit
93e5345fbc
4 changed files with 37 additions and 170 deletions
|
@ -3058,7 +3058,6 @@ void idCommonLocal::ShutdownGame( bool reloading ) {
|
|||
if ( sw ) {
|
||||
sw->StopAllSounds();
|
||||
}
|
||||
soundSystem->ClearBuffer();
|
||||
|
||||
// shutdown the script debugger
|
||||
// DebuggerServerShutdown();
|
||||
|
|
|
@ -606,7 +606,6 @@ public:
|
|||
|
||||
void Shutdown( void );
|
||||
void Init( idRenderWorld *rw );
|
||||
void ClearBuffer( void );
|
||||
|
||||
// update
|
||||
void ForegroundUpdate( int currentTime );
|
||||
|
@ -683,7 +682,6 @@ public:
|
|||
|
||||
// shutdown routine
|
||||
virtual void Shutdown( void );
|
||||
virtual void ClearBuffer( void );
|
||||
|
||||
// sound is attached to the window, and must be recreated when the window is changed
|
||||
virtual bool ShutdownHW( void );
|
||||
|
@ -731,7 +729,6 @@ public:
|
|||
ALuint AllocOpenALSource( idSoundChannel *chan, bool looping, bool stereo );
|
||||
void FreeOpenALSource( ALuint handle );
|
||||
|
||||
idAudioHardware * snd_audio_hw;
|
||||
idSoundCache * soundCache;
|
||||
|
||||
idSoundWorldLocal * currentSoundWorld; // the one to mix each async tic
|
||||
|
|
|
@ -426,30 +426,25 @@ void idSoundSystemLocal::Shutdown() {
|
|||
// EAX or not, the list needs to be cleared
|
||||
EFXDatabase.Clear();
|
||||
|
||||
// destroy openal sources
|
||||
if ( useOpenAL ) {
|
||||
efxloaded = false;
|
||||
|
||||
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
|
||||
openalSourceCount += 8;
|
||||
for ( ALsizei i = 0; i < openalSourceCount; i++ ) {
|
||||
// stop source
|
||||
alSourceStop( openalSources[i].handle );
|
||||
alSourcei( openalSources[i].handle, AL_BUFFER, 0 );
|
||||
|
||||
for ( ALsizei i = 0; i < openalSourceCount; i++ ) {
|
||||
// stop source
|
||||
alSourceStop( openalSources[i].handle );
|
||||
alSourcei( openalSources[i].handle, AL_BUFFER, 0 );
|
||||
// delete source
|
||||
alDeleteSources( 1, &openalSources[i].handle );
|
||||
|
||||
// delete source
|
||||
alDeleteSources( 1, &openalSources[i].handle );
|
||||
|
||||
// clear entry in source array
|
||||
openalSources[i].handle = 0;
|
||||
openalSources[i].startTime = 0;
|
||||
openalSources[i].chan = NULL;
|
||||
openalSources[i].inUse = false;
|
||||
openalSources[i].looping = false;
|
||||
|
||||
}
|
||||
// clear entry in source array
|
||||
openalSources[i].handle = 0;
|
||||
openalSources[i].startTime = 0;
|
||||
openalSources[i].chan = NULL;
|
||||
openalSources[i].inUse = false;
|
||||
openalSources[i].looping = false;
|
||||
}
|
||||
|
||||
// destroy all the sounds (hardware buffers as well)
|
||||
|
@ -457,15 +452,13 @@ void idSoundSystemLocal::Shutdown() {
|
|||
soundCache = NULL;
|
||||
|
||||
// destroy openal device and context
|
||||
if ( useOpenAL ) {
|
||||
alcMakeContextCurrent( NULL );
|
||||
alcMakeContextCurrent( NULL );
|
||||
|
||||
alcDestroyContext( openalContext );
|
||||
openalContext = NULL;
|
||||
alcDestroyContext( openalContext );
|
||||
openalContext = NULL;
|
||||
|
||||
alcCloseDevice( openalDevice );
|
||||
openalDevice = NULL;
|
||||
}
|
||||
alcCloseDevice( openalDevice );
|
||||
openalDevice = NULL;
|
||||
|
||||
idSampleDecoder::Shutdown();
|
||||
}
|
||||
|
@ -488,26 +481,6 @@ bool idSoundSystemLocal::InitHW() {
|
|||
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
|
||||
s_numberOfSpeakers.SetInteger(numSpeakers);
|
||||
|
||||
|
@ -532,9 +505,6 @@ bool idSoundSystemLocal::ShutdownHW() {
|
|||
|
||||
common->Printf( "Shutting down sound hardware\n" );
|
||||
|
||||
delete snd_audio_hw;
|
||||
snd_audio_hw = NULL;
|
||||
|
||||
isInitialized = false;
|
||||
|
||||
if ( graph ) {
|
||||
|
@ -551,40 +521,15 @@ idSoundSystemLocal::GetCurrent44kHzTime
|
|||
===============
|
||||
*/
|
||||
int idSoundSystemLocal::GetCurrent44kHzTime( void ) const {
|
||||
if ( snd_audio_hw ) {
|
||||
if ( isInitialized ) {
|
||||
return CurrentSoundTime;
|
||||
} 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 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
|
||||
|
@ -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 inTime, numSpeakers;
|
||||
|
||||
if ( !isInitialized || shutdown || !snd_audio_hw ) {
|
||||
if ( !isInitialized || shutdown ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -619,27 +564,16 @@ called from async sound thread when com_asyncSound == 1 ( Windows )
|
|||
*/
|
||||
int idSoundSystemLocal::AsyncUpdate( int inTime ) {
|
||||
|
||||
if ( !isInitialized || shutdown || !snd_audio_hw ) {
|
||||
if ( !isInitialized || shutdown ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ulong dwCurrentWritePos;
|
||||
dword dwCurrentBlock;
|
||||
|
||||
// If not using openal, get actual playback position from sound hardware
|
||||
if ( useOpenAL ) {
|
||||
// here we do it in samples ( overflows in 27 hours or so )
|
||||
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();
|
||||
}
|
||||
// here we do it in samples ( overflows in 27 hours or so )
|
||||
dwCurrentWritePos = idMath::Ftol( (float)Sys_Milliseconds() * 44.1f ) % ( MIXBUFFER_SAMPLES * ROOM_SLICES_IN_BUFFER );
|
||||
dwCurrentBlock = dwCurrentWritePos / MIXBUFFER_SAMPLES;
|
||||
|
||||
if ( nextWriteBlock == 0xffffffff ) {
|
||||
nextWriteBlock = dwCurrentBlock;
|
||||
|
@ -649,17 +583,6 @@ int idSoundSystemLocal::AsyncUpdate( int inTime ) {
|
|||
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.activeSounds = 0;
|
||||
|
||||
|
@ -692,37 +615,16 @@ int idSoundSystemLocal::AsyncUpdate( int inTime ) {
|
|||
soundStats.missedWindow++;
|
||||
}
|
||||
|
||||
if ( useOpenAL ) {
|
||||
// enable audio hardware caching
|
||||
alcSuspendContext( openalContext );
|
||||
} else {
|
||||
// clear the buffer for all the mixing output
|
||||
SIMDProcessor->Memset( finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers );
|
||||
}
|
||||
// enable audio hardware caching
|
||||
alcSuspendContext( openalContext );
|
||||
|
||||
// let the active sound world mix all the channels in unless muted or avi demo recording
|
||||
if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) {
|
||||
currentSoundWorld->MixLoop( newSoundTime, numSpeakers, finalMixBuffer );
|
||||
}
|
||||
|
||||
if ( useOpenAL ) {
|
||||
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
|
||||
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 );
|
||||
}
|
||||
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
|
||||
alcProcessContext( openalContext );
|
||||
|
||||
CurrentSoundTime = newSoundTime;
|
||||
|
||||
|
@ -741,14 +643,10 @@ called by the sound thread when com_asyncSound is 3 ( Linux )
|
|||
*/
|
||||
int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) {
|
||||
|
||||
if ( !isInitialized || shutdown || !snd_audio_hw ) {
|
||||
if ( !isInitialized || shutdown ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( !useOpenAL ) {
|
||||
snd_audio_hw->Flush();
|
||||
}
|
||||
|
||||
unsigned int dwCurrentBlock = (unsigned int)( inTime * 44.1f / MIXBUFFER_SAMPLES );
|
||||
|
||||
if ( nextWriteBlock == 0xffffffff ) {
|
||||
|
@ -766,38 +664,16 @@ int idSoundSystemLocal::AsyncUpdateWrite( int inTime ) {
|
|||
int sampleTime = dwCurrentBlock * MIXBUFFER_SAMPLES;
|
||||
int numSpeakers = s_numberOfSpeakers.GetInteger();
|
||||
|
||||
if ( useOpenAL ) {
|
||||
// enable audio hardware caching
|
||||
alcSuspendContext( openalContext );
|
||||
} else {
|
||||
// clear the buffer for all the mixing output
|
||||
SIMDProcessor->Memset( finalMixBuffer, 0, MIXBUFFER_SAMPLES * sizeof(float) * numSpeakers );
|
||||
}
|
||||
// enable audio hardware caching
|
||||
alcSuspendContext( openalContext );
|
||||
|
||||
// let the active sound world mix all the channels in unless muted or avi demo recording
|
||||
if ( !muted && currentSoundWorld && !currentSoundWorld->fpa[0] ) {
|
||||
currentSoundWorld->MixLoop( sampleTime, numSpeakers, finalMixBuffer );
|
||||
}
|
||||
|
||||
if ( useOpenAL ) {
|
||||
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
|
||||
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 );
|
||||
}
|
||||
// disable audio hardware caching (this updates ALL settings since last alcSuspendContext)
|
||||
alcProcessContext( openalContext );
|
||||
|
||||
// only move to the next block if the write was successful
|
||||
nextWriteBlock = dwCurrentBlock + 1;
|
||||
|
@ -832,7 +708,7 @@ cinData_t idSoundSystemLocal::ImageForTime( const int milliseconds, const bool w
|
|||
cinData_t ret;
|
||||
int i, j;
|
||||
|
||||
if ( !isInitialized || !snd_audio_hw ) {
|
||||
if ( !isInitialized ) {
|
||||
memset( &ret, 0, sizeof( ret ) );
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -290,11 +290,6 @@ public:
|
|||
// shutdown routine
|
||||
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
|
||||
virtual bool InitHW( void ) = 0;
|
||||
virtual bool ShutdownHW( void ) = 0;
|
||||
|
|
Loading…
Reference in a new issue