[vlc-devel] commit: ugly resampler: use memcpy() ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Jan 30 14:52:25 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jan 30 15:34:45 2010 +0200| [cd3b41614db369194fbbe34b93f56441d5b15ae5] | committer: Rémi Denis-Courmont 

ugly resampler: use memcpy()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cd3b41614db369194fbbe34b93f56441d5b15ae5
---

 modules/audio_filter/resampler/ugly.c |   39 +++++++++++++++-----------------
 1 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/modules/audio_filter/resampler/ugly.c b/modules/audio_filter/resampler/ugly.c
index e3a33f4..19afc4c 100644
--- a/modules/audio_filter/resampler/ugly.c
+++ b/modules/audio_filter/resampler/ugly.c
@@ -84,11 +84,11 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
     if( p_filter->fmt_out.audio.i_rate == p_filter->fmt_in.audio.i_rate )
         return p_in_buf;
 
-    unsigned int i_nb_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
-    unsigned int i_in_nb = p_in_buf->i_nb_samples;
-    unsigned int i_out_nb = i_in_nb * p_filter->fmt_out.audio.i_rate
-                                    / p_filter->fmt_in.audio.i_rate;
-    unsigned int i_sample_bytes = i_nb_channels * sizeof(int32_t);
+    block_t *p_out_buf = p_in_buf;
+    unsigned int i_out_nb = p_in_buf->i_nb_samples
+        * p_filter->fmt_out.audio.i_rate / p_filter->fmt_in.audio.i_rate;
+    const unsigned int i_sample_bytes =
+        aout_FormatNbChannels( &p_filter->fmt_in.audio ) * sizeof(int32_t);
 
     if( p_filter->fmt_out.audio.i_rate > p_filter->fmt_in.audio.i_rate )
     {
@@ -97,33 +97,30 @@ static block_t *DoWork( filter_t * p_filter, block_t * p_in_buf )
             goto out;
     }
 
-    int32_t *p_out = (int32_t*)p_out_buf->p_buffer;
-    const int32_t *p_in = (int32_t*)p_in_buf->p_buffer;
+    unsigned char *p_out = p_out_buf->p_buffer;
+    unsigned char *p_in = p_in_buf->p_buffer;
     unsigned int i_remainder = 0;
 
-    for( unsigned i_out = i_out_nb ; i_out-- ; )
+    p_out_buf->i_nb_samples = i_out_nb;
+    p_out_buf->i_buffer = i_out_nb * i_sample_bytes;
+    p_out_buf->i_pts = p_in_buf->i_pts;
+    p_out_buf->i_length = p_out_buf->i_nb_samples *
+        1000000 / p_filter->fmt_out.audio.i_rate;
+
+    while( i_out_nb )
     {
-        for( unsigned i_chan = i_nb_channels ; i_chan ; )
-        {
-            i_chan--;
-            p_out[i_chan] = p_in[i_chan];
-        }
-        p_out += i_nb_channels;
+        memcpy( p_out, p_in, i_sample_bytes );
+        p_out += i_sample_bytes;
+        i_out_nb--;
 
         i_remainder += p_filter->fmt_in.audio.i_rate;
         while( i_remainder >= p_filter->fmt_out.audio.i_rate )
         {
-            p_in += i_nb_channels;
+            p_in += i_sample_bytes;
             i_remainder -= p_filter->fmt_out.audio.i_rate;
         }
     }
 
-    p_out_buf->i_nb_samples = i_out_nb;
-    p_out_buf->i_buffer = i_out_nb * i_sample_bytes;
-    p_out_buf->i_pts = p_in_buf->i_pts;
-    p_out_buf->i_length = p_out_buf->i_nb_samples *
-        1000000 / p_filter->fmt_out.audio.i_rate;
-
     if( p_in_buf != p_out_buf )
 out:
         block_Release( p_in_buf );




More information about the vlc-devel mailing list