dithering for the mpeg audio decoder

Originally committed as revision 3903 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2005-01-30 14:04:56 +00:00
parent 16dd93ab6a
commit a7a858996f
5 changed files with 47 additions and 45 deletions

View File

@ -18,6 +18,10 @@
#define MPA_DUAL 2
#define MPA_MONO 3
/* header + layer + bitrate + freq + lsf/mpeg25 */
#define SAME_HEADER_MASK \
(0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
int mpa_decode_header(AVCodecContext *avctx, uint32_t head);
@ -29,3 +33,20 @@ extern const int sblimit_table[5];
extern const int quant_steps[17];
extern const int quant_bits[17];
extern const int32_t mpa_enwindow[257];
/* fast header check for resync */
static inline int ff_mpa_check_header(uint32_t header){
/* header */
if ((header & 0xffe00000) != 0xffe00000)
return -1;
/* layer check */
if ((header & (3<<17)) == 0)
return -1;
/* bit rate */
if ((header & (0xf<<12)) == 0xf<<12)
return -1;
/* frequency */
if ((header & (3<<10)) == 3<<10)
return -1;
return 0;
}

View File

@ -99,6 +99,7 @@ typedef struct MPADecodeContext {
#endif
void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
unsigned int dither_state;
} MPADecodeContext;
/* layer 3 "granule" */
@ -749,10 +750,11 @@ static void dct32(int32_t *out, int32_t *tab)
#if FRAC_BITS <= 15
static inline int round_sample(int sum)
static inline int round_sample(int *sum)
{
int sum1;
sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;
sum1 = (*sum) >> OUT_SHIFT;
*sum &= (1<<OUT_SHIFT)-1;
if (sum1 < -32768)
sum1 = -32768;
else if (sum1 > 32767)
@ -782,10 +784,11 @@ static inline int round_sample(int sum)
#else
static inline int round_sample(int64_t sum)
static inline int round_sample(int64_t *sum)
{
int sum1;
sum1 = (int)((sum + (int64_t_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);
sum1 = (int)((*sum) >> OUT_SHIFT);
*sum &= (1<<OUT_SHIFT)-1;
if (sum1 < -32768)
sum1 = -32768;
else if (sum1 > 32767)
@ -900,37 +903,37 @@ void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
w = window;
w2 = window + 31;
sum = 0;
sum = s1->dither_state;
p = synth_buf + 16;
SUM8(sum, +=, w, p);
p = synth_buf + 48;
SUM8(sum, -=, w + 32, p);
*samples = round_sample(sum);
*samples = round_sample(&sum);
samples += incr;
w++;
/* we calculate two samples at the same time to avoid one memory
access per two sample */
for(j=1;j<16;j++) {
sum = 0;
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, +=, sum2, -=, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, -=, sum2, -=, w + 32, w2 + 32, p);
*samples = round_sample(sum);
*samples = round_sample(&sum);
samples += incr;
*samples2 = round_sample(sum2);
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
sum = 0;
SUM8(sum, -=, w + 32, p);
*samples = round_sample(sum);
*samples = round_sample(&sum);
s1->dither_state= sum;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
@ -1115,28 +1118,6 @@ static void imdct36(int *out, int *in)
out[8 - 4] = t1;
}
/* fast header check for resync */
static int check_header(uint32_t header)
{
/* header */
if ((header & 0xffe00000) != 0xffe00000)
return -1;
/* layer check */
if (((header >> 17) & 3) == 0)
return -1;
/* bit rate */
if (((header >> 12) & 0xf) == 0xf)
return -1;
/* frequency */
if (((header >> 10) & 3) == 3)
return -1;
return 0;
}
/* header + layer + bitrate + freq + lsf/mpeg25 */
#define SAME_HEADER_MASK \
(0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
/* header decoding. MUST check the header before because no
consistency check is done there. Return 1 if free format found and
that the frame size must be computed externally */
@ -1244,7 +1225,7 @@ int mpa_decode_header(AVCodecContext *avctx, uint32_t head)
MPADecodeContext s1, *s = &s1;
memset( s, 0, sizeof(MPADecodeContext) );
if (check_header(head) != 0)
if (ff_mpa_check_header(head) != 0)
return -1;
if (decode_header(s, head) != 0) {
@ -2566,7 +2547,7 @@ static int decode_frame(AVCodecContext * avctx,
header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
(s->inbuf[2] << 8) | s->inbuf[3];
if (check_header(header) < 0) {
if (ff_mpa_check_header(header) < 0) {
/* no sync found : move by one byte (inefficient, but simple!) */
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
s->inbuf_ptr--;
@ -2712,7 +2693,7 @@ static int decode_frame_adu(AVCodecContext * avctx,
header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
(s->inbuf[2] << 8) | s->inbuf[3] | 0xffe00000;
if (check_header(header) < 0) { // Bad header, discard frame
if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame
*data_size = 0;
return buf_size;
}

View File

@ -125,8 +125,8 @@ ccc201054669e94717022bb4f2aea4ce *./data/out.yuv
stddev: 10.99 PSNR:27.30 bytes:7602176
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
95712 ./data/a-mp2.mp2
91ab1b253cd360037d3fca67b795aba8 *./data/out.wav
stddev:117.02 PSNR: 6.75 bytes:1054720
6956f2c5185c4edbae648c614992a14b *./data/out.wav
stddev:117.02 PSNR: 6.76 bytes:1054720
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
97983 ./data/a-ac3.rm
2d081e0e1f2e9bd4514e9ac8ec41884c *./data/a-g726.wav

View File

@ -1,21 +1,21 @@
ffmpeg regression test
8517e7c83227074b8d632477fda310d5 *./data/b-libav.avi
342282 ./data/b-libav.avi
./data/b-libav.avi CRC=001a3415
./data/b-libav.avi CRC=ccab3a27
c83444a0e8ef47b6af1d868d1bb21696 *./data/b-libav.asf
342967 ./data/b-libav.asf
./data/b-libav.asf CRC=750f18c7
./data/b-libav.asf CRC=41af1ed9
5240a23a9264bc6062d6739c70825ace *./data/b-libav.rm
360251 ./data/b-libav.rm
90784a1b9589095f20fc6bcc0cc23cc4 *./data/b-libav.mpg
387072 ./data/b-libav.mpg
./data/b-libav.mpg CRC=16c74225
./data/b-libav.mpg CRC=8b644837
57a8dfc7926802bb337a9d8918de94a8 *./data/b-libav.swf
41816 ./data/b-libav.swf
./data/b-libav.swf CRC=2b273fea
2b06388316770915293edcbcc693beef *./data/b-libav.ffm
389120 ./data/b-libav.ffm
./data/b-libav.ffm CRC=f765cbdd
./data/b-libav.ffm CRC=688bd1eb
794934a02582f8dfc85d1856514cf37c *./data/b-libav.flv
339325 ./data/b-libav.flv
./data/b-libav.flv CRC=7b9076f8
@ -24,7 +24,7 @@ c83444a0e8ef47b6af1d868d1bb21696 *./data/b-libav.asf
./data/b-libav.mov CRC=da87a90d
fea20ced22451312dd463110e594eda6 *./data/b-libav.nut
332415 ./data/b-libav.nut
./data/b-libav.nut CRC=001a3415
./data/b-libav.nut CRC=ccab3a27
29a2c312bbc5b187491183a918556475 *./data/b-libav.dv
3600000 ./data/b-libav.dv
./data/b-libav.dv CRC=37b096b4

View File

@ -125,8 +125,8 @@ stddev: 0.00 PSNR:99.99 bytes:7602176
stddev: 3.43 PSNR:37.39 bytes:7602176
21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2
95712 ./data/a-mp2.mp2
91ab1b253cd360037d3fca67b795aba8 *./data/out.wav
stddev:117.02 PSNR: 6.75 bytes:1054720
6956f2c5185c4edbae648c614992a14b *./data/out.wav
stddev:117.02 PSNR: 6.76 bytes:1054720
d056da679e6d6682812fffb28a7f0db6 *./data/a-ac3.rm
97983 ./data/a-ac3.rm
2d081e0e1f2e9bd4514e9ac8ec41884c *./data/a-g726.wav