X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fadpcm.c;h=c9a9ec2f85cb9fa4176ada714b008bce184da261;hb=be68773052b3b440f3274b1164fb07b22d147a59;hp=469ec1bd7b40fc88914f60e76325a4480e298810;hpb=fea7f383ddfe2e92b2b58bce13bb53350029ffb0;p=vlc diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c index 469ec1bd7b..c9a9ec2f85 100644 --- a/modules/codec/adpcm.c +++ b/modules/codec/adpcm.c @@ -1,10 +1,11 @@ /***************************************************************************** * adpcm.c : adpcm variant audio decoder ***************************************************************************** - * Copyright (C) 2001, 2002 VideoLAN - * $Id: adpcm.c,v 1.19 2004/01/25 18:20:12 bigben Exp $ + * Copyright (C) 2001, 2002 the VideoLAN team + * $Id$ * * Authors: Laurent Aimar + * Rémi Denis-Courmont * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,7 +19,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -26,8 +27,14 @@ * * Documentation: http://www.pcisys.net/~melanson/codecs/adpcm.txt *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include /***************************************************************************** * Module descriptor @@ -38,8 +45,10 @@ static void CloseDecoder( vlc_object_t * ); static aout_buffer_t *DecodeBlock( decoder_t *, block_t ** ); vlc_module_begin(); - set_description( _("ADPCM audio decoder") ); + set_description( N_("ADPCM audio decoder") ); set_capability( "decoder", 50 ); + set_category( CAT_INPUT ); + set_subcategory( SUBCAT_INPUT_ACODEC ); set_callbacks( OpenDecoder, CloseDecoder ); vlc_module_end(); @@ -52,15 +61,16 @@ enum adpcm_codec_e ADPCM_IMA_WAV, ADPCM_MS, ADPCM_DK3, - ADPCM_DK4 + ADPCM_DK4, + ADPCM_EA }; struct decoder_sys_t { enum adpcm_codec_e codec; - int i_block; - int i_samplesperblock; + size_t i_block; + size_t i_samplesperblock; audio_date_t end_date; }; @@ -70,8 +80,9 @@ static void DecodeAdpcmImaWav( decoder_t *, int16_t *, uint8_t * ); static void DecodeAdpcmImaQT ( decoder_t *, int16_t *, uint8_t * ); static void DecodeAdpcmDk4 ( decoder_t *, int16_t *, uint8_t * ); static void DecodeAdpcmDk3 ( decoder_t *, int16_t *, uint8_t * ); +static void DecodeAdpcmEA ( decoder_t *, int16_t *, uint8_t * ); -static int pi_channels_maps[6] = +static const int pi_channels_maps[6] = { 0, AOUT_CHAN_CENTER, @@ -83,13 +94,13 @@ static int pi_channels_maps[6] = }; /* Various table from http://www.pcisys.net/~melanson/codecs/adpcm.txt */ -static int i_index_table[16] = +static const int i_index_table[16] = { -1, -1, -1, -1, 2, 4, 6, 8, -1, -1, -1, -1, 2, 4, 6, 8 }; -static int i_step_table[89] = +static const int i_step_table[89] = { 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, @@ -102,18 +113,18 @@ static int i_step_table[89] = 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 }; -static int i_adaptation_table[16] = +static const int i_adaptation_table[16] = { 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 }; -static int i_adaptation_coeff1[7] = +static const int i_adaptation_coeff1[7] = { 256, 512, 0, 192, 240, 460, 392 }; -static int i_adaptation_coeff2[7] = +static const int i_adaptation_coeff2[7] = { 0, -256, 0, 64, 0, -208, -232 }; @@ -133,23 +144,17 @@ static int OpenDecoder( vlc_object_t *p_this ) 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('X','A','J', 0): /* EA ADPCM */ break; default: return VLC_EGENERIC; } - /* Allocate the memory needed to store the decoder's structure */ - if( ( p_dec->p_sys = p_sys = - (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) - { - msg_Err( p_dec, "out of memory" ); - return VLC_EGENERIC; - } - if( p_dec->fmt_in.audio.i_channels <= 0 || p_dec->fmt_in.audio.i_channels > 5 ) { - msg_Err( p_dec, "bad channels count(1-5)" ); + msg_Err( p_dec, "invalid number of channel (not between 1 and 5): %i", + p_dec->fmt_in.audio.i_channels ); return VLC_EGENERIC; } @@ -159,6 +164,11 @@ static int OpenDecoder( vlc_object_t *p_this ) return VLC_EGENERIC; } + /* Allocate the memory needed to store the decoder's structure */ + if( ( p_dec->p_sys = p_sys = + (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL ) + return VLC_ENOMEM; + switch( p_dec->fmt_in.i_codec ) { case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ @@ -176,13 +186,23 @@ static int OpenDecoder( vlc_object_t *p_this ) case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ p_sys->codec = ADPCM_DK3; break; + case VLC_FOURCC('X','A','J', 0): /* EA ADPCM */ + p_sys->codec = ADPCM_EA; + p_dec->fmt_in.p_extra = calloc( 2 * p_dec->fmt_in.audio.i_channels, + sizeof( int16_t ) ); + if( p_dec->fmt_in.p_extra == NULL ) + { + free( p_sys ); + return VLC_ENOMEM; + } + break; } if( p_dec->fmt_in.audio.i_blockalign <= 0 ) { p_sys->i_block = (p_sys->codec == ADPCM_IMA_QT) ? 34 * p_dec->fmt_in.audio.i_channels : 1024; - msg_Warn( p_dec, "block size undefined, using %d", p_sys->i_block ); + msg_Warn( p_dec, "block size undefined, using %zu", p_sys->i_block ); } else { @@ -214,10 +234,14 @@ static int OpenDecoder( vlc_object_t *p_this ) p_dec->fmt_in.audio.i_channels = 2; p_sys->i_samplesperblock = ( 4 * ( p_sys->i_block - 16 ) + 2 )/ 3; break; + case ADPCM_EA: + p_sys->i_samplesperblock = + 2 * (p_sys->i_block - p_dec->fmt_in.audio.i_channels) / + p_dec->fmt_in.audio.i_channels; } - msg_Dbg( p_dec, "format: samplerate:%dHz channels:%d bits/sample:%d " - "blockalign:%d samplesperblock:%d", + msg_Dbg( p_dec, "format: samplerate:%d Hz channels:%d bits/sample:%d " + "blockalign:%zu samplesperblock:%zu", p_dec->fmt_in.audio.i_rate, p_dec->fmt_in.audio.i_channels, p_dec->fmt_in.audio.i_bitspersample, p_sys->i_block, p_sys->i_samplesperblock ); @@ -301,6 +325,9 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) DecodeAdpcmDk3( p_dec, (int16_t*)p_out->p_buffer, p_block->p_buffer ); break; + case ADPCM_EA: + DecodeAdpcmEA( p_dec, (int16_t*)p_out->p_buffer, + p_block->p_buffer ); default: break; } @@ -322,6 +349,8 @@ static void CloseDecoder( vlc_object_t *p_this ) decoder_t *p_dec = (decoder_t *)p_this; decoder_sys_t *p_sys = p_dec->p_sys; + if( p_sys->codec == ADPCM_EA ) + free( p_dec->fmt_in.p_extra ); free( p_sys ); } @@ -587,7 +616,7 @@ static void DecodeAdpcmDk4( decoder_t *p_dec, int16_t *p_sample, { decoder_sys_t *p_sys = p_dec->p_sys; adpcm_ima_wav_channel_t channel[2]; - int i_nibbles; + size_t i_nibbles; int b_stereo; b_stereo = p_dec->fmt_in.audio.i_channels == 2 ? 1 : 0; @@ -691,3 +720,74 @@ static void DecodeAdpcmDk3( decoder_t *p_dec, int16_t *p_sample, } } } + + +/* + * EA ADPCM + */ +#define MAX_CHAN 5 +static void DecodeAdpcmEA( decoder_t *p_dec, int16_t *p_sample, + uint8_t *p_buffer ) +{ + static const uint32_t EATable[]= + { + 0x00000000, 0x000000F0, 0x000001CC, 0x00000188, + 0x00000000, 0x00000000, 0xFFFFFF30, 0xFFFFFF24, + 0x00000000, 0x00000001, 0x00000003, 0x00000004, + 0x00000007, 0x00000008, 0x0000000A, 0x0000000B, + 0x00000000, 0xFFFFFFFF, 0xFFFFFFFD, 0xFFFFFFFC + }; + decoder_sys_t *p_sys = p_dec->p_sys; + uint8_t *p_end; + unsigned i_channels, c; + int16_t *prev, *cur; + int32_t c1[MAX_CHAN], c2[MAX_CHAN]; + int8_t d[MAX_CHAN]; + + i_channels = p_dec->fmt_in.audio.i_channels; + p_end = &p_buffer[p_sys->i_block]; + + prev = (int16_t *)p_dec->fmt_in.p_extra; + cur = prev + i_channels; + + for (c = 0; c < i_channels; c++) + { + uint8_t input; + + input = p_buffer[c]; + c1[c] = EATable[input >> 4]; + c2[c] = EATable[(input >> 4) + 4]; + d[c] = (input & 0xf) + 8; + } + + for( p_buffer += i_channels; p_buffer < p_end ; p_buffer += i_channels) + { + for (c = 0; c < i_channels; c++) + { + int32_t spl; + + spl = (p_buffer[c] >> 4) & 0xf; + spl = (spl << 0x1c) >> d[c]; + spl = (spl + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8; + CLAMP( spl, -32768, 32767 ); + prev[c] = cur[c]; + cur[c] = spl; + + *(p_sample++) = spl; + } + + for (c = 0; c < i_channels; c++) + { + int32_t spl; + + spl = p_buffer[c] & 0xf; + spl = (spl << 0x1c) >> d[c]; + spl = (spl + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8; + CLAMP( spl, -32768, 32767 ); + prev[c] = cur[c]; + cur[c] = spl; + + *(p_sample++) = spl; + } + } +}