[vlc-commits] aout_ChannelReorder: optimize 16 and 32 bits cases with aligned access

Rémi Denis-Courmont git at videolan.org
Sat Nov 10 23:21:51 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov 11 00:21:15 2012 +0200| [49e1047e8815ae3c208a80ff44fb792cf1c17454] | committer: Rémi Denis-Courmont

aout_ChannelReorder: optimize 16 and 32 bits cases with aligned access

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

 include/vlc_aout.h        |    2 +-
 src/audio_output/common.c |  101 +++++++++++++++++++++++++--------------------
 2 files changed, 57 insertions(+), 46 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 2835b27..9aa5ec7 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -179,7 +179,7 @@ static const uint32_t pi_vlc_chan_order_wg4[] =
  * internal (WG4) order is requested.
  */
 VLC_API int aout_CheckChannelReorder( const uint32_t *pi_chan_order_in, const uint32_t *pi_chan_order_out, uint32_t i_channel_mask, int i_channels, int *pi_chan_table );
-VLC_API void aout_ChannelReorder( uint8_t *, int, int, const int *, int );
+VLC_API void aout_ChannelReorder( void *, size_t, unsigned, const int *, unsigned );
 
 /**
  * This fonction will compute the extraction parameter into pi_selection to go
diff --git a/src/audio_output/common.c b/src/audio_output/common.c
index b11e086..027caab 100644
--- a/src/audio_output/common.c
+++ b/src/audio_output/common.c
@@ -280,69 +280,80 @@ int aout_CheckChannelReorder( const uint32_t *pi_chan_order_in,
 /*****************************************************************************
  * aout_ChannelReorder :
  *****************************************************************************/
-void aout_ChannelReorder( uint8_t *p_buf, int i_buffer,
-                          int i_channels, const int *pi_chan_table,
-                          int i_bits_per_sample )
+void aout_ChannelReorder( void *ptr, size_t bytes, unsigned channels,
+                          const int *pi_chan_table, unsigned bits_per_sample )
 {
-    uint8_t p_tmp[AOUT_CHAN_MAX * 4];
-    int i, j;
+    size_t samples = bytes / (channels * (bits_per_sample >> 3));
 
-    if( i_bits_per_sample == 8 )
+    assert( channels <= AOUT_CHAN_MAX );
+
+    switch( bits_per_sample )
     {
-        for( i = 0; i < i_buffer / i_channels; i++ )
+        case 32:
         {
-            for( j = 0; j < i_channels; j++ )
+            uint32_t *buf = ptr;
+
+            for( size_t i = 0; i < samples; i++ )
             {
-                p_tmp[pi_chan_table[j]] = p_buf[j];
-            }
+                uint32_t tmp[AOUT_CHAN_MAX];
 
-            memcpy( p_buf, p_tmp, i_channels );
-            p_buf += i_channels;
+                for( size_t j = 0; j < channels; j++ )
+                    tmp[pi_chan_table[j]] = buf[j];
+
+                memcpy( buf, tmp, 4 * channels );
+                buf += channels;
+            }
+            break;
         }
-    }
-    else if( i_bits_per_sample == 16 )
-    {
-        for( i = 0; i < i_buffer / i_channels / 2; i++ )
+
+        case 16:
         {
-            for( j = 0; j < i_channels; j++ )
+            uint16_t *buf = ptr;
+
+            for( size_t i = 0; i < samples; i++ )
             {
-                p_tmp[2 * pi_chan_table[j]]     = p_buf[2 * j];
-                p_tmp[2 * pi_chan_table[j] + 1] = p_buf[2 * j + 1];
-            }
+                uint16_t tmp[AOUT_CHAN_MAX];
 
-            memcpy( p_buf, p_tmp, 2 * i_channels );
-            p_buf += 2 * i_channels;
+                for( size_t j = 0; j < channels; j++ )
+                    tmp[pi_chan_table[j]] = buf[j];
+
+                memcpy( buf, tmp, 2 * channels );
+                buf += channels;
+            }
+            break;
         }
-    }
-    else if( i_bits_per_sample == 24 )
-    {
-        for( i = 0; i < i_buffer / i_channels / 3; i++ )
+
+        case 8:
         {
-            for( j = 0; j < i_channels; j++ )
+            uint8_t *buf = ptr;
+
+            for( size_t i = 0; i < samples; i++ )
             {
-                p_tmp[3 * pi_chan_table[j]]     = p_buf[3 * j];
-                p_tmp[3 * pi_chan_table[j] + 1] = p_buf[3 * j + 1];
-                p_tmp[3 * pi_chan_table[j] + 2] = p_buf[3 * j + 2];
-            }
+                uint8_t tmp[AOUT_CHAN_MAX];
 
-            memcpy( p_buf, p_tmp, 3 * i_channels );
-            p_buf += 3 * i_channels;
+                for( size_t j = 0; j < channels; j++ )
+                    tmp[pi_chan_table[j]] = buf[j];
+
+                memcpy( buf, tmp, channels );
+                buf += channels;
+            }
+            break;
         }
-    }
-    else if( i_bits_per_sample == 32 )
-    {
-        for( i = 0; i < i_buffer / i_channels / 4; i++ )
+
+        case 24:
         {
-            for( j = 0; j < i_channels; j++ )
+            uint8_t *buf = ptr;
+
+            for( size_t i = 0; i < samples; i++ )
             {
-                p_tmp[4 * pi_chan_table[j]]     = p_buf[4 * j];
-                p_tmp[4 * pi_chan_table[j] + 1] = p_buf[4 * j + 1];
-                p_tmp[4 * pi_chan_table[j] + 2] = p_buf[4 * j + 2];
-                p_tmp[4 * pi_chan_table[j] + 3] = p_buf[4 * j + 3];
-            }
+                uint8_t tmp[3 * AOUT_CHAN_MAX];
+
+                for( size_t j = 0; j < channels; j++ )
+                    memcpy( tmp + (3 * pi_chan_table[j]), buf + (3 * j), 3 );
 
-            memcpy( p_buf, p_tmp, 4 * i_channels );
-            p_buf += 4 * i_channels;
+                memcpy( buf, tmp, 3 * channels );
+                buf += 3 * channels;
+            }
         }
     }
 }



More information about the vlc-commits mailing list