Commit c730890f authored by Laurent Aimar's avatar Laurent Aimar

* adpcm: added dk3 too.

parent b5133d4d
......@@ -2,7 +2,7 @@
* adpcm.c : adpcm variant audio decoder
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
* $Id: adpcm.c,v 1.7 2003/02/16 09:50:22 fenrir Exp $
* $Id: adpcm.c,v 1.8 2003/02/16 11:18:11 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
......@@ -42,7 +42,7 @@
#define ADPCM_IMA_WAV 2
#define ADPCM_MS 3
#define ADPCM_DK3 4
#define ADPCM_DK4 4
#define ADPCM_DK4 5
typedef struct adec_thread_s
{
......@@ -81,6 +81,7 @@ static void EndThread ( adec_thread_t * );
static void DecodeAdpcmMs( adec_thread_t *, aout_buffer_t * );
static void DecodeAdpcmImaWav( adec_thread_t *, aout_buffer_t * );
static void DecodeAdpcmDk4( adec_thread_t *, aout_buffer_t * );
static void DecodeAdpcmDk3( adec_thread_t *, aout_buffer_t * );
/*****************************************************************************
* Module descriptor
......@@ -157,7 +158,7 @@ static int OpenDecoder( vlc_object_t *p_this )
case VLC_FOURCC('m','s',0x00,0x02): /* MS ADPCM */
case VLC_FOURCC('m','s',0x00,0x11): /* IMA ADPCM */
case VLC_FOURCC('m','s',0x00,0x61): /* Duck DK4 ADPCM */
// case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */
case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */
p_fifo->pf_run = RunDecoder;
return VLC_SUCCESS;
......@@ -215,11 +216,11 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
#define FREE( p ) if( p ) free( p ); p = NULL
#define GetWLE( p ) \
( *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) )
( *(uint8_t*)(p) + ( *((uint8_t*)(p)+1) << 8 ) )
#define GetDWLE( p ) \
( *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) + \
( *((u8*)(p)+2) << 16 ) + ( *((u8*)(p)+3) << 24 ) )
( *(uint8_t*)(p) + ( *((uint8_t*)(p)+1) << 8 ) + \
( *((uint8_t*)(p)+2) << 16 ) + ( *((uint8_t*)(p)+3) << 24 ) )
/*****************************************************************************
* InitThread: initialize data before entering main loop
......@@ -295,8 +296,13 @@ static int InitThread( adec_thread_t * p_adec )
2 * ( p_adec->i_block - 4 * p_adec->p_wf->nChannels ) /
p_adec->p_wf->nChannels + 1;
break;
case ADPCM_DK3:
p_adec->p_wf->nChannels = 2;
p_adec->i_samplesperblock = ( 4 * ( p_adec->i_block - 16 ) + 2 )/ 3;
break;
default:
p_adec->i_samplesperblock = 0;
msg_Err( p_adec->p_fifo, "unknown adpcm variant" );
return( -1 );
}
msg_Dbg( p_adec->p_fifo,
......@@ -454,6 +460,8 @@ static void DecodeThread( adec_thread_t *p_adec )
break;
case ADPCM_DK4:
DecodeAdpcmDk4( p_adec, p_aout_buffer );
case ADPCM_DK3:
DecodeAdpcmDk3( p_adec, p_aout_buffer );
default:
break;
}
......@@ -757,3 +765,80 @@ static void DecodeAdpcmDk4( adec_thread_t *p_adec,
p_buffer++;
}
}
/*
* Dk3
*/
static void DecodeAdpcmDk3( adec_thread_t *p_adec,
aout_buffer_t *p_aout_buffer)
{
uint8_t *p_buffer, *p_end;
adpcm_ima_wav_channel_t sum;
adpcm_ima_wav_channel_t diff;
uint16_t *p_sample;
int i_diff_value;
p_buffer = p_adec->p_block;
p_end = p_buffer + p_adec->i_block;
p_buffer += 10;
GetWord( sum.i_predictor );
GetWord( diff.i_predictor );
GetByte( sum.i_step_index );
GetByte( diff.i_step_index );
p_sample = (int16_t*)p_aout_buffer->p_buffer;
i_diff_value = diff.i_predictor;
/* we process 6 nibbles at once */
//for( i_group = 0; i_group < ( p_adec->i_block -16 ) / 3; i_group++ )
while( p_buffer + 1 <= p_end )
{
/* first 3 nibbles */
AdpcmImaWavExpandNibble( &sum,
(*p_buffer)&0x0f);
AdpcmImaWavExpandNibble( &diff,
(*p_buffer) >> 4 );
i_diff_value = ( i_diff_value + diff.i_predictor ) / 2;
*p_sample++ = sum.i_predictor + i_diff_value;
*p_sample++ = sum.i_predictor - i_diff_value;
p_buffer++;
AdpcmImaWavExpandNibble( &sum,
(*p_buffer)&0x0f);
*p_sample++ = sum.i_predictor + i_diff_value;
*p_sample++ = sum.i_predictor - i_diff_value;
/* now last 3 nibbles */
AdpcmImaWavExpandNibble( &sum,
(*p_buffer)>>4);
p_buffer++;
if( p_buffer < p_end )
{
AdpcmImaWavExpandNibble( &diff,
(*p_buffer)&0x0f );
i_diff_value = ( i_diff_value + diff.i_predictor ) / 2;
*p_sample++ = sum.i_predictor + i_diff_value;
*p_sample++ = sum.i_predictor - i_diff_value;
AdpcmImaWavExpandNibble( &sum,
(*p_buffer)>>4);
p_buffer++;
*p_sample++ = sum.i_predictor + i_diff_value;
*p_sample++ = sum.i_predictor - i_diff_value;
}
}
}
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