Skip to content

Commit

Permalink
Removed predeclares in decoders.
Browse files Browse the repository at this point in the history
Saves a few lines per file, moves the metadata to the end.
  • Loading branch information
icculus committed Jul 20, 2018
1 parent 940142c commit 3676d9a
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 418 deletions.
98 changes: 43 additions & 55 deletions src/SDL_sound_aiff.c
Expand Up @@ -31,37 +31,6 @@

#if SOUND_SUPPORTS_AIFF

static Uint32 SANE_to_Uint32 (Uint8 *sanebuf);


static int AIFF_init(void);
static void AIFF_quit(void);
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 int AIFF_rewind(Sound_Sample *sample);
static int AIFF_seek(Sound_Sample *sample, Uint32 ms);

static const char *extensions_aiff[] = { "AIFF", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
{
{
extensions_aiff,
"Audio Interchange File Format",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"https://icculus.org/SDL_sound/"
},

AIFF_init, /* init() method */
AIFF_quit, /* quit() method */
AIFF_open, /* open() method */
AIFF_close, /* close() method */
AIFF_read, /* read() method */
AIFF_rewind, /* rewind() method */
AIFF_seek /* seek() method */
};


/*****************************************************************************
* aiff_t is what we store in our internal->decoder_private field... *
*****************************************************************************/
Expand Down Expand Up @@ -166,11 +135,33 @@ typedef struct
} comm_t;


/*
* Sample rate is encoded as an "80 bit IEEE Standard 754 floating point
* number (Standard Apple Numeric Environment [SANE] data type Extended)".
* Whose bright idea was that?
*
* This function was adapted from libsndfile, and while I do know a little
* bit about the IEEE floating point standard I don't pretend to fully
* understand this.
*/
static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
{
/* Is the frequency outside of what we can represent with Uint32? */
if ( (sanebuf[0] & 0x80)
|| (sanebuf[0] <= 0x3F)
|| (sanebuf[0] > 0x40)
|| (sanebuf[0] == 0x40 && sanebuf[1] > 0x1C) )
return 0;

return ((sanebuf[2] << 23) | (sanebuf[3] << 15) | (sanebuf[4] << 7)
| (sanebuf[5] >> 1)) >> (29 - sanebuf[1]);
} /* SANE_to_Uint32 */


/*
* Read in a comm_t from disk. This makes this process safe regardless of
* the processor's byte order or how the comm_t structure is packed.
*/

static int read_comm_chunk(SDL_RWops *rw, comm_t *comm)
{
Uint8 sampleRate[10];
Expand Down Expand Up @@ -355,29 +346,6 @@ static void AIFF_quit(void)
} /* AIFF_quit */


/*
* Sample rate is encoded as an "80 bit IEEE Standard 754 floating point
* number (Standard Apple Numeric Environment [SANE] data type Extended)".
* Whose bright idea was that?
*
* This function was adapted from libsndfile, and while I do know a little
* bit about the IEEE floating point standard I don't pretend to fully
* understand this.
*/
static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
{
/* Is the frequency outside of what we can represent with Uint32? */
if ( (sanebuf[0] & 0x80)
|| (sanebuf[0] <= 0x3F)
|| (sanebuf[0] > 0x40)
|| (sanebuf[0] == 0x40 && sanebuf[1] > 0x1C) )
return 0;

return ((sanebuf[2] << 23) | (sanebuf[3] << 15) | (sanebuf[4] << 7)
| (sanebuf[5] >> 1)) >> (29 - sanebuf[1]);
} /* SANE_to_Uint32 */


static int find_chunk(SDL_RWops *rw, Uint32 id)
{
Sint32 siz = 0;
Expand Down Expand Up @@ -543,6 +511,26 @@ static int AIFF_seek(Sound_Sample *sample, Uint32 ms)
return a->fmt.seek_sample(sample, ms);
} /* AIFF_seek */

