mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
engine: soundlib: fixes for BE
This commit is contained in:
@@ -152,6 +152,8 @@ static qboolean StreamFindNextChunk( file_t *file, const char *name, int *last_c
|
||||
if( FS_Read( file, &iff_chunk_len, sizeof( iff_chunk_len )) != sizeof( iff_chunk_len ))
|
||||
return false;
|
||||
|
||||
iff_chunk_len = LittleLong( iff_chunk_len );
|
||||
|
||||
if( iff_chunk_len < 0 )
|
||||
return false; // didn't find the chunk
|
||||
|
||||
@@ -394,6 +396,7 @@ stream_t *Stream_OpenWAV( const char *filename )
|
||||
FS_Read( file, chunkName, 4 );
|
||||
|
||||
FS_Read( file, &t, sizeof( t ));
|
||||
t = LittleShort( t );
|
||||
if( t != 1 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: %s not a microsoft PCM format\n", __func__, filename );
|
||||
@@ -402,14 +405,15 @@ stream_t *Stream_OpenWAV( const char *filename )
|
||||
}
|
||||
|
||||
FS_Read( file, &t, sizeof( t ));
|
||||
sound.channels = t;
|
||||
sound.channels = LittleShort( t );
|
||||
|
||||
FS_Read( file, &sound.rate, sizeof( int ));
|
||||
sound.rate = LittleLong( sound.rate );
|
||||
|
||||
FS_Seek( file, 6, SEEK_CUR );
|
||||
|
||||
FS_Read( file, &t, sizeof( t ));
|
||||
sound.width = t / 8;
|
||||
sound.width = LittleShort( t ) / 8;
|
||||
|
||||
sound.loopstart = 0;
|
||||
|
||||
@@ -423,7 +427,7 @@ stream_t *Stream_OpenWAV( const char *filename )
|
||||
}
|
||||
|
||||
FS_Read( file, &sound.samples, sizeof( int ));
|
||||
sound.samples = ( sound.samples / sound.width ) / sound.channels;
|
||||
sound.samples = ( LittleLong( sound.samples ) / sound.width ) / sound.channels;
|
||||
|
||||
// at this point we have valid stream
|
||||
stream = Mem_Calloc( host.soundpool, sizeof( stream_t ));
|
||||
|
||||
@@ -84,37 +84,37 @@ void Sound_Shutdown( void )
|
||||
|
||||
uint GAME_EXPORT Sound_GetApproxWavePlayLen( const char *filepath )
|
||||
{
|
||||
string name;
|
||||
file_t *f;
|
||||
wavehdr_t wav;
|
||||
size_t filesize;
|
||||
uint msecs;
|
||||
|
||||
string name;
|
||||
Q_strncpy( name, filepath, sizeof( name ));
|
||||
COM_FixSlashes( name );
|
||||
|
||||
f = FS_Open( name, "rb", false );
|
||||
file_t *f = FS_Open( name, "rb", false );
|
||||
if( !f )
|
||||
return 0;
|
||||
|
||||
wavehdr_t wav;
|
||||
if( FS_Read( f, &wav, sizeof( wav )) != sizeof( wav ))
|
||||
{
|
||||
FS_Close( f );
|
||||
return 0;
|
||||
}
|
||||
|
||||
filesize = FS_FileLength( f );
|
||||
filesize -= 128; // magic number from GoldSrc, seems to be header size
|
||||
// magic number from GoldSrc, seems to be header size
|
||||
size_t filesize = FS_FileLength( f ) - 128;
|
||||
|
||||
FS_Close( f );
|
||||
|
||||
// is real wav file ?
|
||||
if( wav.riff_id != RIFFHEADER || wav.wave_id != WAVEHEADER || wav.fmt_id != FORMHEADER )
|
||||
if( wav.riff_id != LittleLong( RIFFHEADER ) || wav.wave_id != LittleLong( WAVEHEADER ) || wav.fmt_id != LittleLong( FORMHEADER ))
|
||||
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);
|
||||
int avgBytes = LittleLong( wav.nAvgBytesPerSec );
|
||||
uint msecs;
|
||||
|
||||
if( avgBytes >= 1000 )
|
||||
msecs = (uint)((float)filesize / ((float)avgBytes / 1000.0f));
|
||||
else
|
||||
msecs = (uint)(((float)filesize / (float)avgBytes) * 1000.0f);
|
||||
|
||||
return msecs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user