Commit d1a171cf authored by Sam Hocevar's avatar Sam Hocevar

* Don't rely on fmt_in.audio.i_bitspersample in transformations, because

    filter functions could be chained.
parent 8d419259
...@@ -244,7 +244,7 @@ static block_t *Float32toS24( filter_t *p_filter, block_t *p_block ) ...@@ -244,7 +244,7 @@ static block_t *Float32toS24( filter_t *p_filter, block_t *p_block )
uint8_t *p_out = (uint8_t *)p_in; uint8_t *p_out = (uint8_t *)p_in;
int32_t out; int32_t out;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 4; i--; )
{ {
if ( *p_in >= 1.0 ) out = 8388607; if ( *p_in >= 1.0 ) out = 8388607;
else if ( *p_in < -1.0 ) out = -8388608; else if ( *p_in < -1.0 ) out = -8388608;
...@@ -271,7 +271,7 @@ static block_t *Float32toS16( filter_t *p_filter, block_t *p_block ) ...@@ -271,7 +271,7 @@ static block_t *Float32toS16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer; float *p_in = (float *)p_block->p_buffer;
int16_t *p_out = (int16_t *)p_in; int16_t *p_out = (int16_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 4; i--; )
{ {
#if 0 #if 0
/* Slow version. */ /* Slow version. */
...@@ -299,7 +299,7 @@ static block_t *Float32toU16( filter_t *p_filter, block_t *p_block ) ...@@ -299,7 +299,7 @@ static block_t *Float32toU16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer; float *p_in = (float *)p_block->p_buffer;
uint16_t *p_out = (uint16_t *)p_in; uint16_t *p_out = (uint16_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 4; i--; )
{ {
if ( *p_in >= 1.0 ) *p_out = 65535; if ( *p_in >= 1.0 ) *p_out = 65535;
else if ( *p_in < -1.0 ) *p_out = 0; else if ( *p_in < -1.0 ) *p_out = 0;
...@@ -319,7 +319,7 @@ static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block ) ...@@ -319,7 +319,7 @@ static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block )
int i; int i;
p_block_out = p_block_out =
p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer*4/3 ); p_filter->pf_audio_buffer_new( p_filter, p_block->i_buffer * 4 / 3 );
if( !p_block_out ) if( !p_block_out )
{ {
msg_Warn( p_filter, "can't get output buffer" ); msg_Warn( p_filter, "can't get output buffer" );
...@@ -329,8 +329,9 @@ static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block ) ...@@ -329,8 +329,9 @@ static block_t *S24toFloat32( filter_t *p_filter, block_t *p_block )
p_in = p_block->p_buffer; p_in = p_block->p_buffer;
p_out = (float *)p_block_out->p_buffer; p_out = (float *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 3; i--; )
{ {
/* FIXME: unaligned reads */
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2])) *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
#else #else
...@@ -357,7 +358,7 @@ static block_t *S24toS16( filter_t *p_filter, block_t *p_block ) ...@@ -357,7 +358,7 @@ static block_t *S24toS16( filter_t *p_filter, block_t *p_block )
uint8_t *p_in = (uint8_t *)p_block->p_buffer; uint8_t *p_in = (uint8_t *)p_block->p_buffer;
uint8_t *p_out = (uint8_t *)p_in; uint8_t *p_out = (uint8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 3; i--; )
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*p_out++ = *p_in++; *p_out++ = *p_in++;
...@@ -392,7 +393,7 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block ) ...@@ -392,7 +393,7 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
p_in = (int16_t *)p_block->p_buffer; p_in = (int16_t *)p_block->p_buffer;
p_out = (float *)p_block_out->p_buffer; p_out = (float *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
{ {
#if 0 #if 0
/* Slow version */ /* Slow version */
...@@ -437,7 +438,7 @@ static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block ) ...@@ -437,7 +438,7 @@ static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
p_in = (int16_t *)p_block->p_buffer; p_in = (int16_t *)p_block->p_buffer;
p_out = (float *)p_block_out->p_buffer; p_out = (float *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
{ {
*p_out++ = (float)(*p_in++ - 32768) / 32768.0; *p_out++ = (float)(*p_in++ - 32768) / 32768.0;
} }
...@@ -469,7 +470,7 @@ static block_t *S16toS24( filter_t *p_filter, block_t *p_block ) ...@@ -469,7 +470,7 @@ static block_t *S16toS24( filter_t *p_filter, block_t *p_block )
p_in = (uint8_t *)p_block->p_buffer; p_in = (uint8_t *)p_block->p_buffer;
p_out = (uint8_t *)p_block_out->p_buffer; p_out = (uint8_t *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
{ {
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*p_out++ = *p_in++; *p_out++ = *p_in++;
...@@ -498,7 +499,7 @@ static block_t *S16toS8( filter_t *p_filter, block_t *p_block ) ...@@ -498,7 +499,7 @@ static block_t *S16toS8( filter_t *p_filter, block_t *p_block )
int16_t *p_in = (int16_t *)p_block->p_buffer; int16_t *p_in = (int16_t *)p_block->p_buffer;
int8_t *p_out = (int8_t *)p_in; int8_t *p_out = (int8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = (*p_in++) >> 8; *p_out++ = (*p_in++) >> 8;
p_block->i_buffer /= 2; p_block->i_buffer /= 2;
...@@ -510,7 +511,7 @@ static block_t *S16toU8( filter_t *p_filter, block_t *p_block ) ...@@ -510,7 +511,7 @@ static block_t *S16toU8( filter_t *p_filter, block_t *p_block )
int16_t *p_in = (int16_t *)p_block->p_buffer; int16_t *p_in = (int16_t *)p_block->p_buffer;
uint8_t *p_out = (uint8_t *)p_in; uint8_t *p_out = (uint8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = ((*p_in++) + 32768) >> 8; *p_out++ = ((*p_in++) + 32768) >> 8;
p_block->i_buffer /= 2; p_block->i_buffer /= 2;
...@@ -522,7 +523,7 @@ static block_t *S16toU16( filter_t *p_filter, block_t *p_block ) ...@@ -522,7 +523,7 @@ static block_t *S16toU16( filter_t *p_filter, block_t *p_block )
int16_t *p_in = (int16_t *)p_block->p_buffer; int16_t *p_in = (int16_t *)p_block->p_buffer;
uint16_t *p_out = (uint16_t *)p_in; uint16_t *p_out = (uint16_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = (*p_in++) + 32768; *p_out++ = (*p_in++) + 32768;
return p_block; return p_block;
...@@ -534,7 +535,7 @@ static block_t *U16toS8( filter_t *p_filter, block_t *p_block ) ...@@ -534,7 +535,7 @@ static block_t *U16toS8( filter_t *p_filter, block_t *p_block )
uint16_t *p_in = (uint16_t *)p_block->p_buffer; uint16_t *p_in = (uint16_t *)p_block->p_buffer;
int8_t *p_out = (int8_t *)p_in; int8_t *p_out = (int8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = ((int)(*p_in++) - 32768) >> 8; *p_out++ = ((int)(*p_in++) - 32768) >> 8;
p_block->i_buffer /= 2; p_block->i_buffer /= 2;
...@@ -546,7 +547,7 @@ static block_t *U16toU8( filter_t *p_filter, block_t *p_block ) ...@@ -546,7 +547,7 @@ static block_t *U16toU8( filter_t *p_filter, block_t *p_block )
uint16_t *p_in = (uint16_t *)p_block->p_buffer; uint16_t *p_in = (uint16_t *)p_block->p_buffer;
uint8_t *p_out = (uint8_t *)p_in; uint8_t *p_out = (uint8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = (*p_in++) >> 8; *p_out++ = (*p_in++) >> 8;
p_block->i_buffer /= 2; p_block->i_buffer /= 2;
...@@ -558,7 +559,7 @@ static block_t *U16toS16( filter_t *p_filter, block_t *p_block ) ...@@ -558,7 +559,7 @@ static block_t *U16toS16( filter_t *p_filter, block_t *p_block )
int16_t *p_in = (int16_t *)p_block->p_buffer; int16_t *p_in = (int16_t *)p_block->p_buffer;
uint16_t *p_out = (uint16_t *)p_in; uint16_t *p_out = (uint16_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer / 2; i--; )
*p_out++ = (int)(*p_in++) - 32768; *p_out++ = (int)(*p_in++) - 32768;
return p_block; return p_block;
...@@ -570,7 +571,7 @@ static block_t *S8toU8( filter_t *p_filter, block_t *p_block ) ...@@ -570,7 +571,7 @@ static block_t *S8toU8( filter_t *p_filter, block_t *p_block )
int8_t *p_in = (int8_t *)p_block->p_buffer; int8_t *p_in = (int8_t *)p_block->p_buffer;
uint8_t *p_out = (uint8_t *)p_in; uint8_t *p_out = (uint8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = ((*p_in++) + 128); *p_out++ = ((*p_in++) + 128);
return p_block; return p_block;
...@@ -581,7 +582,7 @@ static block_t *U8toS8( filter_t *p_filter, block_t *p_block ) ...@@ -581,7 +582,7 @@ static block_t *U8toS8( filter_t *p_filter, block_t *p_block )
uint8_t *p_in = (uint8_t *)p_block->p_buffer; uint8_t *p_in = (uint8_t *)p_block->p_buffer;
int8_t *p_out = (int8_t *)p_in; int8_t *p_out = (int8_t *)p_in;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = ((*p_in++) - 128); *p_out++ = ((*p_in++) - 128);
return p_block; return p_block;
...@@ -606,7 +607,7 @@ static block_t *S8toU16( filter_t *p_filter, block_t *p_block ) ...@@ -606,7 +607,7 @@ static block_t *S8toU16( filter_t *p_filter, block_t *p_block )
p_in = (int8_t *)p_block->p_buffer; p_in = (int8_t *)p_block->p_buffer;
p_out = (uint16_t *)p_block_out->p_buffer; p_out = (uint16_t *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = ((*p_in++) + 128) << 8; *p_out++ = ((*p_in++) + 128) << 8;
p_block_out->i_samples = p_block->i_samples; p_block_out->i_samples = p_block->i_samples;
...@@ -637,7 +638,7 @@ static block_t *U8toS16( filter_t *p_filter, block_t *p_block ) ...@@ -637,7 +638,7 @@ static block_t *U8toS16( filter_t *p_filter, block_t *p_block )
p_in = (uint8_t *)p_block->p_buffer; p_in = (uint8_t *)p_block->p_buffer;
p_out = (int16_t *)p_block_out->p_buffer; p_out = (int16_t *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = ((*p_in++) - 128) << 8; *p_out++ = ((*p_in++) - 128) << 8;
p_block_out->i_samples = p_block->i_samples; p_block_out->i_samples = p_block->i_samples;
...@@ -669,7 +670,7 @@ static block_t *S8toS16( filter_t *p_filter, block_t *p_block ) ...@@ -669,7 +670,7 @@ static block_t *S8toS16( filter_t *p_filter, block_t *p_block )
p_in = (int8_t *)p_block->p_buffer; p_in = (int8_t *)p_block->p_buffer;
p_out = (int16_t *)p_block_out->p_buffer; p_out = (int16_t *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = (*p_in++) << 8; *p_out++ = (*p_in++) << 8;
p_block_out->i_samples = p_block->i_samples; p_block_out->i_samples = p_block->i_samples;
...@@ -700,7 +701,7 @@ static block_t *U8toU16( filter_t *p_filter, block_t *p_block ) ...@@ -700,7 +701,7 @@ static block_t *U8toU16( filter_t *p_filter, block_t *p_block )
p_in = (uint8_t *)p_block->p_buffer; p_in = (uint8_t *)p_block->p_buffer;
p_out = (uint16_t *)p_block_out->p_buffer; p_out = (uint16_t *)p_block_out->p_buffer;
for( i = p_block->i_buffer*8/p_filter->fmt_in.audio.i_bitspersample; i--; ) for( i = p_block->i_buffer; i--; )
*p_out++ = (*p_in++) << 8; *p_out++ = (*p_in++) << 8;
p_block_out->i_samples = p_block->i_samples; p_block_out->i_samples = p_block->i_samples;
......
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