00001
00006 #ifndef _MP3_FORMAT_H_
00007 #define _MP3_FORMAT_H_
00008
00014 struct mp3_frame_header
00015 {
00017 enum { size = 21 };
00018
00020 enum { IDex, ID, layer, protection_bit, bitrate_index, frequency,
00021 padding_bit, private_bit, mode, mode_extension, copyright, original, emphasis };
00022
00024 enum { stereo, joint_stereo, dual_channel, single_channel };
00025
00026 static const int bits[];
00027 static const int bitrate_table[2][4][16];
00028 static const int version_table[2][2];
00029 static const int layer_table[4];
00030 static const int frequency_table[2][2][4];
00031 };
00032
00033 #ifdef FRAMEHEADER
00034 const int mp3_frame_header::bits[] = { 0, 1, 2, 4, 5, 9, 11, 12, 13, 15, 17, 18, 19, 21 };
00035 const int mp3_frame_header::bitrate_table[2][4][16] =
00036 { { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
00037 { -1, 8, 16, 24, 32, 64, 80, 56, 64, 128, 160, 112, 128, 256, 320, -1 },
00038 { -1, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1 },
00039 { -1, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1 } },
00040 { { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
00041 { -1, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 },
00042 { -1, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, -1 },
00043 { -1, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, -1 } } };
00044
00045 const int mp3_frame_header::version_table[2][2] = { { 3, -1 }, { 2, 1 } };
00046 const int mp3_frame_header::layer_table[4] = { -1, 3, 2, 1 };
00047 const int mp3_frame_header::frequency_table[2][2][4] = { { { 11025, 12000, 8000, -1 }, { -1, -1, -1, -1 } },
00048 { { 22050, 24000, 16000, -1 }, { 44100, 48000, 32000, -1 } } };
00049 #endif
00050
00056 struct mp3_data_header_mpeg1_1ch
00057 {
00059 enum { size = 18 };
00060
00062 enum { main_data_begin, private_bits, scfsi };
00063
00064 static const int bits[];
00065 };
00066
00072 struct mp3_data_header_mpeg1_2ch
00073 {
00075 enum { size = 20 };
00076
00078 enum { main_data_begin, private_bits, scfsi };
00079
00080 static const int bits[];
00081 };
00082
00088 struct mp3_data_header_mpeg2_1ch
00089 {
00091 enum { size = 9 };
00092
00094 enum { main_data_begin, private_bits };
00095
00096 static const int bits[];
00097 };
00098
00104 struct mp3_data_header_mpeg2_2ch
00105 {
00107 enum { size = 10 };
00108
00110 enum { main_data_begin, private_bits };
00111
00112 static const int bits[];
00113 };
00114
00115 #ifdef DATAHEADER
00116 const int mp3_data_header_mpeg1_1ch::bits[] = { 0, 9, 14, 18 };
00117 const int mp3_data_header_mpeg1_2ch::bits[] = { 0, 9, 12, 20 };
00118 const int mp3_data_header_mpeg2_1ch::bits[] = { 0, 8, 9 };
00119 const int mp3_data_header_mpeg2_2ch::bits[] = { 0, 8, 10 };
00120 #endif
00121
00122
00128 struct mp3_channel_header_mpeg1
00129 {
00131 enum { size = 59 };
00132
00134 enum { part2_3_length, big_values, global_gain, scalefac_compress, window_switching_flag,
00135 variable_part, preflag, scalefac_scale, count1table_select };
00136
00137 static const int bits[];
00138 };
00139
00145 struct mp3_channel_header_mpeg2
00146 {
00148 enum { size = 63 };
00149
00151 enum { part2_3_length, big_values, global_gain, scalefac_compress, window_switching_flag,
00152 variable_part, scalefac_scale, count1table_select };
00153
00154 static const int bits[];
00155 };
00156
00157 #ifdef CHANNELHEADER
00158 const int mp3_channel_header_mpeg1::bits[] = { 0, 12, 21, 29, 33, 34, 56, 57, 58, 59 };
00159 const int mp3_channel_header_mpeg2::bits[] = { 0, 12, 21, 29, 38, 39, 61, 62, 63 };
00160 #endif
00161
00162
00168 struct mp3_tag_v1
00169 {
00171 enum { size = 128,
00172 headersize = 3
00173 };
00174
00175 static const char *header;
00176 };
00177
00178 #ifdef TAGV1
00179 const char *mp3_tag_v1::header = "TAG";
00180 #endif
00181
00182
00188 struct mp3
00189 {
00190 enum { sync = 0x7FF,
00191 syncbits = 11,
00192 CRCbits = 16,
00193 frametime = 26,
00194 maxloud = 4
00195 };
00196 };
00197
00198 #endif //_MP3_FORMAT_H_