[SDL_sound] AIFF decoder

Ryan C. Gordon icculus at clutteredmind.org
Thu Sep 20 04:19:20 EDT 2001


> The AIFF decoder seems to be working now, at least for the files that
> I've thrown at it. It wasn't until now that I realized how similar
> AIFF is to WAV, so I rewrote it to be much more like your WAV decoder.
> There are some subtle differences in find_chunk() and how it's used
> though.

Excellent!  Thanks!

> I've also made a small patch to the WAV loader which I'm sure you will
> agree with me when I say it's extremely important and should be given
> the highest priority. ;-)

It's sad, in the decoder skeleton I make fun of people that mess up a
simple search-and-replace operation, and then I go and do that very thing.
I'm so embarrassed.  :)

> This means, correct me if I'm wrong, that I will get a number of RWops
> which all share the same FILE pointer. The sound decoders seem to just
> assume that internal->rw is still positioned where they left it at the
> end of the last call to the decoder.

This is intentional, actually. RWops are meant to be, in the Unix
philosophy, a single stream of bytes. Not to mention that, sooner or
later, a HTTP or whatnot RWops will show up that can't perform seeking,
and then we're in trouble.

For now, I've committed that code, with and #ifdef around it, but I think
these are better ways to handle the problem:

1) It's safe to get more than one FILE * to a file that is opened read
only. You can then seek and read in each FILE * independent of the others.
If the source of your FILE * can be changed to fopen() the same physical
file again for each sound source, then not only is it more efficient
overall (since the kernel will buffer reads, but it can't do much for the
overhead of all the seeking), and thread-safe, but it requires no changes
to SDL_sound. PhysicsFS (http://icculus.org/physfs/) does this for ZIP
files (and probably should for GRP files), if you want an example.

1.5) Hhmm...we could always add support for that archive format to
PhysicsFS.  :)

2) If we use the patch to SDL_sound, if nothing else, you'll have to make
sure that you wrap each of these "files" in a reference counting RWops,
since SDL_sound closes the RWops when done with it, which would close the
original FILE *, too. See extra_rwops.* and decoders/mp3.c for examples
of this in action.

3) Add another RWops to extra_rwops.c that takes a single FILE * or
SDL_RWops and splits it into several. This does the same thing as your
patch, except it moves the burden out of SDL_sound, and puts the overhead
only on those that choose to use it (and changes how one solves the
problems of multiple closings of the same FILE *). Note that this is still
inherently thread UNsafe, though, unless you add a mutex that is shared
between RWops that have a common FILE *, which is also a headache, but not
impossible.

That's my dissertation on the subject. Obviously, I'm a big fan of
option #1, but that depends on how feasible it is for you to make a
change in the other project. I'd take option #3 next. Let me know how
you'd like to proceed.

--ryan.






More information about the sdlsound mailing list