Commit 949ed6bb authored by Michael Niedermayer's avatar Michael Niedermayer

use bytestream reader instead of bitstream for THP

5% smaller adpcm.o
20% faster

Originally committed as revision 8657 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8e952e4d
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
*/ */
#include "avcodec.h" #include "avcodec.h"
#include "bitstream.h" #include "bitstream.h"
#include "bytestream.h"
/** /**
* @file adpcm.c * @file adpcm.c
...@@ -1317,7 +1318,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, ...@@ -1317,7 +1318,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
break; break;
case CODEC_ID_ADPCM_THP: case CODEC_ID_ADPCM_THP:
{ {
GetBitContext gb;
int table[2][16]; int table[2][16];
unsigned int samplecnt; unsigned int samplecnt;
int prev[2][2]; int prev[2][2];
...@@ -1328,18 +1328,15 @@ static int adpcm_decode_frame(AVCodecContext *avctx, ...@@ -1328,18 +1328,15 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
return -1; return -1;
} }
init_get_bits(&gb, src, buf_size * 8); src+=4;
src += buf_size; samplecnt = bytestream_get_be32(&src);
get_bits_long(&gb, 32); /* Channel size */
samplecnt = get_bits_long(&gb, 32);
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
table[0][i] = get_sbits(&gb, 16); table[0][i] = (int16_t)bytestream_get_be16(&src);
/* Initialize the previous sample. */ /* Initialize the previous sample. */
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
prev[0][i] = get_sbits(&gb, 16); prev[0][i] = (int16_t)bytestream_get_be16(&src);
if (samplecnt >= (samples_end - samples) / (st + 1)) { if (samplecnt >= (samples_end - samples) / (st + 1)) {
av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n");
...@@ -1351,17 +1348,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, ...@@ -1351,17 +1348,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx,
/* Read in every sample for this channel. */ /* Read in every sample for this channel. */
for (i = 0; i < samplecnt / 14; i++) { for (i = 0; i < samplecnt / 14; i++) {
int index = get_bits (&gb, 4) & 7; int index = (*src >> 4) & 7;
unsigned int exp = get_bits (&gb, 4); unsigned int exp = 28 - (*src++ & 15);
int factor1 = table[ch][index * 2]; int factor1 = table[ch][index * 2];
int factor2 = table[ch][index * 2 + 1]; int factor2 = table[ch][index * 2 + 1];
/* Decode 14 samples. */ /* Decode 14 samples. */
for (n = 0; n < 14; n++) { for (n = 0; n < 14; n++) {
int sampledat = get_sbits (&gb, 4); int32_t sampledat;
if(n&1) sampledat= *src++ <<28;
else sampledat= (*src&0xF0)<<24;
*samples = ((prev[ch][0]*factor1 *samples = ((prev[ch][0]*factor1
+ prev[ch][1]*factor2) >> 11) + (sampledat << exp); + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
prev[ch][1] = prev[ch][0]; prev[ch][1] = prev[ch][0];
prev[ch][0] = *samples++; prev[ch][0] = *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