Commit 449d9902 authored by Sam Hocevar's avatar Sam Hocevar

* modules/audio_filter/format.c: fix audio conversion crashes and bugs.

parent e40429e2
......@@ -244,7 +244,7 @@ static block_t *Float32toS24( filter_t *p_filter, block_t *p_block )
uint8_t *p_out = (uint8_t *)p_in;
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;
else if ( *p_in < -1.0 ) out = -8388608;
......@@ -271,7 +271,7 @@ static block_t *Float32toS16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer;
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
/* Slow version. */
......@@ -299,7 +299,7 @@ static block_t *Float32toU16( filter_t *p_filter, block_t *p_block )
float *p_in = (float *)p_block->p_buffer;
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;
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 )
int i;
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 )
{
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 )
p_in = p_block->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
*p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
#else
......@@ -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_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
*p_out++ = *p_in++;
......@@ -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_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
/* Slow version */
......@@ -422,7 +423,7 @@ static block_t *S16toFloat32( filter_t *p_filter, block_t *p_block )
static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
{
block_t *p_block_out;
int16_t *p_in;
uint16_t *p_in;
float *p_out;
int i;
......@@ -434,10 +435,10 @@ static block_t *U16toFloat32( filter_t *p_filter, block_t *p_block )
return NULL;
}
p_in = (int16_t *)p_block->p_buffer;
p_in = (uint16_t *)p_block->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;
}
......@@ -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_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
*p_out++ = *p_in++;
......@@ -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;
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_block->i_buffer /= 2;
......@@ -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;
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_block->i_buffer /= 2;
......@@ -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;
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;
return 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;
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_block->i_buffer /= 2;
......@@ -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;
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_block->i_buffer /= 2;
......@@ -555,10 +556,10 @@ static block_t *U16toU8( filter_t *p_filter, block_t *p_block )
static block_t *U16toS16( filter_t *p_filter, block_t *p_block )
{
int i;
int16_t *p_in = (int16_t *)p_block->p_buffer;
uint16_t *p_out = (uint16_t *)p_in;
uint16_t *p_in = (uint16_t *)p_block->p_buffer;
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 / 2; i--; )
*p_out++ = (int)(*p_in++) - 32768;
return 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;
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);
return 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;
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);
return 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_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_block_out->i_samples = p_block->i_samples;
......@@ -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_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_block_out->i_samples = p_block->i_samples;
......@@ -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_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_block_out->i_samples = p_block->i_samples;
......@@ -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_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_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