1 /* 2 * D header for libmad. 3 * 4 * libmad - MPEG audio decoder library 5 * Copyright (C) 2000-2004 Underbit Technologies, Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 * If you would like to negotiate alternate licensing terms, you may do 22 * so by contacting: Underbit Technologies, Inc. <info@underbit.com> 23 */ 24 module deimos.mad; 25 26 import core.stdc.config; 27 28 extern(C): 29 30 alias mad_fixed_t = int; 31 alias mad_fixed64hi_t = int; 32 alias mad_fixed64lo_t = uint; 33 alias mad_sample_t = int; 34 35 enum MAD_BUFFER_GUARD = 8; 36 enum MAD_BUFFER_MDLEN = (511 + 2048 + MAD_BUFFER_GUARD); 37 38 enum MAD_F_FRACBITS = 28; 39 enum MAD_F_ONE = 0x10000000; 40 41 enum mad_units 42 { 43 HOURS = -2, 44 MINUTES = -1, 45 SECONDS = 0, 46 DECISECONDS = 10, 47 CENTISECONDS = 100, 48 MILLISECONDS = 1000, 49 _8000_HZ = 8000, 50 _11025_HZ = 11025, 51 _12000_HZ = 12000, 52 _16000_HZ = 16000, 53 _22050_HZ = 22050, 54 _24000_HZ = 24000, 55 _32000_HZ = 32000, 56 _44100_HZ = 44100, 57 _48000_HZ = 48000, 58 _24_FPS = 24, 59 _25_FPS = 25, 60 _30_FPS = 30, 61 _48_FPS = 48, 62 _50_FPS = 50, 63 _60_FPS = 60, 64 _75_FPS = 75, 65 _23_976_FPS = -24, 66 _24_975_FPS = -25, 67 _29_97_FPS = -30, 68 _47_952_FPS = -48, 69 _49_95_FPS = -50, 70 _59_94_FPS = -60 71 } 72 73 enum mad_error 74 { 75 NONE = 0, 76 BUFLEN = 1, 77 BUFPTR = 2, 78 NOMEM = 49, 79 LOSTSYNC = 257, 80 BADLAYER = 258, 81 BADBITRATE = 259, 82 BADSAMPLERATE = 260, 83 BADEMPHASIS = 261, 84 BADCRC = 513, 85 BADBITALLOC = 529, 86 BADSCALEFACTOR = 545, 87 BADMODE = 546, 88 BADFRAMELEN = 561, 89 BADBIGVALUES = 562, 90 BADBLOCKTYPE = 563, 91 BADSCFSI = 564, 92 BADDATAPTR = 565, 93 BADPART3LEN = 566, 94 BADHUFFTABLE = 567, 95 BADHUFFDATA = 568, 96 BADSTEREO = 569 97 } 98 99 enum mad_option 100 { 101 IGNORECRC = 1, 102 HALFSAMPLERATE = 2 103 } 104 105 enum mad_layer 106 { 107 I = 1, 108 II = 2, 109 III = 3 110 } 111 112 enum mad_mode 113 { 114 SINGLE_CHANNEL = 0, 115 DUAL_CHANNEL = 1, 116 JOINT_STEREO = 2, 117 STEREO = 3 118 } 119 120 enum mad_emphasis 121 { 122 NONE = 0, 123 _50_15_US = 1, 124 CCITT_J_17 = 3, 125 RESERVED = 2 126 } 127 128 enum mad_flag 129 { 130 NPRIVATE_III = 7, 131 INCOMPLETE = 8, 132 PROTECTION = 16, 133 COPYRIGHT = 32, 134 ORIGINAL = 64, 135 PADDING = 128, 136 I_STEREO = 256, 137 MS_STEREO = 512, 138 FREEFORMAT = 1024, 139 LSF_EXT = 4096, 140 MC_EXT = 8192, 141 MPEG_2_5_EXT = 16384 142 } 143 144 enum mad_private 145 { 146 HEADER = 256, 147 III = 31 148 } 149 150 enum _Anonymous_4 151 { 152 MAD_PCM_CHANNEL_SINGLE = 0 153 } 154 155 enum _Anonymous_5 156 { 157 MAD_PCM_CHANNEL_DUAL_1 = 0, 158 MAD_PCM_CHANNEL_DUAL_2 = 1 159 } 160 161 enum _Anonymous_6 162 { 163 MAD_PCM_CHANNEL_STEREO_LEFT = 0, 164 MAD_PCM_CHANNEL_STEREO_RIGHT = 1 165 } 166 167 enum mad_decoder_mode 168 { 169 SYNC = 0, 170 ASYNC = 1 171 } 172 173 enum mad_flow 174 { 175 CONTINUE = 0, 176 STOP = 16, 177 BREAK = 17, 178 IGNORE = 32 179 } 180 181 struct mad_bitptr 182 { 183 const(ubyte)* byte_; 184 ushort cache; 185 ushort left; 186 } 187 188 struct mad_timer_t 189 { 190 c_long seconds; 191 c_ulong fraction; 192 } 193 194 struct mad_stream 195 { 196 const(ubyte)* buffer; 197 const(ubyte)* bufend; 198 c_ulong skiplen; 199 int sync; 200 c_ulong freerate; 201 const(ubyte)* this_frame; 202 const(ubyte)* next_frame; 203 mad_bitptr ptr; 204 mad_bitptr anc_ptr; 205 uint anc_bitlen; 206 char[MAD_BUFFER_MDLEN]* main_data; 207 uint md_len; 208 int options; 209 mad_error error; 210 } 211 static assert(mad_stream.sizeof == 120); 212 213 struct mad_header 214 { 215 mad_layer layer; 216 mad_mode mode; 217 int mode_extension; 218 mad_emphasis emphasis; 219 c_ulong bitrate; 220 uint samplerate; 221 ushort crc_check; 222 ushort crc_target; 223 int flags; 224 int private_bits; 225 mad_timer_t duration; 226 } 227 static assert(mad_header.sizeof == 56); 228 229 struct mad_frame 230 { 231 mad_header header; 232 int options; 233 mad_fixed_t[32][36][2] sbsample; 234 mad_fixed_t[18][32][2]* overlap; 235 } 236 static assert(mad_frame.sizeof == 9288); 237 238 struct mad_pcm 239 { 240 uint samplerate; 241 ushort channels; 242 ushort length; 243 mad_fixed_t[1152][2] samples; 244 } 245 246 struct mad_synth 247 { 248 mad_fixed_t[8][16][2][2][2] filter; 249 uint phase; 250 mad_pcm pcm; 251 } 252 253 alias input_func_t = extern(C) mad_flow function (void*, mad_stream*); 254 alias header_func_t = extern(C) mad_flow function (void*, const(mad_header)*); 255 alias filter_func_t = extern(C) mad_flow function (void*, const(mad_stream)*, mad_frame*); 256 alias output_func_t = extern(C) mad_flow function (void*, const(mad_header)*, mad_pcm*); 257 alias error_func_t = extern(C) mad_flow function (void*, mad_stream*, mad_frame*); 258 alias message_func_t = extern(C) mad_flow function (void*, void*, uint*); 259 260 struct mad_decoder 261 { 262 mad_decoder_mode mode; 263 int options; 264 static struct _async { 265 c_long pid; 266 int in_; 267 int out_; 268 }; 269 _async async; 270 static struct _sync { 271 mad_stream stream; 272 mad_frame frame; 273 mad_synth synth; 274 } 275 _sync* sync; 276 void* cb_data; 277 input_func_t input_func; 278 header_func_t header_func; 279 filter_func_t filter_func; 280 output_func_t output_func; 281 error_func_t error_func; 282 message_func_t message_func; 283 } 284 static assert(mad_decoder.sizeof == 88); 285 static assert(mad_decoder.init.sync.offsetof == 24); 286 287 mad_fixed_t mad_f_abs (mad_fixed_t); 288 mad_fixed_t mad_f_div (mad_fixed_t, mad_fixed_t); 289 void mad_bit_init (mad_bitptr*, const(ubyte)*); 290 uint mad_bit_length (const(mad_bitptr)*, const(mad_bitptr)*); 291 const(ubyte)* mad_bit_nextbyte (const(mad_bitptr)*); 292 void mad_bit_skip (mad_bitptr*, uint); 293 c_ulong mad_bit_read (mad_bitptr*, uint); 294 void mad_bit_write (mad_bitptr*, uint, c_ulong); 295 ushort mad_bit_crc (mad_bitptr, uint, ushort); 296 int mad_timer_compare (mad_timer_t, mad_timer_t); 297 void mad_timer_negate (mad_timer_t*); 298 mad_timer_t mad_timer_abs (mad_timer_t); 299 void mad_timer_set (mad_timer_t*, c_ulong, c_ulong, c_ulong); 300 void mad_timer_add (mad_timer_t*, mad_timer_t); 301 void mad_timer_multiply (mad_timer_t*, c_long); 302 c_long mad_timer_count (mad_timer_t, mad_units); 303 c_ulong mad_timer_fraction (mad_timer_t, c_ulong); 304 void mad_timer_string (mad_timer_t, char*, const(char)*, mad_units, mad_units, c_ulong); 305 void mad_stream_init (mad_stream*); 306 void mad_stream_finish (mad_stream*); 307 void mad_stream_buffer (mad_stream*, const(ubyte)*, c_ulong); 308 void mad_stream_skip (mad_stream*, c_ulong); 309 int mad_stream_sync (mad_stream*); 310 const(char)* mad_stream_errorstr (const(mad_stream)*); 311 void mad_header_init (mad_header*); 312 int mad_header_decode (mad_header*, mad_stream*); 313 void mad_frame_init (mad_frame*); 314 void mad_frame_finish (mad_frame*); 315 int mad_frame_decode (mad_frame*, mad_stream*); 316 void mad_frame_mute (mad_frame*); 317 void mad_synth_init (mad_synth*); 318 void mad_synth_mute (mad_synth*); 319 void mad_synth_frame (mad_synth*, const(mad_frame)*); 320 void mad_decoder_init (mad_decoder*, void*, input_func_t, header_func_t, filter_func_t, output_func_t, error_func_t, message_func_t); 321 int mad_decoder_finish (mad_decoder*); 322 int mad_decoder_run (mad_decoder*, mad_decoder_mode); 323 int mad_decoder_message (mad_decoder*, void*, uint*); 324