X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=snd_wav.c;h=b55c36653358524b8dd636f341323c92dfeb41a8;hb=9b73f5e152089c02f4157b4f3cddcc884e3648cd;hp=c40986e2dcc87b4b0c45e5adc1e3a1e3c1ec31a6;hpb=087c96690cbc912a6eeca0555d5bf1ffaa6c2daf;p=xonotic%2Fdarkplaces.git diff --git a/snd_wav.c b/snd_wav.c index c40986e2..b55c3665 100644 --- a/snd_wav.c +++ b/snd_wav.c @@ -65,7 +65,7 @@ static int GetLittleLong(void) return val; } -static void FindNextChunk(char *name) +static void FindNextChunk(const char *name) { while (1) { @@ -84,6 +84,12 @@ static void FindNextChunk(char *name) data_p = NULL; return; } + if (data_p + iff_chunk_len > iff_end) + { + // truncated chunk! + data_p = NULL; + return; + } data_p -= 8; last_chunk = data_p + 8 + ( (iff_chunk_len + 1) & ~1 ); if (!strncmp((const char *)data_p, name, 4)) @@ -91,7 +97,7 @@ static void FindNextChunk(char *name) } } -static void FindChunk(char *name) +static void FindChunk(const char *name) { last_chunk = iff_data; FindNextChunk (name); @@ -223,10 +229,10 @@ static wavinfo_t GetWavinfo (char *name, unsigned char *wav, int wavlength) WAV_FetchSound ==================== */ -static const snd_buffer_t* WAV_FetchSound (channel_t* ch, unsigned int *start, unsigned int nbsampleframes) +static const snd_buffer_t* WAV_FetchSound (void *sfxfetcher, void **chfetcherpointer, unsigned int *start, unsigned int nbsampleframes) { *start = 0; - return (snd_buffer_t *)ch->sfx->fetcher_data; + return (snd_buffer_t *)sfxfetcher; } /* @@ -234,16 +240,11 @@ static const snd_buffer_t* WAV_FetchSound (channel_t* ch, unsigned int *start, u WAV_FreeSfx ==================== */ -static void WAV_FreeSfx (sfx_t* sfx) +static void WAV_FreeSfx (void *sfxfetcherdata) { - snd_buffer_t* sb = (snd_buffer_t *)sfx->fetcher_data; - + snd_buffer_t* sb = (snd_buffer_t *)sfxfetcherdata; // Free the sound buffer - sfx->memsize -= (sb->maxframes * sb->format.channels * sb->format.width) + sizeof (*sb) - sizeof (sb->samples); Mem_Free(sb); - - sfx->fetcher_data = NULL; - sfx->fetcher = NULL; } /* @@ -289,7 +290,8 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) return false; } - Con_DPrintf ("Loading WAV file \"%s\"\n", filename); + if (developer_loading.integer >= 2) + Con_Printf ("Loading WAV file \"%s\"\n", filename); info = GetWavinfo (sfx->name, data, (int)filesize); if (info.channels < 1 || info.channels > 2) // Stereo sounds are allowed (intended for music) @@ -301,10 +303,9 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) //if (info.channels == 2) // Log_Printf("stereosounds.log", "%s\n", sfx->name); -#if BYTE_ORDER != LITTLE_ENDIAN // We must convert the WAV data from little endian // to the machine endianess before resampling it - if (info.width == 2) + if (info.width == 2 && mem_bigendian) { unsigned int len, i; short* ptr; @@ -314,7 +315,6 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) for (i = 0; i < len; i++) ptr[i] = LittleShort (ptr[i]); } -#endif wav_format.speed = info.rate; wav_format.width = info.width; @@ -334,7 +334,7 @@ qboolean S_LoadWavFile (const char *filename, sfx_t *sfx) if (info.loopstart < 0) sfx->loopstart = sfx->total_length; else - sfx->loopstart = (double)info.loopstart * (double)snd_renderbuffer->format.speed / (double)sb->format.speed; + sfx->loopstart = (unsigned int) ((double)info.loopstart * (double)sb->format.speed / (double)info.rate); sfx->loopstart = min(sfx->loopstart, sfx->total_length); sfx->flags &= ~SFXFLAG_STREAMED;