X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fadpcm.c;h=b052965920a53a875464f6c86128a4f3eb6054fa;hb=35f29374c21dec786285b781bf823371f25650cf;hp=7afc1f600a349871c3ff8d41fa224b1bece70793;hpb=d3fe7f28797d4dba65ffcdd60bf932e758a48a9e;p=vlc diff --git a/modules/codec/adpcm.c b/modules/codec/adpcm.c index 7afc1f600a..b052965920 100644 --- a/modules/codec/adpcm.c +++ b/modules/codec/adpcm.c @@ -1,25 +1,25 @@ /***************************************************************************** * adpcm.c : adpcm variant audio decoder ***************************************************************************** - * Copyright (C) 2001, 2002 the VideoLAN team + * Copyright (C) 2001, 2002 VLC authors and VideoLAN * $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 - * the Free Software Foundation; either version 2 of the License, or + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. * - * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -27,8 +27,12 @@ * * Documentation: http://www.pcisys.net/~melanson/codecs/adpcm.txt *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include /***************************************************************************** @@ -37,15 +41,15 @@ static int OpenDecoder( vlc_object_t * ); static void CloseDecoder( vlc_object_t * ); -static aout_buffer_t *DecodeBlock( decoder_t *, block_t ** ); +static block_t *DecodeBlock( decoder_t *, block_t ** ); -vlc_module_begin(); - set_description( _("ADPCM audio decoder") ); - set_capability( "decoder", 50 ); - set_category( CAT_INPUT ); - set_subcategory( SUBCAT_INPUT_ACODEC ); - set_callbacks( OpenDecoder, CloseDecoder ); -vlc_module_end(); +vlc_module_begin () + 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 () /***************************************************************************** * Local prototypes @@ -64,10 +68,10 @@ 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; + date_t end_date; }; static void DecodeAdpcmMs ( decoder_t *, int16_t *, uint8_t * ); @@ -77,7 +81,7 @@ 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, @@ -89,13 +93,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, @@ -108,18 +112,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 }; @@ -137,8 +141,8 @@ static int OpenDecoder( vlc_object_t *p_this ) case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ 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_CODEC_ADPCM_DK3: + case VLC_CODEC_ADPCM_DK4: case VLC_FOURCC('X','A','J', 0): /* EA ADPCM */ break; default: @@ -148,7 +152,7 @@ static int OpenDecoder( vlc_object_t *p_this ) if( p_dec->fmt_in.audio.i_channels <= 0 || p_dec->fmt_in.audio.i_channels > 5 ) { - msg_Err( p_dec, "invalid number of channel (not between 1 and 5): %i", + msg_Err( p_dec, "invalid number of channel (not between 1 and 5): %i", p_dec->fmt_in.audio.i_channels ); return VLC_EGENERIC; } @@ -162,26 +166,23 @@ static int OpenDecoder( vlc_object_t *p_this ) /* 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_ENOMEM; - } switch( p_dec->fmt_in.i_codec ) { case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ p_sys->codec = ADPCM_IMA_QT; break; - case VLC_FOURCC('m','s',0x00,0x11): /* IMA ADPCM */ + case VLC_CODEC_ADPCM_IMA_WAV: /* IMA ADPCM */ p_sys->codec = ADPCM_IMA_WAV; break; - case VLC_FOURCC('m','s',0x00,0x02): /* MS ADPCM */ + case VLC_CODEC_ADPCM_MS: /* MS ADPCM */ p_sys->codec = ADPCM_MS; break; - case VLC_FOURCC('m','s',0x00,0x61): /* Duck DK4 ADPCM */ + case VLC_CODEC_ADPCM_DK4: /* Duck DK4 ADPCM */ p_sys->codec = ADPCM_DK4; break; - case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ + case VLC_CODEC_ADPCM_DK3: /* Duck DK3 ADPCM */ p_sys->codec = ADPCM_DK3; break; case VLC_FOURCC('X','A','J', 0): /* EA ADPCM */ @@ -200,7 +201,7 @@ static int OpenDecoder( vlc_object_t *p_this ) { 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 { @@ -239,20 +240,21 @@ static int OpenDecoder( vlc_object_t *p_this ) } msg_Dbg( p_dec, "format: samplerate:%d Hz channels:%d bits/sample:%d " - "blockalign:%d samplesperblock:%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 ); - p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE; + p_dec->fmt_out.i_cat = AUDIO_ES; + p_dec->fmt_out.i_codec = VLC_CODEC_S16N; p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate; p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels; p_dec->fmt_out.audio.i_physical_channels = p_dec->fmt_out.audio.i_original_channels = pi_channels_maps[p_dec->fmt_in.audio.i_channels]; - aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate ); - aout_DateSet( &p_sys->end_date, 0 ); + date_Init( &p_sys->end_date, p_dec->fmt_out.audio.i_rate, 1 ); + date_Set( &p_sys->end_date, 0 ); p_dec->pf_decode_audio = DecodeBlock; @@ -262,7 +264,7 @@ static int OpenDecoder( vlc_object_t *p_this ) /***************************************************************************** * DecodeBlock: *****************************************************************************/ -static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) +static block_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) { decoder_sys_t *p_sys = p_dec->p_sys; block_t *p_block; @@ -271,12 +273,12 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) p_block = *pp_block; - if( p_block->i_pts != 0 && - p_block->i_pts != aout_DateGet( &p_sys->end_date ) ) + if( p_block->i_pts > VLC_TS_INVALID && + p_block->i_pts != date_Get( &p_sys->end_date ) ) { - aout_DateSet( &p_sys->end_date, p_block->i_pts ); + date_Set( &p_sys->end_date, p_block->i_pts ); } - else if( !aout_DateGet( &p_sys->end_date ) ) + else if( !date_Get( &p_sys->end_date ) ) { /* We've just started the stream, wait for the first PTS. */ block_Release( p_block ); @@ -284,22 +286,22 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) } /* Don't re-use the same pts twice */ - p_block->i_pts = 0; + p_block->i_pts = VLC_TS_INVALID; if( p_block->i_buffer >= p_sys->i_block ) { - aout_buffer_t *p_out; + block_t *p_out; - p_out = p_dec->pf_aout_buffer_new( p_dec, p_sys->i_samplesperblock ); + p_out = decoder_NewAudioBuffer( p_dec, p_sys->i_samplesperblock ); if( p_out == NULL ) { block_Release( p_block ); return NULL; } - p_out->start_date = aout_DateGet( &p_sys->end_date ); - p_out->end_date = - aout_DateIncrement( &p_sys->end_date, p_sys->i_samplesperblock ); + p_out->i_pts = date_Get( &p_sys->end_date ); + p_out->i_length = date_Increment( &p_sys->end_date, + p_sys->i_samplesperblock ) - p_out->i_pts; switch( p_sys->codec ) { @@ -614,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; @@ -727,65 +729,56 @@ static void DecodeAdpcmDk3( decoder_t *p_dec, int16_t *p_sample, static void DecodeAdpcmEA( decoder_t *p_dec, int16_t *p_sample, uint8_t *p_buffer ) { - static const uint32_t EATable[]= + static const int16_t EATable[]= { - 0x00000000, 0x000000F0, 0x000001CC, 0x00000188, - 0x00000000, 0x00000000, 0xFFFFFF30, 0xFFFFFF24, - 0x00000000, 0x00000001, 0x00000003, 0x00000004, - 0x00000007, 0x00000008, 0x0000000A, 0x0000000B, - 0x00000000, 0xFFFFFFFF, 0xFFFFFFFD, 0xFFFFFFFC + 0x0000, 0x00F0, 0x01CC, 0x0188, 0x0000, 0x0000, 0xFF30, 0xFF24, + 0x0000, 0x0001, 0x0003, 0x0004, 0x0007, 0x0008, 0x000A, 0x000B, + 0x0000, 0xFFFF, 0xFFFD, 0xFFFC, }; 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]; + int_fast32_t c1[MAX_CHAN], c2[MAX_CHAN]; + int_fast8_t d[MAX_CHAN]; - prev = (int16_t *)p_dec->fmt_in.p_extra; - cur = prev + i_channels; + unsigned chans = p_dec->fmt_in.audio.i_channels; + const uint8_t *p_end = &p_buffer[p_sys->i_block]; + int16_t *prev = (int16_t *)p_dec->fmt_in.p_extra; + int16_t *cur = prev + chans; - for (c = 0; c < i_channels; c++) + for (unsigned c = 0; c < chans; c++) { - uint8_t input; + uint8_t input = p_buffer[c]; - 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 (p_buffer += chans; p_buffer < p_end; p_buffer += chans) { - for (c = 0; c < i_channels; c++) - { - int32_t spl; + union { uint32_t u; int32_t i; } 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 ); + for (unsigned c = 0; c < chans; c++) + { + spl.u = (p_buffer[c] & 0xf0u) << 24u; + spl.i >>= d[c]; + spl.i = (spl.i + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8; + CLAMP(spl.i, -32768, 32767); prev[c] = cur[c]; - cur[c] = spl; + cur[c] = spl.i; - *(p_sample++) = spl; + *(p_sample++) = spl.i; } - for (c = 0; c < i_channels; c++) + for (unsigned c = 0; c < chans; 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 ); + spl.u = (p_buffer[c] & 0x0fu) << 28u; + spl.i >>= d[c]; + spl.i = (spl.i + cur[c] * c1[c] + prev[c] * c2[c] + 0x80) >> 8; + CLAMP(spl.i, -32768, 32767); prev[c] = cur[c]; - cur[c] = spl; + cur[c] = spl.i; - *(p_sample++) = spl; + *(p_sample++) = spl.i; } } }