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.
This commit is contained in:
Bill Currie 2010-11-21 14:18:15 +09:00
parent 99e87b092b
commit 4cec187465
2 changed files with 26 additions and 5 deletions

View file

@ -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;

View file

@ -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;