Bug 2721 - Errors in sound codec and Ogg Vorbis decoder
Status: RESOLVED FIXED
Alias: None
Product: ioquake3
Classification: Unclassified
Component: Sound
Version: 1.33 SVN
Hardware: All All
: P2 normal
Assignee: Zachary J. Slater
QA Contact: ioquake3 bugzilla mailing list
URL:
Depends on:
Blocks:
 
Reported: 2006-05-27 06:54 EDT by Joerg Dietrich
Modified: 2007-05-21 11:26:39 EDT
0 users

See Also:


Attachments
The patch for the errors. (997 bytes, patch)
2006-05-27 06:54 EDT, Joerg Dietrich

Description Joerg Dietrich 2006-05-27 06:54:15 EDT
sound codec patch

This patch corrects some quirks and errors in the icculus.org/quake3 sound codec and Ogg Vorbis decoder.

The function S_FileExtension() in code/client/snd_codec.c tries to find the
file extension of a file. It did so by starting at the beginning of the filename
and searching to the first '.' . This could lead to problems with relative paths.
It did not because Quake 3 filters out relative paths. 
Now the function starts at the end of the filename and searches backwards
to the next '/'.

In function S_FindCodecForFile() in code/client/snd_codec.c when there is no
extension in the filename it tries all available codecs. 
For this it copied the filename to a temporary buffer minus the last four chars 
for the extension. As there is no extension we must copy the whole string.

In functions S_CodecLoad() and S_CodecOpenStream() in code/client/snd_codec.c
I changed the default behavior. Originally the sound codec tried to load/open the
sound with the exact name given. Now it tries all available codecs to open
a sound file with the same name but an other extension. This allows to recompress
sounds e.g. from WAV to OGG without recompiling the map.

In function S_OGG_CodecReadStream() in code/client/snd_codec_ogg.c I added support
for big endian machines. Up until now the Ogg Vorbis decoder always returned
little endian samples. Now it takes the endianess of the host into acount and returns 
big endian samples for big endian machines.

This patch was tested in SuSE Linux 10.1, Windows 2000 with MinGW and MacOS 10.4 
on an G4 Mac mini.
Comment 1 Joerg Dietrich 2006-05-27 06:54:55 EDT
Created attachment 919 [details]
The patch for the errors.
Comment 2 Thilo Schulz 2006-05-27 11:03:28 EDT
> Now the function starts at the end of the filename and searches backwards
> to the next '/'.

That seems fine :)

> Now it tries all available codecs to open
> a sound file with the same name but an other extension. This allows to
> recompress sounds e.g. from WAV to OGG without recompiling the map.

This looks more like a dirty hack than a good feature. ID only did that for original quake3 for image formats, because they realized their game wouldn't fit on a CD if they had all textures in .tga very shortly before it went gold. So they quickly converted the files to .jpg and added a jpeg decoder.
I wouldn't want to have a hack like that included.

> In function S_OGG_CodecReadStream() in code/client/snd_codec_ogg.c I added
> support for big endian machines. Up until now the Ogg Vorbis decoder always
> returned little endian samples. Now it takes the endianess of the host into
> acount and returns big endian samples for big endian machines.

Ok that's probably a good thing to do.
Comment 3 Joerg Dietrich 2006-05-27 12:08:20 EDT
(In reply to comment #2)

> > Now it tries all available codecs to open
> > a sound file with the same name but an other extension. This allows to
> > recompress sounds e.g. from WAV to OGG without recompiling the map.
> 
> This looks more like a dirty hack than a good feature. ID only did that for
> original quake3 for image formats, because they realized their game wouldn't
> fit on a CD if they had all textures in .tga very shortly before it went gold.
> So they quickly converted the files to .jpg and added a jpeg decoder.
> I wouldn't want to have a hack like that included.

This is a valid argument. On the other hand we get format independence.
We don't need to care if a sound is a WAV, an OGG or whatever as long
as it is available in any form.

If this feature is not wanted apply the patch and revert the two
functions S_CodecLoad() and S_CodecOpenStream() in code/client/snd_codec.c
to their original state. It is only an one line change.
Comment 4 Thilo Schulz 2006-05-31 20:15:18 EDT
Ci'd, thanks!
Comment 5 Ryan C. Gordon 2007-05-21 11:26:39 EDT
Setting a QA contact on all ioquake3 bugs, even resolved ones. Sorry if you get a flood of email from this, it should only happen once. Apologies for the incovenience.

--ryan.