Differentiate assembler and assembly in documentation and comments
[libav.git] / libavcodec / mpegaudiodecheader.c
CommitLineData
4bd8e17c
AJ
1/*
2 * MPEG Audio header decoder
406792e7 3 * Copyright (c) 2001, 2002 Fabrice Bellard
4bd8e17c 4 *
2912e87a 5 * This file is part of Libav.
4bd8e17c 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
4bd8e17c
AJ
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
4bd8e17c
AJ
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
2912e87a 18 * License along with Libav; if not, write to the Free Software
4bd8e17c
AJ
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
ba87f080 23 * @file
4bd8e17c
AJ
24 * MPEG Audio header decoder.
25 */
26
4bd8e17c
AJ
27#include "avcodec.h"
28#include "mpegaudio.h"
29#include "mpegaudiodata.h"
c6e1599b 30#include "mpegaudiodecheader.h"
4bd8e17c
AJ
31
32
82ab61f9 33int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
4bd8e17c
AJ
34{
35 int sample_rate, frame_size, mpeg25, padding;
36 int sample_rate_index, bitrate_index;
37 if (header & (1<<20)) {
38 s->lsf = (header & (1<<19)) ? 0 : 1;
39 mpeg25 = 0;
40 } else {
41 s->lsf = 1;
42 mpeg25 = 1;
43 }
44
45 s->layer = 4 - ((header >> 17) & 3);
46 /* extract frequency */
47 sample_rate_index = (header >> 10) & 3;
82ab61f9 48 sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
4bd8e17c
AJ
49 sample_rate_index += 3 * (s->lsf + mpeg25);
50 s->sample_rate_index = sample_rate_index;
51 s->error_protection = ((header >> 16) & 1) ^ 1;
52 s->sample_rate = sample_rate;
53
54 bitrate_index = (header >> 12) & 0xf;
55 padding = (header >> 9) & 1;
56 //extension = (header >> 8) & 1;
57 s->mode = (header >> 6) & 3;
58 s->mode_ext = (header >> 4) & 3;
59 //copyright = (header >> 3) & 1;
60 //original = (header >> 2) & 1;
61 //emphasis = header & 3;
62
63 if (s->mode == MPA_MONO)
64 s->nb_channels = 1;
65 else
66 s->nb_channels = 2;
67
68 if (bitrate_index != 0) {
82ab61f9 69 frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
4bd8e17c
AJ
70 s->bit_rate = frame_size * 1000;
71 switch(s->layer) {
72 case 1:
73 frame_size = (frame_size * 12000) / sample_rate;
74 frame_size = (frame_size + padding) * 4;
75 break;
76 case 2:
77 frame_size = (frame_size * 144000) / sample_rate;
78 frame_size += padding;
79 break;
80 default:
81 case 3:
82 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
83 frame_size += padding;
84 break;
85 }
86 s->frame_size = frame_size;
87 } else {
88 /* if no frame size computed, signal it */
89 return 1;
90 }
91
92#if defined(DEBUG)
dfd2a005 93 av_dlog(NULL, "layer%d, %d Hz, %d kbits/s, ",
4bd8e17c
AJ
94 s->layer, s->sample_rate, s->bit_rate);
95 if (s->nb_channels == 2) {
96 if (s->layer == 3) {
97 if (s->mode_ext & MODE_EXT_MS_STEREO)
dfd2a005 98 av_dlog(NULL, "ms-");
4bd8e17c 99 if (s->mode_ext & MODE_EXT_I_STEREO)
dfd2a005 100 av_dlog(NULL, "i-");
4bd8e17c 101 }
dfd2a005 102 av_dlog(NULL, "stereo");
4bd8e17c 103 } else {
dfd2a005 104 av_dlog(NULL, "mono");
4bd8e17c 105 }
dfd2a005 106 av_dlog(NULL, "\n");
4bd8e17c
AJ
107#endif
108 return 0;
109}
0199e00b 110
82ab61f9 111int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
0199e00b
MR
112{
113 MPADecodeHeader s1, *s = &s1;
114
115 if (ff_mpa_check_header(head) != 0)
116 return -1;
117
82ab61f9 118 if (avpriv_mpegaudio_decode_header(s, head) != 0) {
0199e00b
MR
119 return -1;
120 }
121
122 switch(s->layer) {
123 case 1:
36ef5369 124 avctx->codec_id = AV_CODEC_ID_MP1;
0199e00b
MR
125 *frame_size = 384;
126 break;
127 case 2:
36ef5369 128 avctx->codec_id = AV_CODEC_ID_MP2;
0199e00b
MR
129 *frame_size = 1152;
130 break;
131 default:
132 case 3:
36ef5369 133 avctx->codec_id = AV_CODEC_ID_MP3;
0199e00b
MR
134 if (s->lsf)
135 *frame_size = 576;
136 else
137 *frame_size = 1152;
138 break;
139 }
140
141 *sample_rate = s->sample_rate;
142 *channels = s->nb_channels;
143 *bit_rate = s->bit_rate;
0199e00b
MR
144 return s->frame_size;
145}