Commit 49e1047e authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout_ChannelReorder: optimize 16 and 32 bits cases with aligned access

parent d8232746
......@@ -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
......
......@@ -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;
}
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment