mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-15 13:41:33 +01:00
engine: soundlib: make Sound_GetApproxWavePlayLen behave like in GoldSrc
This commit is contained in:
parent
3e7dd30fd7
commit
fe2c4af8c2
@ -98,11 +98,11 @@ uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath )
|
||||
file_t *f;
|
||||
wavehdr_t wav;
|
||||
size_t filesize;
|
||||
float seconds;
|
||||
uint samples;
|
||||
uint msecs;
|
||||
|
||||
f = FS_Open( filepath, "rb", false );
|
||||
if( !f ) return 0;
|
||||
if( !f )
|
||||
return 0;
|
||||
|
||||
if( FS_Read( f, &wav, sizeof( wav )) != sizeof( wav ))
|
||||
{
|
||||
@ -111,7 +111,7 @@ uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath )
|
||||
}
|
||||
|
||||
filesize = FS_FileLength( f );
|
||||
filesize -= ( sizeof( wavehdr_t ) + sizeof( chunkhdr_t ));
|
||||
filesize -= 128; // magic number from GoldSrc, seems to be header size
|
||||
|
||||
FS_Close( f );
|
||||
|
||||
@ -119,21 +119,11 @@ uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath )
|
||||
if( wav.riff_id != RIFFHEADER || wav.wave_id != WAVEHEADER || wav.fmt_id != FORMHEADER )
|
||||
return 0;
|
||||
|
||||
if( wav.wFormatTag != 1 )
|
||||
return 0;
|
||||
if( wav.nAvgBytesPerSec >= 1000 )
|
||||
msecs = (uint)((float)filesize / ((float)wav.nAvgBytesPerSec / 1000.0f));
|
||||
else msecs = (uint)(((float)filesize / (float)wav.nAvgBytesPerSec) * 1000.0f);
|
||||
|
||||
if( wav.nChannels != 1 && wav.nChannels != 2 )
|
||||
return 0;
|
||||
|
||||
if( wav.nBitsPerSample != 8 && wav.nBitsPerSample != 16 )
|
||||
return 0;
|
||||
|
||||
// calc samplecount
|
||||
seconds = (float)filesize / wav.nAvgBytesPerSec / wav.nChannels;
|
||||
samples = (uint)(( wav.nSamplesPerSec * wav.nChannels ) * seconds );
|
||||
|
||||
// g-cont. this function returns samplecount or time in milliseconds ???
|
||||
return (uint)(seconds * 1000);
|
||||
return msecs;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user