FastLED 3.9.15
Loading...
Searching...
No Matches

◆ UnpackFrameHeader()

int fl::third_party::UnpackFrameHeader ( MP3DecInfo * mp3DecInfo,
const unsigned char * buf )

Definition at line 223 of file bitstream.hpp.

224{
225
226 int verIdx;
227 FrameHeader *fh;
228
229 /* validate pointers and sync word */
230 if (!mp3DecInfo || !mp3DecInfo->FrameHeaderPS || (buf[0] & SYNCWORDH) != SYNCWORDH || (buf[1] & SYNCWORDL) != SYNCWORDL)
231 return -1;
232
233 fh = ((FrameHeader *)(mp3DecInfo->FrameHeaderPS));
234
235 /* read header fields - use bitmasks instead of GetBits() for speed, since format never varies */
236 verIdx = (buf[1] >> 3) & 0x03;
237 fh->ver = (MPEGVersion)( verIdx == 0 ? MPEG25 : ((verIdx & 0x01) ? MPEG1 : MPEG2) );
238 fh->layer = 4 - ((buf[1] >> 1) & 0x03); /* easy mapping of index to layer number, 4 = error */
239 fh->crc = 1 - ((buf[1] >> 0) & 0x01);
240 fh->brIdx = (buf[2] >> 4) & 0x0f;
241 fh->srIdx = (buf[2] >> 2) & 0x03;
242 fh->paddingBit = (buf[2] >> 1) & 0x01;
243 fh->privateBit = (buf[2] >> 0) & 0x01;
244 fh->sMode = (StereoMode)((buf[3] >> 6) & 0x03); /* maps to correct enum (see definition) */
245 fh->modeExt = (buf[3] >> 4) & 0x03;
246 fh->copyFlag = (buf[3] >> 3) & 0x01;
247 fh->origFlag = (buf[3] >> 2) & 0x01;
248 fh->emphasis = (buf[3] >> 0) & 0x03;
249
250 /* check parameters to avoid indexing tables with bad values */
251 if (fh->srIdx == 3 || fh->layer == 4 || fh->brIdx == 15)
252 return -1;
253
254 fh->sfBand = &sfBandTable[fh->ver][fh->srIdx]; /* for readability (we reference sfBandTable many times in decoder) */
255 if (fh->sMode != Joint) /* just to be safe (dequant, stproc check fh->modeExt) */
256 fh->modeExt = 0;
257
258 /* init user-accessible data */
259 mp3DecInfo->nChans = (fh->sMode == Mono ? 1 : 2);
260 mp3DecInfo->samprate = samplerateTab[fh->ver][fh->srIdx];
261 mp3DecInfo->nGrans = (fh->ver == MPEG1 ? NGRANS_MPEG1 : NGRANS_MPEG2);
262 mp3DecInfo->nGranSamps = ((int)samplesPerFrameTab[fh->ver][fh->layer - 1]) / mp3DecInfo->nGrans;
263 mp3DecInfo->layer = fh->layer;
264 mp3DecInfo->version = fh->ver;
265
266 /* get bitrate and nSlots from table, unless brIdx == 0 (free mode) in which case caller must figure it out himself
267 * question - do we want to overwrite mp3DecInfo->bitrate with 0 each time if it's free mode, and
268 * copy the pre-calculated actual free bitrate into it in mp3dec.c (according to the spec,
269 * this shouldn't be necessary, since it should be either all frames free or none free)
270 */
271 if (fh->brIdx) {
272 mp3DecInfo->bitrate = ((int)bitrateTab[fh->ver][fh->layer - 1][fh->brIdx]) * 1000;
273
274 /* nSlots = total frame bytes (from table) - sideInfo bytes - header - CRC (if present) + pad (if present) */
275 mp3DecInfo->nSlots = (int)slotTab[fh->ver][fh->srIdx][fh->brIdx] -
276 (int)sideBytesTab[fh->ver][(fh->sMode == Mono ? 0 : 1)] -
277 4 - (fh->crc ? 2 : 0) + (fh->paddingBit ? 1 : 0);
278 }
279
280 /* load crc word, if enabled, and return length of frame header (in bytes) */
281 if (fh->crc) {
282 fh->CRCWord = ((int)buf[4] << 8 | (int)buf[5] << 0);
283 return 6;
284 } else {
285 fh->CRCWord = 0;
286 return 4;
287 }
288}
StereoMode
Definition coder.h:143
@ Mono
Definition coder.h:147
@ Joint
Definition coder.h:145
#define NGRANS_MPEG2
Definition mp3common.h:54
#define SYNCWORDL
Definition mp3common.h:64
#define SYNCWORDH
Definition mp3common.h:63
#define NGRANS_MPEG1
Definition mp3common.h:53
MPEGVersion version
Definition mp3common.h:91
void * FrameHeaderPS
Definition mp3common.h:68
int nGranSamps
Definition mp3common.h:88
MPEGVersion
Definition mp3dec.h:82
@ MPEG25
Definition mp3dec.h:85
@ MPEG2
Definition mp3dec.h:84
@ MPEG1
Definition mp3dec.h:83
const short slotTab[3][3][15]
Definition mp3tabs.hpp:110
const short sideBytesTab[3][2]
Definition mp3tabs.hpp:100
const int32_t samplerateTab[3][3]
Definition mp3tabs.hpp:53
struct fl::third_party::_FrameHeader FrameHeader
const short samplesPerFrameTab[3][3]
Definition mp3tabs.hpp:88
const SFBandTable sfBandTable[3][3]
Definition mp3tabs.hpp:135
const short bitrateTab[3][3][15]
Definition mp3tabs.hpp:64
const SFBandTable * sfBand
Definition coder.h:175

References bitrateTab, fl::third_party::_FrameHeader::brIdx, fl::third_party::_FrameHeader::copyFlag, fl::third_party::_FrameHeader::crc, fl::third_party::_FrameHeader::CRCWord, fl::third_party::_FrameHeader::emphasis, FL_NOEXCEPT, Joint, fl::third_party::_FrameHeader::layer, fl::third_party::_FrameHeader::modeExt, Mono, MPEG1, MPEG2, MPEG25, NGRANS_MPEG1, NGRANS_MPEG2, fl::third_party::_FrameHeader::origFlag, fl::third_party::_FrameHeader::paddingBit, fl::third_party::_FrameHeader::privateBit, samplerateTab, samplesPerFrameTab, fl::third_party::_FrameHeader::sfBand, sfBandTable, sideBytesTab, slotTab, fl::third_party::_FrameHeader::sMode, fl::third_party::_FrameHeader::srIdx, SYNCWORDH, SYNCWORDL, and fl::third_party::_FrameHeader::ver.

Referenced by MP3Decode(), and MP3GetNextFrameInfo().

+ Here is the caller graph for this function: