1 /* 2 * Interface to MP3 LAME encoding engine 3 * 4 * Copyright (c) 1999 Mark Taylor 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2, or (at your option) 9 * any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; see the file COPYING. If not, write to 18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 /* $Id: lame.h,v 1.2 2003/08/12 00:02:55 snelg Exp $ */ 22 23 #ifndef LAME_LAME_H 24 #define LAME_LAME_H 25 26 #include <stdio.h> 27 #include <stdarg.h> 28 29 #if defined(__cplusplus) 30 extern "C" { 31 #endif 32 33 34 #if defined(WIN32) 35 #undef CDECL 36 #define CDECL _cdecl 37 #else 38 #define CDECL 39 #endif 40 41 42 typedef enum vbr_mode_e { 43 vbr_off=0, 44 vbr_mt, 45 vbr_rh, 46 vbr_abr, 47 vbr_mtrh, 48 vbr_max_indicator, /* Don't use this! It's used for sanity checks. */ 49 vbr_default=vbr_rh /* change this to change the default VBR mode of LAME */ 50 } vbr_mode; 51 52 53 /* MPEG modes */ 54 typedef enum MPEG_mode_e { 55 STEREO = 0, 56 JOINT_STEREO, 57 DUAL_CHANNEL, /* LAME doesn't supports this! */ 58 MONO, 59 NOT_SET, 60 MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 61 } MPEG_mode; 62 63 /* Padding types */ 64 typedef enum Padding_type_e { 65 PAD_NO = 0, 66 PAD_ALL, 67 PAD_ADJUST, 68 PAD_MAX_INDICATOR /* Don't use this! It's used for sanity checks. */ 69 } Padding_type; 70 71 72 73 struct lame_global_struct; 74 typedef struct lame_global_struct lame_global_flags; 75 typedef lame_global_flags *lame_t; 76 77 78 79 80 /*********************************************************************** 81 * 82 * The LAME API 83 * These functions should be called, in this order, for each 84 * MP3 file to be encoded 85 * 86 ***********************************************************************/ 87 88 89 /* 90 * REQUIRED: 91 * initialize the encoder. sets default for all encoder paramters, 92 * returns -1 if some malloc()'s failed 93 * otherwise returns 0 94 */ 95 lame_global_flags * CDECL lame_init(void); 96 /* obsolete version */ 97 int CDECL lame_init_old(lame_global_flags *); 98 99 100 /* 101 * OPTIONAL: 102 * set as needed to override defaults 103 */ 104 105 /******************************************************************** 106 * input stream description 107 ***********************************************************************/ 108 // number of samples. default = 2^32-1 109 int CDECL lame_set_num_samples(lame_global_flags *, unsigned long); 110 unsigned long CDECL lame_get_num_samples(const lame_global_flags *); 111 112 // input sample rate in Hz. default = 44100hz 113 int CDECL lame_set_in_samplerate(lame_global_flags *, int); 114 int CDECL lame_get_in_samplerate(const lame_global_flags *); 115 116 // number of channels in input stream. default=2 117 int CDECL lame_set_num_channels(lame_global_flags *, int); 118 int CDECL lame_get_num_channels(const lame_global_flags *); 119 120 // scale the input by this amount before encoding. default=0 (disabled) 121 // (not used by decoding routines) 122 int CDECL lame_set_scale(lame_global_flags *, float); 123 float CDECL lame_get_scale(const lame_global_flags *); 124 125 // output sample rate in Hz. default = 0, which means LAME picks best value 126 // based on the amount of compression. MPEG only allows: 127 // MPEG1 32, 44.1, 48khz 128 // MPEG2 16, 22.05, 24 129 // MPEG2.5 8, 11.025, 12 130 // (not used by decoding routines) 131 int CDECL lame_set_out_samplerate(lame_global_flags *, int); 132 int CDECL lame_get_out_samplerate(const lame_global_flags *); 133 134 135 /******************************************************************** 136 * general control parameters 137 ***********************************************************************/ 138 // 1=cause LAME to collect data for an MP3 frame analzyer. default=0 139 int CDECL lame_set_analysis(lame_global_flags *, int); 140 int CDECL lame_get_analysis(const lame_global_flags *); 141 142 // 1 = write a Xing VBR header frame. 143 // default = 1 for VBR/ABR modes, 0 for CBR mode 144 // this variable must have been added by a Hungarian notation Windows programmer :-) 145 int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int); 146 int CDECL lame_get_bWriteVbrTag(const lame_global_flags *); 147 148 // 1=decode only. use lame/mpglib to convert mp3/ogg to wav. default=0 149 int CDECL lame_set_decode_only(lame_global_flags *, int); 150 int CDECL lame_get_decode_only(const lame_global_flags *); 151 152 // 1=encode a Vorbis .ogg file. default=0 153 int CDECL lame_set_ogg(lame_global_flags *, int); 154 int CDECL lame_get_ogg(const lame_global_flags *); 155 156 // internal algorithm selection. True quality is determined by the bitrate 157 // but this variable will effect quality by selecting expensive or cheap algorithms. 158 // quality=0..9. 0=best (very slow). 9=worst. 159 // recommended: 2 near-best quality, not too slow 160 // 5 good quality, fast 161 // 7 ok quality, really fast 162 int CDECL lame_set_quality(lame_global_flags *, int); 163 int CDECL lame_get_quality(const lame_global_flags *); 164 165 // mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono 166 // default: lame picks based on compression ration and input channels 167 int CDECL lame_set_mode(lame_global_flags *, MPEG_mode); 168 MPEG_mode CDECL lame_get_mode(const lame_global_flags *); 169 170 // mode_automs. Us a M/S mode with a switching threshold based on 171 // compression ratio 172 // default = 0 (disabled) 173 int CDECL lame_set_mode_automs(lame_global_flags *, int); 174 int CDECL lame_get_mode_automs(const lame_global_flags *); 175 176 // force_ms. Force M/S for all frames. For testing only. 177 // default = 0 (disabled) 178 int CDECL lame_set_force_ms(lame_global_flags *, int); 179 int CDECL lame_get_force_ms(const lame_global_flags *); 180 181 // use free_format? default = 0 (disabled) 182 int CDECL lame_set_free_format(lame_global_flags *, int); 183 int CDECL lame_get_free_format(const lame_global_flags *); 184 185 /* 186 * OPTIONAL: 187 * Set printf like error/debug/message reporting functions. 188 * The second argument has to be a pointer to a function which looks like 189 * void my_debugf(const char *format, va_list ap) 190 * { 191 * (void) vfprintf(stdout, format, ap); 192 * } 193 * If you use NULL as the value of the pointer in the set function, the 194 * lame buildin function will be used (prints to stderr). 195 * To quiet any output you have to replace the body of the example function 196 * with just "return;" and use it in the set function. 197 */ 198 int CDECL lame_set_errorf(lame_global_flags *, 199 void (*func)(const char *, va_list)); 200 int CDECL lame_set_debugf(lame_global_flags *, 201 void (*func)(const char *, va_list)); 202 int CDECL lame_set_msgf (lame_global_flags *, 203 void (*func)(const char *, va_list)); 204 205 206 207 /* set one of brate compression ratio. default is compression ratio of 11. */ 208 int CDECL lame_set_brate(lame_global_flags *, int); 209 int CDECL lame_get_brate(const lame_global_flags *); 210 int CDECL lame_set_compression_ratio(lame_global_flags *, float); 211 float CDECL lame_get_compression_ratio(const lame_global_flags *); 212 213 /******************************************************************** 214 * frame params 215 ***********************************************************************/ 216 // mark as copyright. default=0 217 int CDECL lame_set_copyright(lame_global_flags *, int); 218 int CDECL lame_get_copyright(const lame_global_flags *); 219 220 // mark as original. default=1 221 int CDECL lame_set_original(lame_global_flags *, int); 222 int CDECL lame_get_original(const lame_global_flags *); 223 224 // error_protection. Use 2 bytes from each fraome for CRC checksum. default=0 225 int CDECL lame_set_error_protection(lame_global_flags *, int); 226 int CDECL lame_get_error_protection(const lame_global_flags *); 227 228 // padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default) 229 int CDECL lame_set_padding_type(lame_global_flags *, Padding_type); 230 Padding_type CDECL lame_get_padding_type(const lame_global_flags *); 231 232 // MP3 'private extension' bit Meaningless 233 int CDECL lame_set_extension(lame_global_flags *, int); 234 int CDECL lame_get_extension(const lame_global_flags *); 235 236 // enforce strict ISO complience. default=0 237 int CDECL lame_set_strict_ISO(lame_global_flags *, int); 238 int CDECL lame_get_strict_ISO(const lame_global_flags *); 239 240 241 /******************************************************************** 242 * quantization/noise shaping 243 ***********************************************************************/ 244 245 // disable the bit reservoir. For testing only. default=0 246 int CDECL lame_set_disable_reservoir(lame_global_flags *, int); 247 int CDECL lame_get_disable_reservoir(const lame_global_flags *); 248 249 // select a different "best quantization" function. default=0 250 int CDECL lame_set_experimentalX(lame_global_flags *, int); 251 int CDECL lame_get_experimentalX(const lame_global_flags *); 252 253 // another experimental option. for testing only 254 int CDECL lame_set_experimentalY(lame_global_flags *, int); 255 int CDECL lame_get_experimentalY(const lame_global_flags *); 256 257 // another experimental option. for testing only 258 int CDECL lame_set_experimentalZ(lame_global_flags *, int); 259 int CDECL lame_get_experimentalZ(const lame_global_flags *); 260 261 // Naoki's psycho acoustic model. default=0 262 int CDECL lame_set_exp_nspsytune(lame_global_flags *, int); 263 int CDECL lame_get_exp_nspsytune(const lame_global_flags *); 264 265 266 267 /******************************************************************** 268 * VBR control 269 ***********************************************************************/ 270 // Types of VBR. default = vbr_off = CBR 271 int CDECL lame_set_VBR(lame_global_flags *, vbr_mode); 272 vbr_mode CDECL lame_get_VBR(const lame_global_flags *); 273 274 // VBR quality level. 0=highest 9=lowest 275 int CDECL lame_set_VBR_q(lame_global_flags *, int); 276 int CDECL lame_get_VBR_q(const lame_global_flags *); 277 278 // Ignored except for VBR=vbr_abr (ABR mode) 279 int CDECL lame_set_VBR_mean_bitrate_kbps(lame_global_flags *, int); 280 int CDECL lame_get_VBR_mean_bitrate_kbps(const lame_global_flags *); 281 282 int CDECL lame_set_VBR_min_bitrate_kbps(lame_global_flags *, int); 283 int CDECL lame_get_VBR_min_bitrate_kbps(const lame_global_flags *); 284 285 int CDECL lame_set_VBR_max_bitrate_kbps(lame_global_flags *, int); 286 int CDECL lame_get_VBR_max_bitrate_kbps(const lame_global_flags *); 287 288 // 1=stricetly enforce VBR_min_bitrate. Normally it will be violated for 289 // analog silence 290 int CDECL lame_set_VBR_hard_min(lame_global_flags *, int); 291 int CDECL lame_get_VBR_hard_min(const lame_global_flags *); 292 293 294 /******************************************************************** 295 * Filtering control 296 ***********************************************************************/ 297 // freq in Hz to apply lowpass. Default = 0 = lame chooses. -1 = disabled 298 int CDECL lame_set_lowpassfreq(lame_global_flags *, int); 299 int CDECL lame_get_lowpassfreq(const lame_global_flags *); 300 // width of transition band, in Hz. Default = one polyphase filter band 301 int CDECL lame_set_lowpasswidth(lame_global_flags *, int); 302 int CDECL lame_get_lowpasswidth(const lame_global_flags *); 303 304 // freq in Hz to apply highpass. Default = 0 = lame chooses. -1 = disabled 305 int CDECL lame_set_highpassfreq(lame_global_flags *, int); 306 int CDECL lame_get_highpassfreq(const lame_global_flags *); 307 // width of transition band, in Hz. Default = one polyphase filter band 308 int CDECL lame_set_highpasswidth(lame_global_flags *, int); 309 int CDECL lame_get_highpasswidth(const lame_global_flags *); 310 311 312 /******************************************************************** 313 * psycho acoustics and other arguments which you should not change 314 * unless you know what you are doing 315 ***********************************************************************/ 316 // only use ATH for masking 317 int CDECL lame_set_ATHonly(lame_global_flags *, int); 318 int CDECL lame_get_ATHonly(const lame_global_flags *); 319 320 // only use ATH for short blocks 321 int CDECL lame_set_ATHshort(lame_global_flags *, int); 322 int CDECL lame_get_ATHshort(const lame_global_flags *); 323 324 // disable ATH 325 int CDECL lame_set_noATH(lame_global_flags *, int); 326 int CDECL lame_get_noATH(const lame_global_flags *); 327 328 // select ATH formula 329 int CDECL lame_set_ATHtype(lame_global_flags *, int); 330 int CDECL lame_get_ATHtype(const lame_global_flags *); 331 332 // lower ATH by this many db 333 int CDECL lame_set_ATHlower(lame_global_flags *, float); 334 float CDECL lame_get_ATHlower(const lame_global_flags *); 335 336 // select adaptive ATH type 337 int CDECL lame_set_adjust_type( lame_global_flags *, int); 338 int CDECL lame_get_adjust_type( const lame_global_flags *); 339 340 // select adaptive ATH level adjustment scheme 341 int CDECL lame_set_adapt_thres_type( lame_global_flags *, int); 342 int CDECL lame_get_adapt_thres_type( const lame_global_flags *); 343 344 // adjust (in dB) the point below which adaptive ATH level adjustment occurs 345 int CDECL lame_set_adapt_thres_level( lame_global_flags *, float); 346 float CDECL lame_get_adapt_thres_level( const lame_global_flags* ); 347 348 // predictability limit (ISO tonality formula) 349 int CDECL lame_set_cwlimit(lame_global_flags *, int); 350 int CDECL lame_get_cwlimit(const lame_global_flags *); 351 352 // allow blocktypes to differ between channels? 353 // default: 0 for jstereo, 1 for stereo 354 int CDECL lame_set_allow_diff_short(lame_global_flags *, int); 355 int CDECL lame_get_allow_diff_short(const lame_global_flags *); 356 357 // use temporal masking effect (default = 1) 358 int CDECL lame_set_useTemporal(lame_global_flags *, int); 359 int CDECL lame_get_useTemporal(const lame_global_flags *); 360 361 // disable short blocks 362 int CDECL lame_set_no_short_blocks(lame_global_flags *, int); 363 int CDECL lame_get_no_short_blocks(const lame_global_flags *); 364 365 // force short blocks 366 int CDECL lame_set_force_short_blocks(lame_global_flags *, int); 367 int CDECL lame_get_force_short_blocks(const lame_global_flags *); 368 369 /* Input PCM is emphased PCM (for instance from one of the rarely 370 emphased CDs), it is STRONGLY not recommended to use this, because 371 psycho does not take it into account, and last but not least many decoders 372 ignore these bits */ 373 int CDECL lame_set_emphasis(lame_global_flags *, int); 374 int CDECL lame_get_emphasis(const lame_global_flags *); 375 376 377 378 /************************************************************************/ 379 /* internal variables, cannot be set... */ 380 /* provided because they may be of use to calling application */ 381 /************************************************************************/ 382 // version 0=MPEG-2 1=MPEG-1 (2=MPEG-2.5) 383 int CDECL lame_get_version(const lame_global_flags *); 384 385 // encoder delay 386 int CDECL lame_get_encoder_delay(const lame_global_flags *); 387 388 // padding appended to the input to make sure decoder can fully decode 389 // all input. Note that this value can only be calculated during the 390 // call to lame_encoder_flush(). Before lame_encoder_flush() has 391 // been called, the value of encoder_padding = 0. 392 int CDECL lame_get_encoder_padding(const lame_global_flags *); 393 394 // size of MPEG frame 395 int CDECL lame_get_framesize(const lame_global_flags *); 396 397 // number of PCM samples buffered, but not yet encoded to mp3 data. 398 int CDECL lame_get_mf_samples_to_encode( const lame_global_flags* gfp ); 399 400 // size (bytes) of mp3 data buffered, but not yet encoded. 401 // this is the number of bytes which would be output by a call to 402 // lame_encode_flush_nogap. NOTE: lame_encode_flush() will return 403 // more bytes than this because it will encode the reamining buffered 404 // PCM samples before flushing the mp3 buffers. 405 int CDECL lame_get_size_mp3buffer( const lame_global_flags* gfp ); 406 407 // number of frames encoded so far 408 int CDECL lame_get_frameNum(const lame_global_flags *); 409 410 // lame's estimate of the total number of frames to be encoded 411 // only valid if calling program set num_samples 412 int CDECL lame_get_totalframes(const lame_global_flags *); 413 414 415 416 417 418 419 420 421 /* 422 * REQUIRED: 423 * sets more internal configuration based on data provided above. 424 * returns -1 if something failed. 425 */ 426 int CDECL lame_init_params(lame_global_flags *); 427 428 429 /* 430 * OPTIONAL: 431 * get the version number, in a string. of the form: 432 * "3.63 (beta)" or just "3.63". 433 */ 434 const char* CDECL get_lame_version ( void ); 435 const char* CDECL get_lame_short_version ( void ); 436 const char* CDECL get_lame_very_short_version ( void ); 437 const char* CDECL get_psy_version ( void ); 438 const char* CDECL get_mp3x_version ( void ); 439 const char* CDECL get_lame_url ( void ); 440 441 /* 442 * OPTIONAL: 443 * get the version numbers in numerical form. 444 */ 445 typedef struct { 446 /* generic LAME version */ 447 int major; 448 int minor; 449 int alpha; /* 0 if not an alpha version */ 450 int beta; /* 0 if not a beta version */ 451 452 /* version of the psy model */ 453 int psy_major; 454 int psy_minor; 455 int psy_alpha; /* 0 if not an alpha version */ 456 int psy_beta; /* 0 if not a beta version */ 457 458 /* compile time features */ 459 const char *features; /* Don't make assumptions about the contents! */ 460 } lame_version_t; 461 void CDECL get_lame_version_numerical ( lame_version_t *const ); 462 463 464 /* 465 * OPTIONAL: 466 * print internal lame configuration to message handler 467 */ 468 void CDECL lame_print_config(const lame_global_flags* gfp); 469 470 void CDECL lame_print_internals( const lame_global_flags *gfp); 471 472 473 /* 474 * input pcm data, output (maybe) mp3 frames. 475 * This routine handles all buffering, resampling and filtering for you. 476 * 477 * return code number of bytes output in mp3buf. Can be 0 478 * -1: mp3buf was too small 479 * -2: malloc() problem 480 * -3: lame_init_params() not called 481 * -4: psycho acoustic problems 482 * -5: ogg cleanup encoding error 483 * -6: ogg frame encoding error 484 * 485 * The required mp3buf_size can be computed from num_samples, 486 * samplerate and encoding rate, but here is a worst case estimate: 487 * 488 * mp3buf_size in bytes = 1.25*num_samples + 7200 489 * 490 * I think a tighter bound could be: (mt, March 2000) 491 * MPEG1: 492 * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512 493 * MPEG2: 494 * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256 495 * 496 * but test first if you use that! 497 * 498 * set mp3buf_size = 0 and LAME will not check if mp3buf_size is 499 * large enough. 500 * 501 * NOTE: 502 * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels 503 * will be averaged into the L channel before encoding only the L channel 504 * This will overwrite the data in buffer_l[] and buffer_r[]. 505 * 506 */ 507 int CDECL lame_encode_buffer ( 508 lame_global_flags* gfp, /* global context handle */ 509 const short int buffer_l [], /* PCM data for left channel */ 510 const short int buffer_r [], /* PCM data for right channel */ 511 const int nsamples, /* number of samples per channel */ 512 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 513 const int mp3buf_size ); /* number of valid octets in this 514 stream */ 515 516 /* 517 * as above, but input has L & R channel data interleaved. 518 * NOTE: 519 * num_samples = number of samples in the L (or R) 520 * channel, not the total number of samples in pcm[] 521 */ 522 int CDECL lame_encode_buffer_interleaved( 523 lame_global_flags* gfp, /* global context handlei */ 524 short int pcm[], /* PCM data for left and right 525 channel, interleaved */ 526 int num_samples, /* number of samples per channel, 527 _not_ number of samples in 528 pcm[] */ 529 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 530 int mp3buf_size ); /* number of valid octets in this 531 stream */ 532 533 534 /* as lame_encode_buffer, but for 'float's */ 535 int CDECL lame_encode_buffer_float( 536 lame_global_flags* gfp, /* global context handle */ 537 const float buffer_l [], /* PCM data for left channel */ 538 const float buffer_r [], /* PCM data for right channel */ 539 const int nsamples, /* number of samples per channel */ 540 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 541 const int mp3buf_size ); /* number of valid octets in this 542 stream */ 543 544 /* as lame_encode_buffer, but for int's */ 545 int CDECL lame_encode_buffer_int( 546 lame_global_flags* gfp, /* global context handle */ 547 const int buffer_l [], /* PCM data for left channel */ 548 const int buffer_r [], /* PCM data for right channel */ 549 const int nsamples, /* number of samples per channel */ 550 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 551 const int mp3buf_size ); /* number of valid octets in this 552 stream */ 553 554 /* as lame_encode_buffer, but for long's */ 555 int CDECL lame_encode_buffer_long( 556 lame_global_flags* gfp, /* global context handle */ 557 const long buffer_l [], /* PCM data for left channel */ 558 const long buffer_r [], /* PCM data for right channel */ 559 const int nsamples, /* number of samples per channel */ 560 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 561 const int mp3buf_size ); /* number of valid octets in this 562 stream */ 563 564 565 566 567 568 569 /* 570 * REQUIRED: 571 * lame_encode_flush will flush the intenal PCM buffers, padding with 572 * 0's to make sure the final frame is complete, and then flush 573 * the internal MP3 buffers, and thus may return a 574 * final few mp3 frames. 'mp3buf' should be at least 7200 bytes long 575 * to hold all possible emitted data. 576 * 577 * will also write id3v1 tags (if any) into the bitstream 578 * 579 * return code = number of bytes output to mp3buf. Can be 0 580 */ 581 int CDECL lame_encode_flush( 582 lame_global_flags * gfp, /* global context handle */ 583 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 584 int size); /* number of valid octets in this stream */ 585 586 /* 587 * OPTIONAL: 588 * lame_encode_flush_nogap will flush the internal mp3 buffers and pad 589 * the last frame with ancillary data so it is a complete mp3 frame. 590 * 591 * 'mp3buf' should be at least 7200 bytes long 592 * to hold all possible emitted data. 593 * 594 * After a call to this routine, the outputed mp3 data is complete, but 595 * you may continue to encode new PCM samples and write future mp3 data 596 * to a different file. The two mp3 files will play back with no gaps 597 * if they are concatenated together. 598 * 599 * This routine will NOT write id3v1 tags into the bitstream. 600 * 601 * return code = number of bytes output to mp3buf. Can be 0 602 */ 603 int CDECL lame_encode_flush_nogap( 604 lame_global_flags * gfp, /* global context handle */ 605 unsigned char* mp3buf, /* pointer to encoded MP3 stream */ 606 int size); /* number of valid octets in this stream */ 607 608 /* 609 * OPTIONAL: 610 * Normally, this is called by lame_init_params(). It writes id3v2 and 611 * Xing headers into the front of the bitstream, and sets frame counters 612 * and bitrate histogram data to 0. You can also call this after 613 * lame_encode_flush_nogap(). 614 */ 615 int CDECL lame_init_bitstream( 616 lame_global_flags * gfp); /* global context handle */ 617 618 619 620 /* 621 * OPTIONAL: some simple statistics 622 * a bitrate histogram to visualize the distribution of used frame sizes 623 * a stereo mode histogram to visualize the distribution of used stereo 624 * modes, useful in joint-stereo mode only 625 * 0: LR left-right encoded 626 * 1: LR-I left-right and intensity encoded (currently not supported) 627 * 2: MS mid-side encoded 628 * 3: MS-I mid-side and intensity encoded (currently not supported) 629 * 630 * attention: don't call them after lame_encode_finish 631 * suggested: lame_encode_flush -> lame_*_hist -> lame_close 632 */ 633 634 void CDECL lame_bitrate_hist( 635 const lame_global_flags *const gfp, 636 int bitrate_count[14] ); 637 void CDECL lame_bitrate_kbps( 638 const lame_global_flags *const gfp, 639 int bitrate_kbps [14] ); 640 void CDECL lame_stereo_mode_hist( 641 const lame_global_flags *const gfp, 642 int stereo_mode_count[4] ); 643 644 void CDECL lame_bitrate_stereo_mode_hist ( 645 const lame_global_flags* gfp, 646 int bitrate_stmode_count [14] [4] ); 647 648 649 /* 650 * OPTIONAL: 651 * lame_mp3_tags_fid will append a Xing VBR tag to the mp3 file with file 652 * pointer fid. These calls perform forward and backwards seeks, so make 653 * sure fid is a real file. Make sure lame_encode_flush has been called, 654 * and all mp3 data has been written to the file before calling this 655 * function. 656 * NOTE: 657 * if VBR tags are turned off by the user, or turned off by LAME because 658 * the output is not a regular file, this call does nothing 659 */ 660 void CDECL lame_mp3_tags_fid(lame_global_flags *,FILE* fid); 661 662 663 /* 664 * REQUIRED: 665 * final call to free all remaining buffers 666 */ 667 int CDECL lame_close (lame_global_flags *); 668 669 /* 670 * OBSOLETE: 671 * lame_encode_finish combines lame_encode_flush() and lame_close() in 672 * one call. However, once this call is made, the statistics routines 673 * will no longer work because the data will have been cleared 674 */ 675 int CDECL lame_encode_finish( 676 lame_global_flags* gfp, 677 unsigned char* mp3buf, 678 int size ); 679 680 681 682 683 684 685 686 /********************************************************************* 687 * 688 * decoding 689 * 690 * a simple interface to mpglib, part of mpg123, is also included if 691 * libmp3lame is compiled with HAVE_MPGLIB 692 * 693 *********************************************************************/ 694 typedef struct { 695 int header_parsed; /* 1 if header was parsed and following data was 696 computed */ 697 int stereo; /* number of channels */ 698 int samplerate; /* sample rate */ 699 int bitrate; /* bitrate */ 700 int mode; /* mp3 frame type */ 701 int mode_ext; /* mp3 frame type */ 702 int framesize; /* number of samples per mp3 frame */ 703 704 /* this data is only computed if mpglib detects a Xing VBR header */ 705 unsigned long nsamp; /* number of samples in mp3 file. */ 706 int totalframes; /* total number of frames in mp3 file */ 707 708 /* this data is not currently computed by the mpglib routines */ 709 int framenum; /* frames decoded counter */ 710 } mp3data_struct; 711 712 713 /* required call to initialize decoder */ 714 int CDECL lame_decode_init(void); 715 716 /********************************************************************* 717 * input 1 mp3 frame, output (maybe) pcm data. 718 * lame_decode() return code: 719 * -1: error 720 * 0: need more data 721 * n>0: size of pcm output 722 *********************************************************************/ 723 int CDECL lame_decode( 724 unsigned char * mp3buf, 725 int len, 726 short pcm_l[], 727 short pcm_r[] ); 728 729 /* same as lame_decode, and also returns mp3 header data */ 730 int CDECL lame_decode_headers( 731 unsigned char* mp3buf, 732 int len, 733 short pcm_l[], 734 short pcm_r[], 735 mp3data_struct* mp3data ); 736 737 /* same as lame_decode, but returns at most one frame */ 738 int CDECL lame_decode1( 739 unsigned char* mp3buf, 740 int len, 741 short pcm_l[], 742 short pcm_r[] ); 743 744 /* same as lame_decode1, but returns at most one frame and mp3 header data */ 745 int CDECL lame_decode1_headers( 746 unsigned char* mp3buf, 747 int len, 748 short pcm_l[], 749 short pcm_r[], 750 mp3data_struct* mp3data ); 751 752 753 754 755 756 /********************************************************************* 757 * 758 * id3tag stuff 759 * 760 *********************************************************************/ 761 762 /* 763 * id3tag.h -- Interface to write ID3 version 1 and 2 tags. 764 * 765 * Copyright (C) 2000 Don Melton. 766 * 767 * This library is free software; you can redistribute it and/or 768 * modify it under the terms of the GNU Library General Public 769 * License as published by the Free Software Foundation; either 770 * version 2 of the License, or (at your option) any later version. 771 * 772 * This library is distributed in the hope that it will be useful, 773 * but WITHOUT ANY WARRANTY; without even the implied warranty of 774 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 775 * Library General Public License for more details. 776 * 777 * You should have received a copy of the GNU Library General Public 778 * License along with this library; if not, write to the Free Software 779 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 780 */ 781 782 /* utility to obtain alphabetically sorted list of genre names with numbers */ 783 extern void id3tag_genre_list( 784 void (*handler)(int, const char *, void *), 785 void* cookie); 786 787 extern void id3tag_init (lame_global_flags *gfp); 788 789 /* force addition of version 2 tag */ 790 extern void id3tag_add_v2 (lame_global_flags *gfp); 791 792 /* add only a version 1 tag */ 793 extern void id3tag_v1_only (lame_global_flags *gfp); 794 795 /* add only a version 2 tag */ 796 extern void id3tag_v2_only (lame_global_flags *gfp); 797 798 /* pad version 1 tag with spaces instead of nulls */ 799 extern void id3tag_space_v1 (lame_global_flags *gfp); 800 801 /* pad version 2 tag with extra 128 bytes */ 802 extern void id3tag_pad_v2 (lame_global_flags *gfp); 803 804 extern void id3tag_set_title( 805 lame_global_flags* gfp, 806 const char* title ); 807 extern void id3tag_set_artist( 808 lame_global_flags* gfp, 809 const char* artist ); 810 extern void id3tag_set_album( 811 lame_global_flags* gfp, 812 const char* album ); 813 extern void id3tag_set_year( 814 lame_global_flags* gfp, 815 const char* year ); 816 extern void id3tag_set_comment( 817 lame_global_flags* gfp, 818 const char* comment ); 819 extern void id3tag_set_track( 820 lame_global_flags* gfp, 821 const char* track ); 822 823 /* return non-zero result if genre name or number is invalid */ 824 extern int id3tag_set_genre( 825 lame_global_flags* gfp, 826 const char* genre ); 827 828 /*********************************************************************** 829 * 830 * list of valid bitrates [kbps] & sample frequencies [Hz]. 831 * first index: 0: MPEG-2 values (sample frequencies 16...24 kHz) 832 * 1: MPEG-1 values (sample frequencies 32...48 kHz) 833 * 2: MPEG-2.5 values (sample frequencies 8...12 kHz) 834 ***********************************************************************/ 835 extern const int bitrate_table [3] [16]; 836 extern const int samplerate_table [3] [ 4]; 837 838 839 840 /* maximum size of mp3buffer needed if you encode at most 1152 samples for 841 each call to lame_encode_buffer. see lame_encode_buffer() below 842 (LAME_MAXMP3BUFFER is now obsolete) */ 843 #define LAME_MAXMP3BUFFER 16384 844 845 846 #if defined(__cplusplus) 847 } 848 #endif 849 #endif /* LAME_LAME_H */ 850