summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/mpegaudiodec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/mpegaudiodec.c')
-rw-r--r--src/libffmpeg/libavcodec/mpegaudiodec.c137
1 files changed, 109 insertions, 28 deletions
diff --git a/src/libffmpeg/libavcodec/mpegaudiodec.c b/src/libffmpeg/libavcodec/mpegaudiodec.c
index b08f83757..09e9b8cdb 100644
--- a/src/libffmpeg/libavcodec/mpegaudiodec.c
+++ b/src/libffmpeg/libavcodec/mpegaudiodec.c
@@ -25,6 +25,7 @@
//#define DEBUG
#include "avcodec.h"
#include "mpegaudio.h"
+#include "dsputil.h"
/*
* TODO:
@@ -66,6 +67,8 @@ typedef int32_t MPA_INT;
#define HEADER_SIZE 4
#define BACKSTEP_SIZE 512
+struct GranuleDef;
+
typedef struct MPADecodeContext {
uint8_t inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */
int inbuf_index;
@@ -93,6 +96,7 @@ typedef struct MPADecodeContext {
#ifdef DEBUG
int frame_count;
#endif
+ void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
} MPADecodeContext;
/* layer 3 "granule" */
@@ -127,6 +131,9 @@ typedef struct HuffTable {
#include "mpegaudiodectab.h"
+static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g);
+static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g);
+
/* vlc structure for decoding layer 3 huffman tables */
static VLC huff_vlc[16];
static uint8_t *huff_code_table[16];
@@ -144,7 +151,8 @@ static uint32_t *table_4_3_value;
/* intensity stereo coef table */
static int32_t is_table[2][16];
static int32_t is_table_lsf[2][2][16];
-static int32_t csa_table[8][2];
+static int32_t csa_table[8][4];
+static float csa_table_float[8][4];
static int32_t mdct_win[8][36];
/* lower 2 bits: modulo 3, higher bits: shift */
@@ -310,6 +318,11 @@ static int decode_init(AVCodecContext * avctx)
static int init=0;
int i, j, k;
+ if(avctx->antialias_algo == FF_AA_INT)
+ s->compute_antialias= compute_antialias_integer;
+ else
+ s->compute_antialias= compute_antialias_float;
+
if (!init && !avctx->parse_only) {
/* scale factors table for layer 1/2 */
for(i=0;i<64;i++) {
@@ -462,6 +475,13 @@ static int decode_init(AVCodecContext * avctx)
ca = cs * ci;
csa_table[i][0] = FIX(cs);
csa_table[i][1] = FIX(ca);
+ csa_table[i][2] = FIX(ca) + FIX(cs);
+ csa_table[i][3] = FIX(ca) - FIX(cs);
+ csa_table_float[i][0] = cs;
+ csa_table_float[i][1] = ca;
+ csa_table_float[i][2] = ca + cs;
+ csa_table_float[i][3] = ca - cs;
+// printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
}
/* compute mdct windows */
@@ -1206,17 +1226,11 @@ static int decode_header(MPADecodeContext *s, uint32_t header)
return 0;
}
-#if 0
/* useful helper to get mpeg audio stream infos. Return -1 if error in
- header */
-int mp_decode_header(int *sample_rate_ptr,
- int *nb_channels_ptr,
- int *coded_frame_size_ptr,
- int *decoded_frame_size_ptr,
- uint32_t head)
+ header, otherwise the coded frame size in bytes */
+int mpa_decode_header(AVCodecContext *avctx, uint32_t head)
{
MPADecodeContext s1, *s = &s1;
- int decoded_frame_size;
if (check_header(head) != 0)
return -1;
@@ -1227,27 +1241,26 @@ int mp_decode_header(int *sample_rate_ptr,
switch(s->layer) {
case 1:
- decoded_frame_size = 384;
+ avctx->frame_size = 384;
break;
case 2:
- decoded_frame_size = 1152;
+ avctx->frame_size = 1152;
break;
default:
case 3:
if (s->lsf)
- decoded_frame_size = 576;
+ avctx->frame_size = 576;
else
- decoded_frame_size = 1152;
+ avctx->frame_size = 1152;
break;
}
- *sample_rate_ptr = s->sample_rate;
- *nb_channels_ptr = s->nb_channels;
- *coded_frame_size_ptr = s->frame_size;
- *decoded_frame_size_ptr = decoded_frame_size * 2 * s->nb_channels;
- return 0;
+ avctx->sample_rate = s->sample_rate;
+ avctx->channels = s->nb_channels;
+ avctx->bit_rate = s->bit_rate;
+ avctx->sub_id = s->layer;
+ return s->frame_size;
}
-#endif
/* return the number of decoded frames */
static int mp_decode_layer1(MPADecodeContext *s)
@@ -1899,11 +1912,11 @@ static void compute_stereo(MPADecodeContext *s,
}
}
-static void compute_antialias(MPADecodeContext *s,
+static void compute_antialias_integer(MPADecodeContext *s,
GranuleDef *g)
{
int32_t *ptr, *p0, *p1, *csa;
- int n, tmp0, tmp1, i, j;
+ int n, i, j;
/* we antialias only "long" bands */
if (g->block_type == 2) {
@@ -1919,17 +1932,85 @@ static void compute_antialias(MPADecodeContext *s,
for(i = n;i > 0;i--) {
p0 = ptr - 1;
p1 = ptr;
- csa = &csa_table[0][0];
- for(j=0;j<8;j++) {
+ csa = &csa_table[0][0];
+ for(j=0;j<4;j++) {
+ int tmp0 = *p0;
+ int tmp1 = *p1;
+#if 0
+ *p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1]));
+ *p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0]));
+#else
+ int64_t tmp2= MUL64(tmp0 + tmp1, csa[0]);
+ *p0 = FRAC_RND(tmp2 - MUL64(tmp1, csa[2]));
+ *p1 = FRAC_RND(tmp2 + MUL64(tmp0, csa[3]));
+#endif
+ p0--; p1++;
+ csa += 4;
tmp0 = *p0;
tmp1 = *p1;
+#if 0
*p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1]));
*p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0]));
- p0--;
- p1++;
- csa += 2;
+#else
+ tmp2= MUL64(tmp0 + tmp1, csa[0]);
+ *p0 = FRAC_RND(tmp2 - MUL64(tmp1, csa[2]));
+ *p1 = FRAC_RND(tmp2 + MUL64(tmp0, csa[3]));
+#endif
+ p0--; p1++;
+ csa += 4;
}
- ptr += 18;
+ ptr += 18;
+ }
+}
+
+static void compute_antialias_float(MPADecodeContext *s,
+ GranuleDef *g)
+{
+ int32_t *ptr, *p0, *p1;
+ int n, i, j;
+
+ /* we antialias only "long" bands */
+ if (g->block_type == 2) {
+ if (!g->switch_point)
+ return;
+ /* XXX: check this for 8000Hz case */
+ n = 1;
+ } else {
+ n = SBLIMIT - 1;
+ }
+
+ ptr = g->sb_hybrid + 18;
+ for(i = n;i > 0;i--) {
+ float *csa = &csa_table_float[0][0];
+ p0 = ptr - 1;
+ p1 = ptr;
+ for(j=0;j<4;j++) {
+ float tmp0 = *p0;
+ float tmp1 = *p1;
+#if 1
+ *p0 = lrintf(tmp0 * csa[0] - tmp1 * csa[1]);
+ *p1 = lrintf(tmp0 * csa[1] + tmp1 * csa[0]);
+#else
+ float tmp2= (tmp0 + tmp1) * csa[0];
+ *p0 = lrintf(tmp2 - tmp1 * csa[2]);
+ *p1 = lrintf(tmp2 + tmp0 * csa[3]);
+#endif
+ p0--; p1++;
+ csa += 4;
+ tmp0 = *p0;
+ tmp1 = *p1;
+#if 1
+ *p0 = lrintf(tmp0 * csa[0] - tmp1 * csa[1]);
+ *p1 = lrintf(tmp0 * csa[1] + tmp1 * csa[0]);
+#else
+ tmp2= (tmp0 + tmp1) * csa[0];
+ *p0 = lrintf(tmp2 - tmp1 * csa[2]);
+ *p1 = lrintf(tmp2 + tmp0 * csa[3]);
+#endif
+ p0--; p1++;
+ csa += 4;
+ }
+ ptr += 18;
}
}
@@ -2359,7 +2440,7 @@ static int mp_decode_layer3(MPADecodeContext *s)
#if defined(DEBUG)
sample_dump(0, g->sb_hybrid, 576);
#endif
- compute_antialias(s, g);
+ s->compute_antialias(s, g);
#if defined(DEBUG)
sample_dump(1, g->sb_hybrid, 576);
#endif