Path: blob/master/libs/mpg123/src/libmpg123/mpeghead.h
4394 views
/*1mpeghead: the bits of an MPEG frame header23copyright ?-2011 by the mpg123 project - free software under the terms of the LGPL 2.14see COPYING and AUTHORS files in distribution or http://mpg123.org5initially written by Michael Hipp & Thomas Orgis (from parse.c)6*/7#ifndef MPG123_MPEGHEAD_H8#define MPG123_MPEGHEAD_H910/*11Avoid human error, let perl do the work of dissecting an MPEG header into parts.12To be clear: Never edit the following definitions by hand, modify the code block inside this comment and run it through perl instead!1314$head = "AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM";15%parts = qw(A sync B version C layer D crc E bitrate F samplerate G padding H private I channel J chanex K copyright L original M emphasis);16for(sort keys %parts)17{18$name = uc($parts{$_});19$bits = $head;20$bits =~ s/$_/1/g;21$bits =~ s/[^1 ]/0/g;22print "\/\* $bits \*\/\n";23$bits =~ s/\s//g;24print "#define HDR_$name".(" " x (18-length($name))).sprintf("0x%08x", eval("0b$bits"))."\n";25$bits =~ m/(0*)$/;26print "#define HDR_${name}_VAL(h)".(" " x (11-length($name)))."(((h)\&HDR_$name) >> ".length($1).")\n";27}28*/2930/* 11111111 11100000 00000000 00000000 */31#define HDR_SYNC 0xffe0000032#define HDR_SYNC_VAL(h) (((h)&HDR_SYNC) >> 21)33/* 00000000 00011000 00000000 00000000 */34#define HDR_VERSION 0x0018000035#define HDR_VERSION_VAL(h) (((h)&HDR_VERSION) >> 19)36/* 00000000 00000110 00000000 00000000 */37#define HDR_LAYER 0x0006000038#define HDR_LAYER_VAL(h) (((h)&HDR_LAYER) >> 17)39/* 00000000 00000001 00000000 00000000 */40#define HDR_CRC 0x0001000041#define HDR_CRC_VAL(h) (((h)&HDR_CRC) >> 16)42/* 00000000 00000000 11110000 00000000 */43#define HDR_BITRATE 0x0000f00044#define HDR_BITRATE_VAL(h) (((h)&HDR_BITRATE) >> 12)45/* 00000000 00000000 00001100 00000000 */46#define HDR_SAMPLERATE 0x00000c0047#define HDR_SAMPLERATE_VAL(h) (((h)&HDR_SAMPLERATE) >> 10)48/* 00000000 00000000 00000010 00000000 */49#define HDR_PADDING 0x0000020050#define HDR_PADDING_VAL(h) (((h)&HDR_PADDING) >> 9)51/* 00000000 00000000 00000001 00000000 */52#define HDR_PRIVATE 0x0000010053#define HDR_PRIVATE_VAL(h) (((h)&HDR_PRIVATE) >> 8)54/* 00000000 00000000 00000000 11000000 */55#define HDR_CHANNEL 0x000000c056#define HDR_CHANNEL_VAL(h) (((h)&HDR_CHANNEL) >> 6)57/* 00000000 00000000 00000000 00110000 */58#define HDR_CHANEX 0x0000003059#define HDR_CHANEX_VAL(h) (((h)&HDR_CHANEX) >> 4)60/* 00000000 00000000 00000000 00001000 */61#define HDR_COPYRIGHT 0x0000000862#define HDR_COPYRIGHT_VAL(h) (((h)&HDR_COPYRIGHT) >> 3)63/* 00000000 00000000 00000000 00000100 */64#define HDR_ORIGINAL 0x0000000465#define HDR_ORIGINAL_VAL(h) (((h)&HDR_ORIGINAL) >> 2)66/* 00000000 00000000 00000000 00000011 */67#define HDR_EMPHASIS 0x0000000368#define HDR_EMPHASIS_VAL(h) (((h)&HDR_EMPHASIS) >> 0)6970/*71A generic mask for telling if a header is somewhat valid for the current stream.72Meaning: Most basic info is not allowed to change.73Checking of channel count needs to be done, too, though. So,74if channel count matches, frames are decoded the same way: frame buffers and decoding75routines can stay the same, especially frame buffers (think spf * channels!).76*/77#define HDR_CMPMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_SAMPLERATE)7879/* A stricter mask, for matching free format headers. */80#define HDR_SAMEMASK (HDR_SYNC|HDR_VERSION|HDR_LAYER|HDR_BITRATE|HDR_SAMPLERATE|HDR_CHANNEL)8182/* Free format headers have zero bitrate value. */83#define HDR_FREE_FORMAT(head) (!(head & HDR_BITRATE))8485/* A mask for changed sampling rate (version or rate bits). */86#define HDR_SAMPMASK (HDR_VERSION|HDR_SAMPLERATE)8788#endif899091