|
|
@ -98,11 +98,11 @@ uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath ) |
|
|
|
file_t *f; |
|
|
|
file_t *f; |
|
|
|
wavehdr_t wav; |
|
|
|
wavehdr_t wav; |
|
|
|
size_t filesize; |
|
|
|
size_t filesize; |
|
|
|
float seconds; |
|
|
|
uint msecs; |
|
|
|
uint samples; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f = FS_Open( filepath, "rb", false ); |
|
|
|
f = FS_Open( filepath, "rb", false ); |
|
|
|
if( !f ) return 0; |
|
|
|
if( !f ) |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
if( FS_Read( f, &wav, sizeof( wav )) != sizeof( wav )) |
|
|
|
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 = FS_FileLength( f ); |
|
|
|
filesize -= ( sizeof( wavehdr_t ) + sizeof( chunkhdr_t )); |
|
|
|
filesize -= 128; // magic number from GoldSrc, seems to be header size
|
|
|
|
|
|
|
|
|
|
|
|
FS_Close( f ); |
|
|
|
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 ) |
|
|
|
if( wav.riff_id != RIFFHEADER || wav.wave_id != WAVEHEADER || wav.fmt_id != FORMHEADER ) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
if( wav.wFormatTag != 1 ) |
|
|
|
if( wav.nAvgBytesPerSec >= 1000 ) |
|
|
|
return 0; |
|
|
|
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 msecs; |
|
|
|
return (uint)(seconds * 1000); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|