changeset 347:778cee61e1be

Mono-to-stereo fixes, more fprintf debugging output.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 23 May 2002 12:37:13 +0000
parents b6341f628568
children 4b46cf359136
files alt_audio_convert.c
diffstat 1 files changed, 29 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/alt_audio_convert.c	Thu May 23 12:36:50 2002 +0000
+++ b/alt_audio_convert.c	Thu May 23 12:37:13 2002 +0000
@@ -157,7 +157,7 @@
 static int convertMonoToStereo( AdapterC Data, int length )
 {
    int i;
-   short* buffer = Data.buffer-2;
+   short* buffer = Data.buffer-1;
    length *= 2;
 
     /*
@@ -165,8 +165,8 @@
      * !!! FIXME:  a second index variable?  --ryan.
      */
    for( i = length; i;  i-=2 )
-        buffer[i] = buffer [i+1] = buffer[i/2];
-   return length*2;
+        buffer[i] = buffer [i-1] = buffer[i/2];
+   return length;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -351,10 +351,15 @@
    if( Ratio > 1.0)
        VarPos = filter_index++;
    else
+   {
+       fprintf (stderr, "Filter: minus5dB\n");
        Data->adapter[filter_index++] = minus5dB;
+   }
 
    while( Ratio > 64.0/31.0)
    {
+       fprintf (stderr, "Filter: %s\n",
+                Mono ? "doubleRateMono" : "doubleRateStereo");
        Data->adapter[filter_index++] =
            Mono ? doubleRateMono : doubleRateStereo;
        Ratio /= 2;
@@ -365,6 +370,8 @@
 
    while( Ratio < 31.0/64.0 )
    {
+       fprintf (stderr, "Filter: %s\n",
+                Mono ? "halfRateMono" : "halfRateStereo");
        Data->adapter[filter_index++] =
            Mono ? halfRateMono : halfRateStereo;
        Ratio *= 2;
@@ -372,6 +379,8 @@
 
    if( Ratio > 1.0 )
    {
+       fprintf (stderr, "Filter: %s\n",
+                Mono ? "varRateMono" : "varRateStereo");
        setupVarFilter( &Data->filter, Ratio, Up );
        Data->adapter[VarPos] =
            Mono ? varRateMono : varRateStereo;
@@ -381,11 +390,13 @@
    }
    else
    {
+       fprintf (stderr, "Filter: %s\n",
+                Mono ? "varRateMono" : "varRateStereo");
        setupVarFilter( &Data->filter, Ratio, Down );
        Data->adapter[filter_index++] =
            Mono ? varRateMono : varRateStereo;
    }
-   return 0;
+   return filter_index;
 }
 
 static int BuildAudioCVT(Sound_AudioCVT *Data,
@@ -606,6 +617,20 @@
                 src_format |= ( AUDIO_16WRONG | AUDIO_SIGN );
                 dst_format |= AUDIO_16WRONG;
             } /* if */
+
+            if ( src_rate != dst_rate )
+            {
+                    /*
+                     * !!! FIXME !!!
+                     *
+                     * The audio conversion filter probably only works if the
+                     * data is in system byte order. So we need to convert to
+                     * system byte order, and then back to original byte
+                     * order. This is not an optimal solution.
+                     */
+                src_format |= AUDIO_16WRONG;
+                dst_format |= AUDIO_16WRONG;
+            }
         } /* else if */
         else if ( SIGNED(src_in_format) != SIGNED(dst_in_format) )
         {