MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / decode_header

Function decode_header

modules/data/mp3/libmad/frame.c:115–228  ·  view source on GitHub ↗

* NAME: decode_header() * DESCRIPTION: read header data and following CRC word */

Source from the content-addressed store, hash-verified

113 * DESCRIPTION: read header data and following CRC word
114 */
115static
116int decode_header(struct mad_header *header, struct mad_stream *stream)
117{
118 unsigned int index;
119
120 header->flags = 0;
121 header->private_bits = 0;
122
123 /* header() */
124
125 /* syncword */
126 mad_bit_skip(&stream->ptr, 11);
127
128 /* MPEG 2.5 indicator (really part of syncword) */
129 if (mad_bit_read(&stream->ptr, 1) == 0)
130 header->flags |= MAD_FLAG_MPEG_2_5_EXT;
131
132 /* ID */
133 if (mad_bit_read(&stream->ptr, 1) == 0)
134 header->flags |= MAD_FLAG_LSF_EXT;
135 else if (header->flags & MAD_FLAG_MPEG_2_5_EXT) {
136 stream->error = MAD_ERROR_LOSTSYNC;
137 return -1;
138 }
139
140 /* layer */
141 header->layer = 4 - mad_bit_read(&stream->ptr, 2);
142
143 if (header->layer == 4) {
144 stream->error = MAD_ERROR_BADLAYER;
145 return -1;
146 }
147
148 /* protection_bit */
149 if (mad_bit_read(&stream->ptr, 1) == 0) {
150 header->flags |= MAD_FLAG_PROTECTION;
151 header->crc_check = mad_bit_crc(stream->ptr, 16, 0xffff);
152 }
153
154 /* bitrate_index */
155 index = mad_bit_read(&stream->ptr, 4);
156
157 if (index == 15) {
158 stream->error = MAD_ERROR_BADBITRATE;
159 return -1;
160 }
161
162 if (header->flags & MAD_FLAG_LSF_EXT)
163 header->bitrate = bitrate_table[3 + (header->layer >> 1)][index];
164 else
165 header->bitrate = bitrate_table[header->layer - 1][index];
166
167 /* sampling_frequency */
168 index = mad_bit_read(&stream->ptr, 2);
169
170 if (index == 3) {
171 stream->error = MAD_ERROR_BADSAMPLERATE;
172 return -1;

Callers 2

free_bitrateFunction · 0.85
mad_header_decodeFunction · 0.85

Calls 3

mad_bit_skipFunction · 0.85
mad_bit_readFunction · 0.85
mad_bit_crcFunction · 0.85

Tested by

no test coverage detected