From e43ccee77fc98ed7e3e8b0ccd71acfd73611bedb Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 24 Apr 2026 21:07:19 +0500 Subject: [PATCH] engine: soundlib: swap WAV data --- engine/client/soundlib/snd_wav.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/engine/client/soundlib/snd_wav.c b/engine/client/soundlib/snd_wav.c index 806a8b44..676a0d43 100644 --- a/engine/client/soundlib/snd_wav.c +++ b/engine/client/soundlib/snd_wav.c @@ -319,6 +319,15 @@ qboolean Sound_LoadWAV( const char *name, const byte *buffer, fs_offset_t filesi memcpy( sound.wav, buffer + (iff_dataPtr - buffer), sound.size ); + // swap 16-bit samples from little endian to native + if( sound.width == 2 ) + { + short *p = (short *)sound.wav; + int count = sound.size / 2; + for( int i = 0; i < count; i++ ) + p[i] = LittleShort( p[i] ); + } + // now convert 8-bit sounds to signed if( sound.width == 1 ) { @@ -462,6 +471,14 @@ int Stream_ReadWAV( stream_t *stream, int bytes, void *buffer ) stream->pos += bytes; FS_Read( stream->file, buffer, bytes ); + if( stream->width == 2 ) + { + short *p = (short *)buffer; + int count = bytes / 2; + for( int i = 0; i < count; i++ ) + p[i] = LittleShort( p[i] ); + } + return bytes; }