From 4cec1874654d445e7aa0a891298365f9bd23096a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 21 Nov 2010 14:18:15 +0900 Subject: [PATCH] zixthree's wav file patch Wav file were not read correctly when encoutering most chunk type beside the ones used by QuakeForge. This patch will fix the riff loader code so that unused but defined chunk are skipped. Most wav files should now be loaded correctly fixing some silent sound effect. Also fixed a typo in wav loader and reordered wav validity check so that format is checked first. The data chunk could be inexistant on some weird format and so an invalid format is a more helpful error text. ! Fix: Skip unsupported chunk in riff loader instead of rejecting riff file. ! Fix: typo in Microsoft name. ! Fix: ordering of wav validity to enable more helpful error text. --- libs/audio/renderer/wav.c | 10 +++++----- libs/util/riff.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/libs/audio/renderer/wav.c b/libs/audio/renderer/wav.c index 0ee193fa2..1f94daf87 100644 --- a/libs/audio/renderer/wav.c +++ b/libs/audio/renderer/wav.c @@ -235,18 +235,18 @@ wav_get_info (QFile *file) Sys_Printf ("missing format chunk\n"); goto bail; } - if (!data) { - Sys_Printf ("missing data chunk\n"); - goto bail; - } if (dfmt->format_tag != 1) { - Sys_Printf ("not Microsfot PCM\n"); + Sys_Printf ("not Microsoft PCM\n"); goto bail; } if (dfmt->channels < 1 || dfmt->channels > 8) { Sys_Printf ("unsupported channel count\n"); goto bail; } + if (!data) { + Sys_Printf ("missing data chunk\n"); + goto bail; + } info.rate = dfmt->samples_per_sec; info.width = dfmt->bits_per_sample / 8; diff --git a/libs/util/riff.c b/libs/util/riff.c index 2e5ee7f95..eff201e13 100644 --- a/libs/util/riff.c +++ b/libs/util/riff.c @@ -367,6 +367,27 @@ riff_read (QFile *f) chunk = &data->ck; } break; + case RIFF_CASE ('w','a','v','l'): + // FIXME: Convert wavl to data ? + case RIFF_CASE ('s','l','n','t'): + // FIXME: Add silence to data + case RIFF_CASE ('l','i','s','t'): + case RIFF_CASE ('l','a','b','l'): + case RIFF_CASE ('n','o','t','e'): + case RIFF_CASE ('l','t','x','t'): + case RIFF_CASE ('p','l','s','t'): + case RIFF_CASE ('i','n','s','t'): + case RIFF_CASE ('f','a','c','t'): + case RIFF_CASE ('s','m','p','l'): + { // Unused chunk, still present in a lot of wav files. + int c; + + Qseek(f, ck.len, SEEK_CUR); + if ((c = Qgetc (f)) && c != -1) + Qungetc (f, c); + continue; // Skip those blocks. + } + break; default: // unknown chunk. bail (could be corrupted file) chunk = 0;