gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash backend/sound_handler.cpp ChangeLog


From: Martin Guy
Subject: [Gnash-commit] gnash backend/sound_handler.cpp ChangeLog
Date: Fri, 18 May 2007 14:21:32 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Martin Guy <martinwguy> 07/05/18 14:21:31

Modified files:
        backend        : sound_handler.cpp 
        .              : ChangeLog 

Log message:
                * backend/sound_handler.cpp: Speed convert_raw_data and handle 
stereo
                  upsampling correctly

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/backend/sound_handler.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3270&r2=1.3271

Patches:
Index: backend/sound_handler.cpp
===================================================================
RCS file: /sources/gnash/gnash/backend/sound_handler.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- backend/sound_handler.cpp   18 May 2007 13:17:51 -0000      1.3
+++ backend/sound_handler.cpp   18 May 2007 14:21:30 -0000      1.4
@@ -36,6 +36,10 @@
        int m_sample_rate,
        bool m_stereo)
 {
+    fprintf(stderr, "Converting raw data from size=%d %d(%s) to %d(%s)\n",
+               sample_size, sample_rate, stereo ? "stereo" : "mono",
+               m_sample_rate, stereo ? "stereo" : "mono");
+
        // simple hack to handle dup'ing mono to stereo
        if ( !stereo && m_stereo)
        {
@@ -43,7 +47,6 @@
        }
 
        // simple hack to lose half the samples to get mono from stereo
-       // Unfortunately, this gives two copies of the left channel.
        if ( stereo && !m_stereo)
        {
                sample_rate <<= 1;
@@ -65,22 +68,85 @@
        int     output_sample_count = (sample_count * dup * (stereo ? 2 : 1)) / 
inc;
        int16_t*        out_data = new int16_t[output_sample_count];
        *adjusted_data = out_data;
-       *adjusted_size = output_sample_count * 2;       // 2 bytes per sample
+    *adjusted_size = output_sample_count * sizeof(int16_t); // in bytes
 
-       if (inc == 1 && dup == 1) {
-               // Speed up no-op case
+    // Either inc > 1 (decimate the audio)
+    // or dup > 1 (repeat samples)
+    // or both == 1 (no transformation required)
+    if (inc == 1 && dup == 1)
+    {
+           // No tranformation required
                memcpy(out_data, data, output_sample_count * sizeof(int16_t));
-       } else {
-               // crude sample rate conversion.
+    }
+    else if (inc > 1)
+    {
+       // Downsample by skipping samples from the input
+       int16_t*        in = (int16_t*) data;
+       for (int i = output_sample_count; i > 0; i--)
+       {
+           *out_data++ = *in;
+           in += inc;
+       }
+    }
+    else if (dup > 1)
+    {
+       // Upsample by duplicating input samples in the output.
+
+       // The straight sample-replication code handles mono-to-stereo (sort of)
+       // and upsampling of mono but would make a botch of stereo-to-stereo
+       // upsampling, giving the left sample in both channels
+       // then the right sample in both channels alternately.
+       // So for stereo-stereo transforms we have a stereo routine.
+
                int16_t*        in = (int16_t*) data;
-               for (int i = 0; i < output_sample_count; i += dup)
+
+       if (stereo && m_stereo) {
+           // Stereo-to-stereo upsampling: Replicate pairs of samples
+           for (int i = output_sample_count / dup / 2; i > 0; i--)
                {
-                       int16_t val = *in;
-                       for (int j = 0; j < dup; j++)
+               for (int j = dup; j > 0; j--)
                        {
-                               *out_data++ = val;
+                       out_data[0] = in[0];
+                       out_data[1] = in[1];
+                       out_data += 2;
+               }
+               in += 2;
+           }
+       } else {
+           // Linear upsampling, either to increase a sample rate
+           // or to convert a mono file to stereo or both:
+           // replicate each sample several times.
+           switch (dup)
+           {
+           case 2:
+               for (int i = output_sample_count / dup; i > 0; i--)
+               {
+                   *out_data++ = *in;
+                   *out_data++ = *in;
+                   in++;
+               }
+               break;
+           case 4:
+               for (int i = output_sample_count / dup; i > 0; i--)
+               {
+                   *out_data++ = *in;
+                   *out_data++ = *in;
+                   *out_data++ = *in;
+                   *out_data++ = *in;
+                   in++;
+               }
+               break;
+           default:
+               for (int i = output_sample_count / dup; i > 0; i--)
+               {
+                   for (int j = dup; j > 0; j--)
+                   {
+                           *out_data++ = *in;
+                   }
+                   in++;
+               }
+               break;
                        }
-                       in += inc;
                }
        }
 }

Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3270
retrieving revision 1.3271
diff -u -b -r1.3270 -r1.3271
--- ChangeLog   18 May 2007 14:04:05 -0000      1.3270
+++ ChangeLog   18 May 2007 14:21:30 -0000      1.3271
@@ -53,6 +53,8 @@
          testsuite/sound_handler_test.cpp,
          testsuite/sound_handler_test.h:
          convert_raw_samples is now just a static fn of sound_handler::
+       * backend/sound_handler.cpp: Speed convert_raw_data and handle stereo
+         upsampling correctly
 
 2007-05-17  Rob Savoye  <address@hidden>
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]