annotate mpegaudiodecheader.c @ 9308:aad816bc3d54 libavcodec

Replacement reference DCT implementation. patch by Dylan Yudaken, dyudaken gmail com
author diego
date Tue, 31 Mar 2009 15:48:47 +0000
parents e9d9d946f213
children 30b00f4bdeb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
1 /*
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
2 * MPEG Audio header decoder
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 5051
diff changeset
3 * Copyright (c) 2001, 2002 Fabrice Bellard
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
4 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
6 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
11 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
16 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
20 */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
21
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
22 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8641
diff changeset
23 * @file libavcodec/mpegaudiodecheader.c
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
24 * MPEG Audio header decoder.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
25 */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
26
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
27 //#define DEBUG
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
28 #include "avcodec.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
29 #include "mpegaudio.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
30 #include "mpegaudiodata.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
31
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
32
8641
54e2916c25a5 Avoid allocating MPADecodeContext on stack.
andoma
parents: 8629
diff changeset
33 int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
34 {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
35 int sample_rate, frame_size, mpeg25, padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
36 int sample_rate_index, bitrate_index;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
37 if (header & (1<<20)) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
38 s->lsf = (header & (1<<19)) ? 0 : 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
39 mpeg25 = 0;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
40 } else {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
41 s->lsf = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
42 mpeg25 = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
43 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
44
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
45 s->layer = 4 - ((header >> 17) & 3);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
46 /* extract frequency */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
47 sample_rate_index = (header >> 10) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
48 sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
49 sample_rate_index += 3 * (s->lsf + mpeg25);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
50 s->sample_rate_index = sample_rate_index;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
51 s->error_protection = ((header >> 16) & 1) ^ 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
52 s->sample_rate = sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
53
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
54 bitrate_index = (header >> 12) & 0xf;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
55 padding = (header >> 9) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
56 //extension = (header >> 8) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
57 s->mode = (header >> 6) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
58 s->mode_ext = (header >> 4) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
59 //copyright = (header >> 3) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
60 //original = (header >> 2) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
61 //emphasis = header & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
62
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
63 if (s->mode == MPA_MONO)
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
64 s->nb_channels = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
65 else
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
66 s->nb_channels = 2;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
67
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
68 if (bitrate_index != 0) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
69 frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
70 s->bit_rate = frame_size * 1000;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
71 switch(s->layer) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
72 case 1:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
73 frame_size = (frame_size * 12000) / sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
74 frame_size = (frame_size + padding) * 4;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
75 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
76 case 2:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
77 frame_size = (frame_size * 144000) / sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
78 frame_size += padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
79 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
80 default:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
81 case 3:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
82 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
83 frame_size += padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
84 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
85 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
86 s->frame_size = frame_size;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
87 } else {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
88 /* if no frame size computed, signal it */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
89 return 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
90 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
91
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
92 #if defined(DEBUG)
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
93 dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ",
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
94 s->layer, s->sample_rate, s->bit_rate);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
95 if (s->nb_channels == 2) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
96 if (s->layer == 3) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
97 if (s->mode_ext & MODE_EXT_MS_STEREO)
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
98 dprintf(s->avctx, "ms-");
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
99 if (s->mode_ext & MODE_EXT_I_STEREO)
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
100 dprintf(s->avctx, "i-");
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
101 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
102 dprintf(s->avctx, "stereo");
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
103 } else {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
104 dprintf(s->avctx, "mono");
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
105 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
106 dprintf(s->avctx, "\n");
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
107 #endif
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
108 return 0;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
109 }