diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/cl_cgame.c | 2 | ||||
-rw-r--r-- | src/client/snd_dma.c | 16 | ||||
-rw-r--r-- | src/client/snd_local.h | 2 | ||||
-rw-r--r-- | src/client/snd_main.c | 14 | ||||
-rw-r--r-- | src/client/snd_mem.c | 6 | ||||
-rw-r--r-- | src/client/snd_openal.c | 23 | ||||
-rw-r--r-- | src/client/snd_public.h | 2 |
7 files changed, 64 insertions, 1 deletions
diff --git a/src/client/cl_cgame.c b/src/client/cl_cgame.c index 0a40e6dd..2e28d049 100644 --- a/src/client/cl_cgame.c +++ b/src/client/cl_cgame.c @@ -542,6 +542,8 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) { return 0; case CG_S_REGISTERSOUND: return S_RegisterSound( VMA(1), args[2] ); + case CG_S_SOUNDDURATION: + return S_SoundDuration( args[1] ); case CG_S_STARTBACKGROUNDTRACK: S_StartBackgroundTrack( VMA(1), VMA(2) ); return 0; diff --git a/src/client/snd_dma.c b/src/client/snd_dma.c index 93d9a316..749be017 100644 --- a/src/client/snd_dma.c +++ b/src/client/snd_dma.c @@ -350,6 +350,21 @@ sfxHandle_t S_Base_RegisterSound( const char *name, qboolean compressed ) { } /* +================== +S_Base_SoundDuration +================== +*/ +static int S_Base_SoundDuration( sfxHandle_t handle ) { + if ( handle < 0 || handle >= s_numSfx ) { + Com_Printf( S_COLOR_YELLOW "S_Base_SoundDuration: handle %i out of range\n", handle ); + return 0; + } + return s_knownSfx[ handle ].duration; +} + + + +/* ===================== S_BeginRegistration @@ -1489,6 +1504,7 @@ qboolean S_Base_Init( soundInterface_t *si ) { si->DisableSounds = S_Base_DisableSounds; si->BeginRegistration = S_Base_BeginRegistration; si->RegisterSound = S_Base_RegisterSound; + si->SoundDuration = S_Base_SoundDuration; si->ClearSoundBuffer = S_Base_ClearSoundBuffer; si->SoundInfo = S_Base_SoundInfo; si->SoundList = S_Base_SoundList; diff --git a/src/client/snd_local.h b/src/client/snd_local.h index 45a5779e..4f028a3d 100644 --- a/src/client/snd_local.h +++ b/src/client/snd_local.h @@ -59,6 +59,7 @@ typedef struct sfx_s { int soundLength; char soundName[MAX_QPATH]; int lastTimeUsed; + int duration; struct sfx_s *next; } sfx_t; @@ -138,6 +139,7 @@ typedef struct void (*DisableSounds)( void ); void (*BeginRegistration)( void ); sfxHandle_t (*RegisterSound)( const char *sample, qboolean compressed ); + int (*SoundDuration)( sfxHandle_t handle ); void (*ClearSoundBuffer)( void ); void (*SoundInfo)( void ); void (*SoundList)( void ); diff --git a/src/client/snd_main.c b/src/client/snd_main.c index ebb0e9da..b8dfdf36 100644 --- a/src/client/snd_main.c +++ b/src/client/snd_main.c @@ -59,6 +59,7 @@ static qboolean S_ValidSoundInterface( soundInterface_t *si ) if( !si->DisableSounds ) return qfalse; if( !si->BeginRegistration ) return qfalse; if( !si->RegisterSound ) return qfalse; + if( !si->SoundDuration ) return qfalse; if( !si->ClearSoundBuffer ) return qfalse; if( !si->SoundInfo ) return qfalse; if( !si->SoundList ) return qfalse; @@ -271,6 +272,19 @@ sfxHandle_t S_RegisterSound( const char *sample, qboolean compressed ) /* ================= +S_SoundDuration +================= +*/ +int S_SoundDuration( sfxHandle_t handle ) +{ + if( si.SoundDuration ) + return si.SoundDuration( handle ); + else + return 0; +} + +/* +================= S_ClearSoundBuffer ================= */ diff --git a/src/client/snd_mem.c b/src/client/snd_mem.c index decab20d..f10510b7 100644 --- a/src/client/snd_mem.c +++ b/src/client/snd_mem.c @@ -201,7 +201,7 @@ qboolean S_LoadSound( sfx_t *sfx ) byte *data; short *samples; snd_info_t info; -// int size; + int size_per_sec; // player specific sounds are never directly loaded if ( sfx->soundName[0] == '*') { @@ -213,6 +213,10 @@ qboolean S_LoadSound( sfx_t *sfx ) if(!data) return qfalse; + size_per_sec = info.rate * info.channels * info.width; + if( size_per_sec > 0 ) + sfx->duration = (int)(1000.0f * ((double)info.size / size_per_sec)); + if ( info.width == 1 ) { Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName); } diff --git a/src/client/snd_openal.c b/src/client/snd_openal.c index 0bda7a1a..fee1d22e 100644 --- a/src/client/snd_openal.c +++ b/src/client/snd_openal.c @@ -111,6 +111,7 @@ typedef struct alSfx_s qboolean inMemory; // Sound is stored in memory qboolean isLocked; // Sound is locked (can not be unloaded) int lastUsedTime; // Time last used + int duration; // Milliseconds } alSfx_t; static qboolean alBuffersInitialised = qfalse; @@ -273,6 +274,7 @@ static void S_AL_BufferLoad(sfxHandle_t sfx) void *data; snd_info_t info; ALuint format; + int size_per_sec; // Nothing? if(knownSfx[sfx].filename[0] == '\0') @@ -294,6 +296,10 @@ static void S_AL_BufferLoad(sfxHandle_t sfx) return; } + size_per_sec = info.rate * info.channels * info.width; + if( size_per_sec > 0 ) + knownSfx[sfx].duration = (int)(1000.0f * ((double)info.size / size_per_sec)); + format = S_AL_Format(info.width, info.channels); // Create a buffer @@ -440,6 +446,22 @@ sfxHandle_t S_AL_RegisterSound( const char *sample, qboolean compressed ) /* ================= +S_AL_SoundDuration +================= +*/ +static +int S_AL_SoundDuration( sfxHandle_t sfx ) +{ + if (sfx < 0 || sfx >= numSfx) + { + Com_Printf(S_COLOR_RED "ERROR: S_AL_SoundDuration: handle %i out of range\n", sfx); + return 0; + } + return knownSfx[sfx].duration; +} + +/* +================= S_AL_BufferGet Return's an sfx's buffer @@ -1983,6 +2005,7 @@ qboolean S_AL_Init( soundInterface_t *si ) si->DisableSounds = S_AL_DisableSounds; si->BeginRegistration = S_AL_BeginRegistration; si->RegisterSound = S_AL_RegisterSound; + si->SoundDuration = S_AL_SoundDuration; si->ClearSoundBuffer = S_AL_ClearSoundBuffer; si->SoundInfo = S_AL_SoundInfo; si->SoundList = S_AL_SoundList; diff --git a/src/client/snd_public.h b/src/client/snd_public.h index c85f414a..d737412b 100644 --- a/src/client/snd_public.h +++ b/src/client/snd_public.h @@ -64,6 +64,8 @@ void S_BeginRegistration( void ); // checks for missing files sfxHandle_t S_RegisterSound( const char *sample, qboolean compressed ); +int S_SoundDuration( sfxHandle_t handle ); + void S_DisplayFreeMemory(void); void S_ClearSoundBuffer( void ); |