Skip to content

Commit

Permalink
Start of audio converter work.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 15, 2001
1 parent 3b2438e commit 4eaa16a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Makefile.am
Expand Up @@ -10,7 +10,8 @@ libSDL_sound_la_SOURCES = \
SDL_sound.c \
SDL_sound_internal.h \
extra_rwops.c \
extra_rwops.h
extra_rwops.h \
audio_convert.c

libSDL_sound_la_LDFLAGS = \
-release $(LT_RELEASE) \
Expand All @@ -19,4 +20,7 @@ libSDL_sound_la_LIBADD = decoders/libdecoders.la


EXTRA_DIST = \
CREDITS
CREDITS \
LICENSE \
CHANGELOG

20 changes: 10 additions & 10 deletions SDL_sound.c
Expand Up @@ -381,13 +381,13 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
memcpy(&desired, (_desired != NULL) ? _desired : &sample->actual,
sizeof (Sound_AudioInfo));

if (SDL_BuildAudioCVT(&internal->sdlcvt,
sample->actual.format,
sample->actual.channels,
(int) sample->actual.rate, /* !!! FIXME: Int? Really? */
desired.format,
desired.channels,
(int) desired.rate) == -1) /* !!! FIXME: Int? Really? */
if (Sound_BuildAudioCVT(&internal->sdlcvt,
sample->actual.format,
sample->actual.channels,
sample->actual.rate,
desired.format,
desired.channels,
desired.rate) == -1)
{
Sound_SetError(SDL_GetError());
funcs->close(sample);
Expand All @@ -398,7 +398,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
if (internal->sdlcvt.len_mult > 1)
{
void *rc = realloc(sample->buffer,
sample->buffer_size * internal->sdlcvt.len_mult);
sample->buffer_size * internal->sdlcvt.len_mult);
if (rc == NULL)
{
funcs->close(sample);
Expand Down Expand Up @@ -611,8 +611,8 @@ Uint32 Sound_Decode(Sound_Sample *sample)
if (internal->sdlcvt.needed)
{
internal->sdlcvt.len = retval;
SDL_ConvertAudio(&internal->sdlcvt);
retval *= internal->sdlcvt.len_mult;
Sound_ConvertAudio(&internal->sdlcvt);
retval = internal->sdlcvt.len_cvt;
} /* if */

return(retval);
Expand Down
23 changes: 20 additions & 3 deletions SDL_sound_internal.h
Expand Up @@ -94,7 +94,7 @@ typedef struct __SOUND_DECODERFUNCTIONS__
* Sound_Sample *prev; (offlimits)
* SDL_RWops *rw; (can use, but do NOT close it)
* const Sound_DecoderFunctions *funcs; (that's this structure)
* SDL_AudioCVT sdlcvt; (offlimits)
* Sound_AudioCVT sdlcvt; (offlimits)
* void *buffer; (offlimits until read() method)
* Uint32 buffer_size; (offlimits until read() method)
* void *decoder_private; (read and write access)
Expand Down Expand Up @@ -158,20 +158,37 @@ typedef struct __SOUND_DECODERFUNCTIONS__
} Sound_DecoderFunctions;


/* A structure to hold a set of audio conversion filters and buffers */

typedef struct Sound_AudioCVT
{
int needed; /* Set to 1 if conversion possible */
Uint16 src_format; /* Source audio format */
Uint16 dst_format; /* Target audio format */
double rate_incr; /* Rate conversion increment */
Uint8 *buf; /* Buffer to hold entire audio data */
int len; /* Length of original audio buffer */
int len_cvt; /* Length of converted audio buffer */
int len_mult; /* buffer must be len*len_mult big */
double len_ratio; /* Given len, final size is len*len_ratio */
void (*filters[20])(struct Sound_AudioCVT *cvt, Uint16 *format);
int filter_index; /* Current audio conversion function */
} Sound_AudioCVT;


typedef struct __SOUND_SAMPLEINTERNAL__
{
Sound_Sample *next;
Sound_Sample *prev;
SDL_RWops *rw;
const Sound_DecoderFunctions *funcs;
SDL_AudioCVT sdlcvt;
Sound_AudioCVT sdlcvt;
void *buffer;
Uint32 buffer_size;
void *decoder_private;
} Sound_SampleInternal;



/* error messages... */
#define ERR_IS_INITIALIZED "Already initialized"
#define ERR_NOT_INITIALIZED "Not initialized"
Expand Down

0 comments on commit 4eaa16a

Please sign in to comment.