changeset 143:3e60862fbd76

Start of audio converter work.
author Ryan C. Gordon <icculus@icculus.org>
date Mon, 15 Oct 2001 21:21:11 +0000
parents 56f6acdc4ea0
children 195c96fa355a
files Makefile.am SDL_sound.c SDL_sound_internal.h
diffstat 3 files changed, 36 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Mon Oct 15 21:20:54 2001 +0000
+++ b/Makefile.am	Mon Oct 15 21:21:11 2001 +0000
@@ -10,7 +10,8 @@
 	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)	\
@@ -19,4 +20,7 @@
 
 
 EXTRA_DIST =	\
-	CREDITS
+	CREDITS \
+	LICENSE \
+	CHANGELOG
+        
--- a/SDL_sound.c	Mon Oct 15 21:20:54 2001 +0000
+++ b/SDL_sound.c	Mon Oct 15 21:21:11 2001 +0000
@@ -381,13 +381,13 @@
     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);
@@ -398,7 +398,7 @@
     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);
@@ -611,8 +611,8 @@
     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);
--- a/SDL_sound_internal.h	Mon Oct 15 21:20:54 2001 +0000
+++ b/SDL_sound_internal.h	Mon Oct 15 21:21:11 2001 +0000
@@ -94,7 +94,7 @@
          *    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)
@@ -158,20 +158,37 @@
 } 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"