engine: clean up unused soundlib flags, set SOUND_LOOPED flag on looped sounds
This commit is contained in:
parent
e18e9ae2ea
commit
433e7de686
10 changed files with 31 additions and 35 deletions
|
@ -52,8 +52,11 @@ void S_SoundList_f( void )
|
||||||
{
|
{
|
||||||
totalSize += sc->size;
|
totalSize += sc->size;
|
||||||
|
|
||||||
if( sc->loopStart >= 0 ) Con_Printf( "L" );
|
if( FBitSet( sc->flags, SOUND_LOOPED ))
|
||||||
else Con_Printf( " " );
|
Con_Printf( "L" );
|
||||||
|
else
|
||||||
|
Con_Printf( " " );
|
||||||
|
|
||||||
if( sfx->name[0] == '*' || !Q_strncmp( sfx->name, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ))
|
if( sfx->name[0] == '*' || !Q_strncmp( sfx->name, DEFAULT_SOUNDPATH, sizeof( DEFAULT_SOUNDPATH ) - 1 ))
|
||||||
Con_Printf( " (%2db) %s : %s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
|
Con_Printf( " (%2db) %s : %s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
|
||||||
else Con_Printf( " (%2db) %s : " DEFAULT_SOUNDPATH "%s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
|
else Con_Printf( " (%2db) %s : " DEFAULT_SOUNDPATH "%s\n", sc->width * 8, Q_memprint( sc->size ), sfx->name );
|
||||||
|
@ -110,7 +113,7 @@ static wavdata_t *S_CreateDefaultSound( void )
|
||||||
|
|
||||||
sc->width = 2;
|
sc->width = 2;
|
||||||
sc->channels = 1;
|
sc->channels = 1;
|
||||||
sc->loopStart = -1;
|
sc->loopStart = 0;
|
||||||
sc->rate = SOUND_DMA_SPEED;
|
sc->rate = SOUND_DMA_SPEED;
|
||||||
sc->samples = SOUND_DMA_SPEED;
|
sc->samples = SOUND_DMA_SPEED;
|
||||||
sc->size = sc->samples * sc->width * sc->channels;
|
sc->size = sc->samples * sc->width * sc->channels;
|
||||||
|
|
|
@ -328,7 +328,7 @@ channel_t *SND_PickDynamicChannel( int entnum, int channel, sfx_t *sfx, qboolean
|
||||||
// don't restart looping sounds for the same entity
|
// don't restart looping sounds for the same entity
|
||||||
wavdata_t *sc = channels[first_to_die].sfx->cache;
|
wavdata_t *sc = channels[first_to_die].sfx->cache;
|
||||||
|
|
||||||
if( sc && sc->loopStart != -1 )
|
if( sc && FBitSet( sc->flags, SOUND_LOOPED ))
|
||||||
{
|
{
|
||||||
channel_t *ch = &channels[first_to_die];
|
channel_t *ch = &channels[first_to_die];
|
||||||
|
|
||||||
|
@ -503,7 +503,7 @@ static void SND_Spatialize( channel_t *ch )
|
||||||
|
|
||||||
pSource = ch->sfx->cache;
|
pSource = ch->sfx->cache;
|
||||||
|
|
||||||
if( ch->use_loop && pSource && pSource->loopStart != -1 )
|
if( ch->use_loop && pSource && FBitSet( pSource->flags, SOUND_LOOPED ))
|
||||||
looping = true;
|
looping = true;
|
||||||
|
|
||||||
if( !ch->staticsound )
|
if( !ch->staticsound )
|
||||||
|
@ -641,7 +641,7 @@ void S_StartSound( const vec3_t pos, int ent, int chan, sound_t handle, float fv
|
||||||
if( !target_chan->leftvol && !target_chan->rightvol )
|
if( !target_chan->leftvol && !target_chan->rightvol )
|
||||||
{
|
{
|
||||||
// looping sounds don't use this optimization because they should stick around until they're killed.
|
// looping sounds don't use this optimization because they should stick around until they're killed.
|
||||||
if( !sfx->cache || sfx->cache->loopStart == -1 )
|
if( !sfx->cache || !FBitSet( sfx->cache->flags, SOUND_LOOPED ))
|
||||||
{
|
{
|
||||||
// if this is a streaming sound, play the whole thing.
|
// if this is a streaming sound, play the whole thing.
|
||||||
if( chan != CHAN_STREAM )
|
if( chan != CHAN_STREAM )
|
||||||
|
@ -893,7 +893,7 @@ int S_GetCurrentStaticSounds( soundlist_t *pout, int size )
|
||||||
VectorCopy( channels[i].origin, pout->origin );
|
VectorCopy( channels[i].origin, pout->origin );
|
||||||
pout->volume = (float)channels[i].master_vol / 255.0f;
|
pout->volume = (float)channels[i].master_vol / 255.0f;
|
||||||
pout->attenuation = channels[i].dist_mult * SND_CLIP_DISTANCE;
|
pout->attenuation = channels[i].dist_mult * SND_CLIP_DISTANCE;
|
||||||
pout->looping = ( channels[i].use_loop && channels[i].sfx->cache->loopStart != -1 );
|
pout->looping = ( channels[i].use_loop && FBitSet( channels[i].sfx->cache->flags, SOUND_LOOPED ));
|
||||||
pout->pitch = channels[i].basePitch;
|
pout->pitch = channels[i].basePitch;
|
||||||
pout->channel = channels[i].entchannel;
|
pout->channel = channels[i].entchannel;
|
||||||
pout->wordIndex = channels[i].wordIndex;
|
pout->wordIndex = channels[i].wordIndex;
|
||||||
|
@ -928,7 +928,7 @@ int S_GetCurrentDynamicSounds( soundlist_t *pout, int size )
|
||||||
if( !channels[i].sfx || !channels[i].sfx->name[0] || !Q_stricmp( channels[i].sfx->name, "*default" ))
|
if( !channels[i].sfx || !channels[i].sfx->name[0] || !Q_stricmp( channels[i].sfx->name, "*default" ))
|
||||||
continue; // don't serialize default sounds
|
continue; // don't serialize default sounds
|
||||||
|
|
||||||
looped = ( channels[i].use_loop && channels[i].sfx->cache->loopStart != -1 );
|
looped = ( channels[i].use_loop && FBitSet( channels[i].sfx->cache->flags, SOUND_LOOPED ));
|
||||||
|
|
||||||
if( channels[i].entchannel == CHAN_STATIC && looped && !Host_IsQuakeCompatible())
|
if( channels[i].entchannel == CHAN_STATIC && looped && !Host_IsQuakeCompatible())
|
||||||
continue; // never serialize static looped sounds. It will be restoring in game code
|
continue; // never serialize static looped sounds. It will be restoring in game code
|
||||||
|
|
|
@ -576,7 +576,7 @@ static void MIX_MixChannelsToPaintbuffer( int endtime, int rate, int outputRate
|
||||||
bZeroVolume = true;
|
bZeroVolume = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !pSource || ( bZeroVolume && pSource->loopStart == -1 ))
|
if( !pSource || ( bZeroVolume && !FBitSet( pSource->flags, SOUND_LOOPED )))
|
||||||
{
|
{
|
||||||
if( !pSource )
|
if( !pSource )
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,7 @@ int S_ConvertLoopedPosition( wavdata_t *pSource, int samplePosition, qboolean us
|
||||||
// convert to a position within the loop
|
// convert to a position within the loop
|
||||||
// At the end of the loop, we return a short buffer, and subsequent call
|
// At the end of the loop, we return a short buffer, and subsequent call
|
||||||
// will loop back and get the rest of the buffer
|
// will loop back and get the rest of the buffer
|
||||||
if( pSource->loopStart >= 0 && samplePosition >= pSource->samples && use_loop )
|
if( FBitSet( pSource->flags, SOUND_LOOPED ) && samplePosition >= pSource->samples && use_loop )
|
||||||
{
|
{
|
||||||
// size of loop
|
// size of loop
|
||||||
int loopSize = pSource->samples - pSource->loopStart;
|
int loopSize = pSource->samples - pSource->loopStart;
|
||||||
|
|
|
@ -479,14 +479,6 @@ typedef enum
|
||||||
WF_TOTALCOUNT, // must be last
|
WF_TOTALCOUNT, // must be last
|
||||||
} sndformat_t;
|
} sndformat_t;
|
||||||
|
|
||||||
// soundlib global settings
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
SL_USE_LERPING = BIT(0), // lerping sounds during resample
|
|
||||||
SL_KEEP_8BIT = BIT(1), // don't expand 8bit sounds automatically up to 16 bit
|
|
||||||
SL_ALLOW_OVERWRITE = BIT(2), // allow to overwrite stored sounds
|
|
||||||
} slFlags_t;
|
|
||||||
|
|
||||||
// wavdata output flags
|
// wavdata output flags
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
@ -495,8 +487,7 @@ typedef enum
|
||||||
SOUND_STREAM = BIT( 1 ), // this is a streaminfo, not a real sound
|
SOUND_STREAM = BIT( 1 ), // this is a streaminfo, not a real sound
|
||||||
|
|
||||||
// Sound_Process manipulation flags
|
// Sound_Process manipulation flags
|
||||||
SOUND_RESAMPLE = BIT(12), // resample sound to specified rate
|
SOUND_RESAMPLE = BIT( 12 ), // resample sound to specified rate
|
||||||
SOUND_CONVERT16BIT = BIT(13), // change sound resolution from 8 bit to 16
|
|
||||||
} sndFlags_t;
|
} sndFlags_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -504,8 +495,8 @@ typedef struct
|
||||||
word rate; // num samples per second (e.g. 11025 - 11 khz)
|
word rate; // num samples per second (e.g. 11025 - 11 khz)
|
||||||
byte width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
|
byte width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
|
||||||
byte channels; // num channels (1 - mono, 2 - stereo)
|
byte channels; // num channels (1 - mono, 2 - stereo)
|
||||||
int loopStart; // offset at this point sound will be looping while playing more than only once
|
uint loopStart; // offset at this point sound will be looping while playing more than only once
|
||||||
int samples; // total samplecount in wav
|
uint samples; // total samplecount in wav
|
||||||
uint type; // compression type
|
uint type; // compression type
|
||||||
uint flags; // misc sound flags
|
uint flags; // misc sound flags
|
||||||
byte *buffer; // sound buffer
|
byte *buffer; // sound buffer
|
||||||
|
|
|
@ -216,7 +216,7 @@ wavdata_t *FS_StreamInfo( stream_t *stream )
|
||||||
if( !stream ) return NULL;
|
if( !stream ) return NULL;
|
||||||
|
|
||||||
// fill structure
|
// fill structure
|
||||||
info.loopStart = -1;
|
info.loopStart = 0;
|
||||||
info.rate = stream->rate;
|
info.rate = stream->rate;
|
||||||
info.width = stream->width;
|
info.width = stream->width;
|
||||||
info.channels = stream->channels;
|
info.channels = stream->channels;
|
||||||
|
|
|
@ -74,7 +74,10 @@ static uint32_t Sound_ParseSynchInteger( uint32_t v )
|
||||||
static void Sound_HandleCustomID3Comment( const char *key, const char *value )
|
static void Sound_HandleCustomID3Comment( const char *key, const char *value )
|
||||||
{
|
{
|
||||||
if( !Q_strcmp( key, "LOOP_START" ) || !Q_strcmp( key, "LOOPSTART" ))
|
if( !Q_strcmp( key, "LOOP_START" ) || !Q_strcmp( key, "LOOPSTART" ))
|
||||||
|
{
|
||||||
sound.loopstart = Q_atoi( value );
|
sound.loopstart = Q_atoi( value );
|
||||||
|
SetBits( sound.flags, SOUND_LOOPED );
|
||||||
|
}
|
||||||
// unknown comment is not an error
|
// unknown comment is not an error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +236,6 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, fs_offset_t filesi
|
||||||
sound.channels = sc.channels;
|
sound.channels = sc.channels;
|
||||||
sound.rate = sc.rate;
|
sound.rate = sc.rate;
|
||||||
sound.width = 2; // always 16-bit PCM
|
sound.width = 2; // always 16-bit PCM
|
||||||
sound.loopstart = -1;
|
|
||||||
sound.size = ( sound.channels * sound.rate * sound.width ) * ( sc.playtime / 1000 ); // in bytes
|
sound.size = ( sound.channels * sound.rate * sound.width ) * ( sc.playtime / 1000 ); // in bytes
|
||||||
padsize = sound.size % FRAME_SIZE;
|
padsize = sound.size % FRAME_SIZE;
|
||||||
pos += FRAME_SIZE; // evaluate pos
|
pos += FRAME_SIZE; // evaluate pos
|
||||||
|
@ -241,7 +243,6 @@ qboolean Sound_LoadMPG( const char *name, const byte *buffer, fs_offset_t filesi
|
||||||
if( !Sound_ParseID3Tag( buffer, filesize ))
|
if( !Sound_ParseID3Tag( buffer, filesize ))
|
||||||
{
|
{
|
||||||
Con_DPrintf( S_WARN "Sound_LoadMPG: (%s) failed to extract LOOP_START tag\n", name );
|
Con_DPrintf( S_WARN "Sound_LoadMPG: (%s) failed to extract LOOP_START tag\n", name );
|
||||||
sound.loopstart = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !sound.size )
|
if( !sound.size )
|
||||||
|
|
|
@ -154,7 +154,7 @@ static qboolean Sound_ResampleInternal( wavdata_t *sc, int inrate, int inwidth,
|
||||||
sound.tempbuffer = (byte *)Mem_Realloc( host.soundpool, sound.tempbuffer, sc->size );
|
sound.tempbuffer = (byte *)Mem_Realloc( host.soundpool, sound.tempbuffer, sc->size );
|
||||||
|
|
||||||
sc->samples = outcount;
|
sc->samples = outcount;
|
||||||
if( sc->loopStart != -1 )
|
if( FBitSet( sc->flags, SOUND_LOOPED ))
|
||||||
sc->loopStart = sc->loopStart / stepscale;
|
sc->loopStart = sc->loopStart / stepscale;
|
||||||
|
|
||||||
if( inrate == outrate )
|
if( inrate == outrate )
|
||||||
|
|
|
@ -245,6 +245,7 @@ qboolean Sound_LoadWAV( const char *name, const byte *buffer, fs_offset_t filesi
|
||||||
{
|
{
|
||||||
iff_dataPtr += 32;
|
iff_dataPtr += 32;
|
||||||
sound.loopstart = GetLittleLong();
|
sound.loopstart = GetLittleLong();
|
||||||
|
SetBits( sound.flags, SOUND_LOOPED );
|
||||||
FindNextChunk( name, "LIST" ); // if the next chunk is a LIST chunk, look for a cue length marker
|
FindNextChunk( name, "LIST" ); // if the next chunk is a LIST chunk, look for a cue length marker
|
||||||
|
|
||||||
if( iff_dataPtr )
|
if( iff_dataPtr )
|
||||||
|
@ -259,7 +260,7 @@ qboolean Sound_LoadWAV( const char *name, const byte *buffer, fs_offset_t filesi
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sound.loopstart = -1;
|
sound.loopstart = 0;
|
||||||
sound.samples = 0;
|
sound.samples = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ typedef struct sndlib_s
|
||||||
int rate; // num samples per second (e.g. 11025 - 11 khz)
|
int rate; // num samples per second (e.g. 11025 - 11 khz)
|
||||||
int width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
|
int width; // resolution - bum bits divided by 8 (8 bit is 1, 16 bit is 2)
|
||||||
int channels; // num channels (1 - mono, 2 - stereo)
|
int channels; // num channels (1 - mono, 2 - stereo)
|
||||||
int loopstart; // start looping from
|
uint loopstart; // start looping from
|
||||||
uint samples; // total samplecount in sound
|
uint samples; // total samplecount in sound
|
||||||
uint flags; // additional sound flags
|
uint flags; // additional sound flags
|
||||||
size_t size; // sound unpacked size (for bounds checking)
|
size_t size; // sound unpacked size (for bounds checking)
|
||||||
|
|
Loading…
Add table
Reference in a new issue