1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*C
(c) 2005 bl0rg.net
**/
#ifndef MP3_H__
#define MP3_H__
/*M
\emph{Size allocated for the ''raw'' content of an MP3 frame.}
This is an arbitrary size.
**/
#define MP3_RAW_SIZE 4000
/*M
\emph{Maximal number of synchronisation errors allowed while
reading an MP3 stream.}
**/
#define MP3_MAX_SYNC 4000
/*M
\emph{MPEG Audio Frame Header size.}
**/
#define MP3_HDR_SIZE 4
/*M
\emph{Scalefactor information contained in a single granule.}
**/
typedef struct {
unsigned int l[23]; /* long window */
unsigned int s[3][13]; /* short window */
} mp3_sf_t;
typedef struct {
int s;
float x;
} mp3_sample_t;
/*M
\emph{MP3 granule.}
**/
typedef struct mp3_granule_s {
int part2_3_length;
int part2_length;
int part3_length;
unsigned int big_values;
unsigned int global_gain;
unsigned int scale_comp;
unsigned int slen0;
unsigned int slen1;
unsigned int blocksplit_flag;
unsigned int block_type;
unsigned int switch_point;
unsigned int tbl_sel[3];
unsigned int reg0_cnt;
unsigned int reg1_cnt;
unsigned int sub_gain[3];
unsigned int maxband[3];
unsigned int maxbandl;
unsigned int maxb;
unsigned int region1start;
unsigned int region2start;
unsigned int preflag;
unsigned int scale_scale;
unsigned int cnt1tbl_sel;
float *full_gain[3];
float *pow2gain;
mp3_sf_t sf; /* scale factor */
mp3_sample_t samples[576];
} mp3_granule_t;
/*M
\emph{MP3 stereo channel.}
**/
typedef struct mp3_channel_s {
unsigned char scfsi[4];
mp3_granule_t granule[2];
} mp3_channel_t;
/*M
\emph{MP3 side information.}
In mono MP3s only the first channel structure is used.
**/
typedef struct mp3_si_s {
unsigned int main_data_end;
unsigned int private_bits;
mp3_channel_t channel[2];
} mp3_si_t;
/*M
\emph{Single MP3 frame.}
**/
typedef struct mp3_frame_s {
unsigned char id;
unsigned char layer;
unsigned char protected;
unsigned char bitrate_index;
unsigned char samplerfindex;
unsigned char padding_bit;
unsigned char private_bit;
unsigned char mode;
unsigned char mode_ext;
unsigned char copyright;
unsigned char original;
unsigned char emphasis;
unsigned char crc[2];
mp3_si_t si;
unsigned long si_size;
unsigned long si_bitsize;
unsigned long adu_bitsize;
unsigned long adu_size;
/* calculated information */
unsigned short syncskip;
unsigned long bitrate;
unsigned long samplerate;
unsigned long samplelen;
unsigned long frame_size;
unsigned long frame_data_size;
unsigned long usec;
/* XXX add length counter for overflow checking */
unsigned char raw[MP3_RAW_SIZE];
} mp3_frame_t;
/*M
\emph{Prototypes and macros.}
**/
#define mp3_frame_data_begin(f) \
((f)->raw + 4 + ((f)->protected ? 0 : 2) + (f)->si_size)
#include "file.h"
int mp3_read_si(mp3_frame_t *frame);
int mp3_read_hdr(mp3_frame_t *frame);
int mp3_read_sf(mp3_frame_t *frame);
int mp3_next_frame(file_t *mp3, mp3_frame_t *frame);
int mp3_unpack(mp3_frame_t *frame);
int mp3_fill_si(mp3_frame_t *frame);
int mp3_fill_hdr(mp3_frame_t *frame);
int mp3_write_frame(file_t *file, mp3_frame_t *frame);
int mp3_trans_frame(mp3_frame_t *frame);
void mp3_calc_hdr(mp3_frame_t *frame);
unsigned long mp3_frame_size(mp3_frame_t *frame);
/*M
**/
#endif /* MP3_H__ */
|