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