Skip to content

Commit

Permalink
Decoders can now list multiple file extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 1, 2001
1 parent 604e0b5 commit e2612fd
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Expand Up @@ -101,6 +101,10 @@
10232001 - Rewrote playsound.c's audio_callback() to no longer need the
overflow buffer hack, which streamlines it a little and trims the
memory requirements for playsound by about 16 kilobytes.
11012001 - API COMPATIBILITY BREAKAGE: Decoders can now list multiple file
extensions each. Playsound has been updated to handle this.
Playsound now registers a SIGINT handler, so you can skip tracks
and/or abort the way that mpg123 does.

--ryan. (icculus@clutteredmind.org)

Expand Down
26 changes: 15 additions & 11 deletions SDL_sound.c
Expand Up @@ -444,8 +444,8 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
Sound_AudioInfo *desired, Uint32 bSize)
{
size_t i;
Sound_Sample *retval;
decoder_element *decoder;

/* sanity checks. */
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL);
Expand All @@ -457,26 +457,30 @@ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,

if (ext != NULL)
{
for (i = 0; decoders[i].funcs != NULL; i++)
for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
{
if (decoders[i].available)
if (decoder->available)
{
const char *decoderExt = decoders[i].funcs->info.extension;
if (__Sound_strcasecmp(decoderExt, ext) == 0)
const char **decoderExt = decoder->funcs->info.extensions;
while (*decoderExt)
{
if (init_sample(decoders[i].funcs, retval, ext, desired))
return(retval);
} /* if */
if (__Sound_strcasecmp(*decoderExt, ext) == 0)
{
if (init_sample(decoder->funcs, retval, ext, desired))
return(retval);
} /* if */
decoderExt++;
} /* while */
} /* if */
} /* for */
} /* if */

/* no direct extension match? Try everything we've got... */
for (i = 0; decoders[i].funcs != NULL; i++)
for (decoder = &decoders[0]; decoder->funcs != NULL; decoder++)
{
if (decoders[i].available)
if (decoder->available)
{
if (init_sample(decoders[i].funcs, retval, ext, desired))
if (init_sample(decoder->funcs, retval, ext, desired))
return(retval);
} /* if */
} /* for */
Expand Down
8 changes: 4 additions & 4 deletions SDL_sound.h
Expand Up @@ -112,10 +112,10 @@ typedef struct __SOUND_AUDIOINFO__
*/
typedef struct __SOUND_DECODERINFO__
{
const char *extension; /* standard file extension. "MP3", "WAV"... */
const char *description; /* Human readable description of decoder. */
const char *author; /* "Name Of Author <email@emailhost.dom>" */
const char *url; /* URL specific to this decoder. */
const char **extensions; /* File extensions, list ends with NULL. */
const char *description; /* Human readable description of decoder. */
const char *author; /* "Name Of Author <email@emailhost.dom>" */
const char *url; /* URL specific to this decoder. */
} Sound_DecoderInfo;


Expand Down
3 changes: 2 additions & 1 deletion decoders/aiff.c
Expand Up @@ -63,10 +63,11 @@ static int AIFF_open(Sound_Sample *sample, const char *ext);
static void AIFF_close(Sound_Sample *sample);
static Uint32 AIFF_read(Sound_Sample *sample);

static const char *extensions_aiff[] = { "AIFF", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
{
{
"AIFF",
extensions_aiff,
"Audio Interchange File Format",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/midi.c
Expand Up @@ -69,10 +69,11 @@ static int MIDI_open(Sound_Sample *sample, const char *ext);
static void MIDI_close(Sound_Sample *sample);
static Uint32 MIDI_read(Sound_Sample *sample);

static const char *extensions_midi[] = { "MIDI", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_MIDI =
{
{
"MIDI",
extensions_midi,
"MIDI music through the TiMidity MIDI to WAVE converter",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"http://www.goice.co.jp/member/mo/timidity/"
Expand Down
9 changes: 8 additions & 1 deletion decoders/mod.c
Expand Up @@ -53,10 +53,17 @@ static int MOD_open(Sound_Sample *sample, const char *ext);
static void MOD_close(Sound_Sample *sample);
static Uint32 MOD_read(Sound_Sample *sample);

static const char *extensions_mikmod[] =
{
"MOD", "IT", "XM", "S3M", "MTM", "669", "STM", "ULT",
"FAR", "MED", "AMF", "DSM", "IMF", "GDM", "STX", "OKT",
NULL
};

const Sound_DecoderFunctions __Sound_DecoderFunctions_MOD =
{
{
"MOD",
extensions_mikmod,
"Play modules through MikMod",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"http://www.mikmod.org/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/mp3.c
Expand Up @@ -55,10 +55,11 @@ static int MP3_open(Sound_Sample *sample, const char *ext);
static void MP3_close(Sound_Sample *sample);
static Uint32 MP3_read(Sound_Sample *sample);

static const char *extensions_smpeg[] = { "MP3", "MPEG", "MPG", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
{
{
"MP3",
extensions_smpeg,
"MPEG-1 Layer 3 audio through SMPEG",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/ogg.c
Expand Up @@ -59,10 +59,11 @@ static int OGG_open(Sound_Sample *sample, const char *ext);
static void OGG_close(Sound_Sample *sample);
static Uint32 OGG_read(Sound_Sample *sample);

static const char *extensions_ogg[] = { "OGG", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_OGG =
{
{
"OGG",
extensions_ogg,
"Ogg Vorbis audio through VorbisFile",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/raw.c
Expand Up @@ -60,10 +60,11 @@ static int RAW_open(Sound_Sample *sample, const char *ext);
static void RAW_close(Sound_Sample *sample);
static Uint32 RAW_read(Sound_Sample *sample);

static const char *extensions_raw[] = { "RAW", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_RAW =
{
{
"RAW",
extensions_raw,
"Raw audio",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/shn.c
Expand Up @@ -67,10 +67,11 @@ static int SHN_open(Sound_Sample *sample, const char *ext);
static void SHN_close(Sound_Sample *sample);
static Uint32 SHN_read(Sound_Sample *sample);

static const char *extensions_shn[] = { "SHN", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_SHN =
{
{
"SHN",
extensions_shn,
"Shorten-compressed audio data",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/skeleton.c
Expand Up @@ -56,10 +56,11 @@ static int FMT_open(Sound_Sample *sample, const char *ext);
static void FMT_close(Sound_Sample *sample);
static Uint32 FMT_read(Sound_Sample *sample);

static const char *extensions_fmt[] = { "FMT", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_FMT =
{
{
"FMT",
extensions_fmt,
"FMT audio format description",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/voc.c
Expand Up @@ -59,10 +59,11 @@ static int VOC_open(Sound_Sample *sample, const char *ext);
static void VOC_close(Sound_Sample *sample);
static Uint32 VOC_read(Sound_Sample *sample);

static const char *extensions_voc[] = { "VOC", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_VOC =
{
{
"VOC",
extensions_voc,
"Creative Labs Voice format",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down
3 changes: 2 additions & 1 deletion decoders/wav.c
Expand Up @@ -50,10 +50,11 @@ static int WAV_open(Sound_Sample *sample, const char *ext);
static void WAV_close(Sound_Sample *sample);
static Uint32 WAV_read(Sound_Sample *sample);

static const char *extensions_wav[] = { "WAV", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_WAV =
{
{
"WAV",
extensions_wav,
"Microsoft WAVE audio format",
"Ryan C. Gordon <icculus@clutteredmind.org>",
"http://www.icculus.org/SDL_sound/"
Expand Down

0 comments on commit e2612fd

Please sign in to comment.