Browse Source

engine: soundlib: make Sound_GetApproxWavePlayLen behave like in GoldSrc

pull/2/head
Alibek Omarov 4 years ago
parent
commit
fe2c4af8c2
  1. 32
      engine/common/soundlib/snd_utils.c

32
engine/common/soundlib/snd_utils.c

@ -95,14 +95,14 @@ byte *Sound_Copy( size_t size ) @@ -95,14 +95,14 @@ byte *Sound_Copy( size_t size )
uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath )
{
file_t *f;
wavehdr_t wav;
size_t filesize;
float seconds;
uint samples;
file_t *f;
wavehdr_t wav;
size_t filesize;
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 ) @@ -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 ) @@ -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.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 );
if( wav.nAvgBytesPerSec >= 1000 )
msecs = (uint)((float)filesize / ((float)wav.nAvgBytesPerSec / 1000.0f));
else msecs = (uint)(((float)filesize / (float)wav.nAvgBytesPerSec) * 1000.0f);
// g-cont. this function returns samplecount or time in milliseconds ???
return (uint)(seconds * 1000);
return msecs;
}
/*

Loading…
Cancel
Save