Browse Source

engine: platform: simplify sound code

Remove SNDDMA_GetSoundtime, because it was mostly copypasted from one
platform code to another.
SNDDMA_GetDMAPos gets removed too, as we have dma.samplepos for that.
pull/2/head
Alibek Omarov 4 years ago
parent
commit
a93d9ac71c
  1. 41
      engine/client/s_main.c
  2. 46
      engine/platform/android/snd_opensles.c
  3. 52
      engine/platform/linux/s_alsa.c
  4. 1
      engine/platform/platform.h
  5. 50
      engine/platform/sdl/s_sdl.c
  6. 51
      engine/platform/stub/s_stub.c

41
engine/client/s_main.c

@ -1450,6 +1450,45 @@ void S_StopAllSounds( qboolean ambient ) @@ -1450,6 +1450,45 @@ void S_StopAllSounds( qboolean ambient )
memset( &soundfade, 0, sizeof( soundfade ));
}
/*
==============
S_GetSoundtime
update global soundtime
(was part of platform code)
===============
*/
static int S_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / 2;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = dma.samplepos;
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds( true );
}
}
oldsamplepos = samplepos;
return ( buffers * fullsamples + samplepos / 2 );
}
//=============================================================================
void S_UpdateChannels( void )
{
@ -1461,7 +1500,7 @@ void S_UpdateChannels( void ) @@ -1461,7 +1500,7 @@ void S_UpdateChannels( void )
if( !dma.buffer ) return;
// updates DMA time
soundtime = SNDDMA_GetSoundtime();
soundtime = S_GetSoundtime();
// soundtime - total samples that have been played out to hardware at dmaspeed
// paintedtime - total samples that have been mixed at speed

46
engine/platform/android/snd_opensles.c

@ -35,7 +35,6 @@ static SLPlayItf snddma_android_play; @@ -35,7 +35,6 @@ static SLPlayItf snddma_android_play;
static pthread_mutex_t snddma_android_mutex = PTHREAD_MUTEX_INITIALIZER;
static int snddma_android_pos;
static int snddma_android_size;
static const SLInterfaceID *pSL_IID_ENGINE;
@ -78,7 +77,7 @@ static void SNDDMA_Android_Callback( SLBufferQueueItf bq, void *context ) @@ -78,7 +77,7 @@ static void SNDDMA_Android_Callback( SLBufferQueueItf bq, void *context )
(*bq)->Enqueue( bq, buffer2, snddma_android_size );
memcpy( buffer2, dma.buffer, snddma_android_size );
memset( dma.buffer, 0, snddma_android_size );
snddma_android_pos += dma.samples;
dma.samplepos += dma.samples;
pthread_mutex_unlock( &snddma_android_mutex );
}
@ -215,11 +214,6 @@ qboolean SNDDMA_Init( void ) @@ -215,11 +214,6 @@ qboolean SNDDMA_Init( void )
return true;
}
int SNDDMA_GetDMAPos( void )
{
return snddma_android_pos;
}
void SNDDMA_Shutdown( void )
{
Msg( "Closing OpenSL ES audio device...\n" );
@ -261,42 +255,4 @@ void SNDDMA_BeginPainting( void ) @@ -261,42 +255,4 @@ void SNDDMA_BeginPainting( void )
{
pthread_mutex_lock( &snddma_android_mutex );
}
/*
==============
SNDDMA_GetSoundtime
update global soundtime
===============
*/
int SNDDMA_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / 2;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = SNDDMA_GetDMAPos();
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds( true );
}
}
oldsamplepos = samplepos;
return (buffers * fullsamples + samplepos / 2);
}
#endif

52
engine/platform/linux/s_alsa.c

@ -198,58 +198,6 @@ qboolean SNDDMA_Init( void ) @@ -198,58 +198,6 @@ qboolean SNDDMA_Init( void )
return true;
}
/*
==============
SNDDMA_GetDMAPos
return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos( void )
{
return dma.samplepos;
}
/*
==============
SNDDMA_GetSoundtime
update global soundtime
===============
*/
int SNDDMA_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / 2;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = SNDDMA_GetDMAPos( );
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds( true );
}
}
oldsamplepos = samplepos;
return ( buffers * fullsamples + samplepos / 2 );
}
/*
==============
SNDDMA_Shutdown

1
engine/platform/platform.h

@ -144,7 +144,6 @@ void IN_EvdevFrame ( void ); @@ -144,7 +144,6 @@ void IN_EvdevFrame ( void );
*/
// initializes cycling through a DMA buffer and returns information on it
qboolean SNDDMA_Init( void );
int SNDDMA_GetSoundtime( void );
void SNDDMA_Shutdown( void );
void SNDDMA_BeginPainting( void );
void SNDDMA_Submit( void );

50
engine/platform/sdl/s_sdl.c

@ -145,56 +145,6 @@ fail: @@ -145,56 +145,6 @@ fail:
return false;
}
/*
==============
SNDDMA_GetDMAPos
return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos( void )
{
return dma.samplepos;
}
/*
==============
SNDDMA_GetSoundtime
update global soundtime
===============
*/
int SNDDMA_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / 2;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = SNDDMA_GetDMAPos( );
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds( true );
}
}
oldsamplepos = samplepos;
return ( buffers * fullsamples + samplepos / 2 );
}
/*
==============

51
engine/platform/stub/s_stub.c

@ -51,57 +51,6 @@ qboolean SNDDMA_Init( void ) @@ -51,57 +51,6 @@ qboolean SNDDMA_Init( void )
return false;
}
/*
==============
SNDDMA_GetDMAPos
return the current sample position (in mono samples read)
inside the recirculating dma buffer, so the mixing code will know
how many sample are required to fill it up.
===============
*/
int SNDDMA_GetDMAPos( void )
{
return dma.samplepos;
}
/*
==============
SNDDMA_GetSoundtime
update global soundtime
===============
*/
int SNDDMA_GetSoundtime( void )
{
static int buffers, oldsamplepos;
int samplepos, fullsamples;
fullsamples = dma.samples / 2;
// it is possible to miscount buffers
// if it has wrapped twice between
// calls to S_Update. Oh well.
samplepos = SNDDMA_GetDMAPos();
if( samplepos < oldsamplepos )
{
buffers++; // buffer wrapped
if( paintedtime > 0x40000000 )
{
// time to chop things off to avoid 32 bit limits
buffers = 0;
paintedtime = fullsamples;
S_StopAllSounds( true );
}
}
oldsamplepos = samplepos;
return (buffers * fullsamples + samplepos / 2);
}
/*
==============
SNDDMA_BeginPainting

Loading…
Cancel
Save