static const char *extensions_aiff[] = { "AIFF", "AIF", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_AIFF =
{
{
extensions_aiff,
"Audio Interchange File Format",
"Torbjörn Andersson <d91tan@Update.UU.SE>",
"https://icculus.org/SDL_sound/"
},

AIFF_init, /* init() method */
AIFF_quit, /* quit() method */
AIFF_open, /* open() method */
AIFF_close, /* close() method */
AIFF_read, /* read() method */
AIFF_rewind, /* rewind() method */
AIFF_seek /* seek() method */
};


#endif /* SOUND_SUPPORTS_AIFF */

/* end of SDL_sound_aiff.c ... */
Expand Down
56 changes: 24 additions & 32 deletions src/SDL_sound_au.c
Expand Up @@ -17,38 +17,6 @@

#if SOUND_SUPPORTS_AU

static int AU_init(void);
static void AU_quit(void);
static int AU_open(Sound_Sample *sample, const char *ext);
static void AU_close(Sound_Sample *sample);
static Uint32 AU_read(Sound_Sample *sample);
static int AU_rewind(Sound_Sample *sample);
static int AU_seek(Sound_Sample *sample, Uint32 ms);

/*
* Sometimes the extension ".snd" is used for these files (mostly on the NeXT),
* and the magic number comes from this. However it may clash with other
* formats and is somewhat of an anachronism, so only .au is used here.
*/
static const char *extensions_au[] = { "AU", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_AU =
{
{
extensions_au,
"Sun/NeXT audio file format",
"Mattias Engdegård <f91-men@nada.kth.se>",
"https://icculus.org/SDL_sound/"
},

AU_init, /* init() method */
AU_quit, /* quit() method */
AU_open, /* open() method */
AU_close, /* close() method */
AU_read, /* read() method */
AU_rewind, /* rewind() method */
AU_seek /* seek() method */
};

/* no init/deinit needed */
static int AU_init(void)
{
Expand Down Expand Up @@ -354,6 +322,30 @@ static int AU_seek(Sound_Sample *sample, Uint32 ms)
return 1;
} /* AU_seek */

/*
* Sometimes the extension ".snd" is used for these files (mostly on the NeXT),
* and the magic number comes from this. However it may clash with other
* formats and is somewhat of an anachronism, so only .au is used here.
*/
static const char *extensions_au[] = { "AU", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_AU =
{
{
extensions_au,
"Sun/NeXT audio file format",
"Mattias Engdegård <f91-men@nada.kth.se>",
"https://icculus.org/SDL_sound/"
},

AU_init, /* init() method */
AU_quit, /* quit() method */
AU_open, /* open() method */
AU_close, /* close() method */
AU_read, /* read() method */
AU_rewind, /* rewind() method */
AU_seek /* seek() method */
};

#endif /* SOUND_SUPPORTS_AU */

/* end of SDL_sound_au.c ... */
Expand Down
100 changes: 46 additions & 54 deletions src/SDL_sound_coreaudio.c
Expand Up @@ -22,59 +22,6 @@ typedef struct CoreAudioFileContainer
AudioStreamBasicDescription* outputFormat;
} CoreAudioFileContainer;

static int CoreAudio_init(void);
static void CoreAudio_quit(void);
static int CoreAudio_open(Sound_Sample *sample, const char *ext);
static void CoreAudio_close(Sound_Sample *sample);
static Uint32 CoreAudio_read(Sound_Sample *sample);
static int CoreAudio_rewind(Sound_Sample *sample);
static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms);

static const char *extensions_coreaudio[] =
{
"aif",
"aiff",
"aifc",
"wav",
"wave",
"mp3",
"mp4",
"m4a",
"aac",
"caf",
"Sd2f",
"Sd2",
"au",
"next",
"mp2",
"mp1",
"ac3",
"3gpp",
"3gp2",
"amrf",
"amr",
"ima4",
"ima",
NULL
};
const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio =
{
{
extensions_coreaudio,
"Decode audio through Core Audio through",
"Eric Wing <ewing . public @ playcontrol.net>",
"https://playcontrol.net"
},

CoreAudio_init, /* init() method */
CoreAudio_quit, /* quit() method */
CoreAudio_open, /* open() method */
CoreAudio_close, /* close() method */
CoreAudio_read, /* read() method */
CoreAudio_rewind, /* rewind() method */
CoreAudio_seek /* seek() method */
};


static int CoreAudio_init(void)
{
Expand Down Expand Up @@ -748,8 +695,53 @@ static int CoreAudio_seek(Sound_Sample *sample, Uint32 ms)
return 1;
} /* CoreAudio_seek */

#endif /* SOUND_SUPPORTS_COREAUDIO */

static const char *extensions_coreaudio[] =
{
"aif",
"aiff",
"aifc",
"wav",
"wave",
"mp3",
"mp4",
"m4a",
"aac",
"caf",
"Sd2f",
"Sd2",
"au",
"next",
"mp2",
"mp1",
"ac3",
"3gpp",
"3gp2",
"amrf",
"amr",
"ima4",
"ima",
NULL
};
const Sound_DecoderFunctions __Sound_DecoderFunctions_CoreAudio =
{
{
extensions_coreaudio,
"Decode audio through Core Audio through",
"Eric Wing <ewing . public @ playcontrol.net>",
"https://playcontrol.net"
},

CoreAudio_init, /* init() method */
CoreAudio_quit, /* quit() method */
CoreAudio_open, /* open() method */
CoreAudio_close, /* close() method */
CoreAudio_read, /* read() method */
CoreAudio_rewind, /* rewind() method */
CoreAudio_seek /* seek() method */
};

#endif /* SOUND_SUPPORTS_COREAUDIO */

/* end of SDL_sound_coreaudio.c ... */

47 changes: 19 additions & 28 deletions src/SDL_sound_flac.c
Expand Up @@ -38,34 +38,6 @@
#define DRFLAC_ZERO_MEMORY(p, sz) SDL_memset((p), 0, (sz))
#include "dr_flac.h"

static int FLAC_init(void);
static void FLAC_quit(void);
static int FLAC_open(Sound_Sample *sample, const char *ext);
static void FLAC_close(Sound_Sample *sample);
static Uint32 FLAC_read(Sound_Sample *sample);
static int FLAC_rewind(Sound_Sample *sample);
static int FLAC_seek(Sound_Sample *sample, Uint32 ms);

static const char *extensions_flac[] = { "FLAC", "FLA", NULL };

const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC =
{
{
extensions_flac,
"Free Lossless Audio Codec",
"Ryan C. Gordon <icculus@icculus.org>",
"https://icculus.org/SDL_sound/"
},

FLAC_init, /* init() method */
FLAC_quit, /* quit() method */
FLAC_open, /* open() method */
FLAC_close, /* close() method */
FLAC_read, /* read() method */
FLAC_rewind, /* rewind() method */
FLAC_seek /* seek() method */
};

static size_t flac_read(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
Uint8 *ptr = (Uint8 *) pBufferOut;
Expand Down Expand Up @@ -185,6 +157,25 @@ static int FLAC_seek(Sound_Sample *sample, Uint32 ms)
return (drflac_seek_to_sample(dr, sampnum) == DRFLAC_TRUE);
} /* FLAC_seek */

static const char *extensions_flac[] = { "FLAC", "FLA", NULL };
const Sound_DecoderFunctions __Sound_DecoderFunctions_FLAC =
{
{
extensions_flac,
"Free Lossless Audio Codec",
"Ryan C. Gordon <icculus@icculus.org>",
"https://icculus.org/SDL_sound/"
},

FLAC_init, /* init() method */
FLAC_quit, /* quit() method */
FLAC_open, /* open() method */
FLAC_close, /* close() method */
FLAC_read, /* read() method */
FLAC_rewind, /* rewind() method */
FLAC_seek /* seek() method */
};

#endif /* SOUND_SUPPORTS_FLAC */

/* end of SDL_sound_flac.c ... */
Expand Down

0 comments on commit 3676d9a

Please sign in to comment.