lame.h

Go to the documentation of this file.
00001 /*
00002  *      Interface to MP3 LAME encoding engine
00003  *
00004  *      Copyright (c) 1999 Mark Taylor
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 
00022 /* $Id: lame.h,v 1.162 2007/07/24 17:46:10 bouvigne Exp $ */
00023 
00024 #ifndef LAME_LAME_H
00025 #define LAME_LAME_H
00026 
00027 #include <stdio.h>
00028 #include <stdarg.h>
00029 
00030 #if defined(__cplusplus)
00031 extern "C" {
00032 #endif
00033 
00034 #if defined(WIN32)
00035 #undef CDECL
00036 #define CDECL _cdecl
00037 #else
00038 #define CDECL
00039 #endif
00040 
00041 #define DEPRECATED_OR_OBSOLETE_CODE_REMOVED 1
00042 
00043 typedef enum vbr_mode_e {
00044   vbr_off=0,
00045   vbr_mt,               /* obsolete, same as vbr_mtrh */
00046   vbr_rh,
00047   vbr_abr,
00048   vbr_mtrh,
00049   vbr_max_indicator,    /* Don't use this! It's used for sanity checks.       */
00050   vbr_default=vbr_mtrh    /* change this to change the default VBR mode of LAME */
00051 } vbr_mode;
00052 
00053 
00054 /* MPEG modes */
00055 typedef enum MPEG_mode_e {
00056   STEREO = 0,
00057   JOINT_STEREO,
00058   DUAL_CHANNEL,   /* LAME doesn't supports this! */
00059   MONO,
00060   NOT_SET,
00061   MAX_INDICATOR   /* Don't use this! It's used for sanity checks. */
00062 } MPEG_mode;
00063 
00064 /* Padding types */
00065 typedef enum Padding_type_e {
00066   PAD_NO = 0,
00067   PAD_ALL,
00068   PAD_ADJUST,
00069   PAD_MAX_INDICATOR   /* Don't use this! It's used for sanity checks. */
00070 } Padding_type;
00071 
00072 
00073 
00074 /*presets*/
00075 typedef enum preset_mode_e {
00076     /*values from 8 to 320 should be reserved for abr bitrates*/
00077     /*for abr I'd suggest to directly use the targeted bitrate as a value*/
00078     ABR_8 = 8,
00079     ABR_320 = 320,
00080 
00081     V9 = 410, /*Vx to match Lame and VBR_xx to match FhG*/
00082     VBR_10 = 410,
00083     V8 = 420,
00084     VBR_20 = 420,
00085     V7 = 430,
00086     VBR_30 = 430,
00087     V6 = 440,
00088     VBR_40 = 440,
00089     V5 = 450,
00090     VBR_50 = 450,
00091     V4 = 460,
00092     VBR_60 = 460,
00093     V3 = 470,
00094     VBR_70 = 470,
00095     V2 = 480,
00096     VBR_80 = 480,
00097     V1 = 490,
00098     VBR_90 = 490,
00099     V0 = 500,
00100     VBR_100 = 500,
00101 
00102 
00103 
00104     /*still there for compatibility*/
00105     R3MIX = 1000,
00106     STANDARD = 1001,
00107     EXTREME = 1002,
00108     INSANE = 1003,
00109     STANDARD_FAST = 1004,
00110     EXTREME_FAST = 1005,
00111     MEDIUM = 1006,
00112     MEDIUM_FAST = 1007
00113 } preset_mode;
00114 
00115 
00116 /*asm optimizations*/
00117 typedef enum asm_optimizations_e {
00118     MMX = 1,
00119     AMD_3DNOW = 2,
00120     SSE = 3
00121 } asm_optimizations;
00122 
00123 
00124 /* psychoacoustic model */
00125 typedef enum Psy_model_e {
00126     PSY_GPSYCHO = 1,
00127     PSY_NSPSYTUNE = 2
00128 } Psy_model;
00129 
00130 
00131 struct lame_global_struct;
00132 typedef struct lame_global_struct lame_global_flags;
00133 typedef lame_global_flags *lame_t;
00134 
00135 
00136 
00137 
00138 /***********************************************************************
00139  *
00140  *  The LAME API
00141  *  These functions should be called, in this order, for each
00142  *  MP3 file to be encoded.  See the file "API" for more documentation
00143  *
00144  ***********************************************************************/
00145 
00146 
00147 /*
00148  * REQUIRED:
00149  * initialize the encoder.  sets default for all encoder parameters,
00150  * returns NULL if some malloc()'s failed
00151  * otherwise returns pointer to structure needed for all future
00152  * API calls.
00153  */
00154 lame_global_flags * CDECL lame_init(void);
00155 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
00156 #else
00157 /* obsolete version */
00158 int CDECL lame_init_old(lame_global_flags *);
00159 #endif
00160 
00161 /*
00162  * OPTIONAL:
00163  * set as needed to override defaults
00164  */
00165 
00166 /********************************************************************
00167  *  input stream description
00168  ***********************************************************************/
00169 /* number of samples.  default = 2^32-1   */
00170 int CDECL lame_set_num_samples(lame_global_flags *, unsigned long);
00171 unsigned long CDECL lame_get_num_samples(const lame_global_flags *);
00172 
00173 /* input sample rate in Hz.  default = 44100hz */
00174 int CDECL lame_set_in_samplerate(lame_global_flags *, int);
00175 int CDECL lame_get_in_samplerate(const lame_global_flags *);
00176 
00177 /* number of channels in input stream. default=2  */
00178 int CDECL lame_set_num_channels(lame_global_flags *, int);
00179 int CDECL lame_get_num_channels(const lame_global_flags *);
00180 
00181 /*
00182   scale the input by this amount before encoding.  default=0 (disabled)
00183   (not used by decoding routines)
00184 */
00185 int CDECL lame_set_scale(lame_global_flags *, float);
00186 float CDECL lame_get_scale(const lame_global_flags *);
00187 
00188 /*
00189   scale the channel 0 (left) input by this amount before encoding.
00190     default=0 (disabled)
00191   (not used by decoding routines)
00192 */
00193 int CDECL lame_set_scale_left(lame_global_flags *, float);
00194 float CDECL lame_get_scale_left(const lame_global_flags *);
00195 
00196 /*
00197   scale the channel 1 (right) input by this amount before encoding.
00198     default=0 (disabled)
00199   (not used by decoding routines)
00200 */
00201 int CDECL lame_set_scale_right(lame_global_flags *, float);
00202 float CDECL lame_get_scale_right(const lame_global_flags *);
00203 
00204 /*
00205   output sample rate in Hz.  default = 0, which means LAME picks best value
00206   based on the amount of compression.  MPEG only allows:
00207   MPEG1    32, 44.1,   48khz
00208   MPEG2    16, 22.05,  24
00209   MPEG2.5   8, 11.025, 12
00210   (not used by decoding routines)
00211 */
00212 int CDECL lame_set_out_samplerate(lame_global_flags *, int);
00213 int CDECL lame_get_out_samplerate(const lame_global_flags *);
00214 
00215 
00216 /********************************************************************
00217  *  general control parameters
00218  ***********************************************************************/
00219 /* 1=cause LAME to collect data for an MP3 frame analyzer. default=0 */
00220 int CDECL lame_set_analysis(lame_global_flags *, int);
00221 int CDECL lame_get_analysis(const lame_global_flags *);
00222 
00223 /*
00224   1 = write a Xing VBR header frame.
00225   default = 1
00226   this variable must have been added by a Hungarian notation Windows programmer :-)
00227 */
00228 int CDECL lame_set_bWriteVbrTag(lame_global_flags *, int);
00229 int CDECL lame_get_bWriteVbrTag(const lame_global_flags *);
00230 
00231 /* 1=decode only.  use lame/mpglib to convert mp3/ogg to wav.  default=0 */
00232 int CDECL lame_set_decode_only(lame_global_flags *, int);
00233 int CDECL lame_get_decode_only(const lame_global_flags *);
00234 
00235 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
00236 #else
00237 /* 1=encode a Vorbis .ogg file.  default=0 */
00238 /* DEPRECATED */
00239 int CDECL lame_set_ogg(lame_global_flags *, int);
00240 int CDECL lame_get_ogg(const lame_global_flags *);
00241 #endif
00242 
00243 /*
00244   internal algorithm selection.  True quality is determined by the bitrate
00245   but this variable will effect quality by selecting expensive or cheap algorithms.
00246   quality=0..9.  0=best (very slow).  9=worst.
00247   recommended:  2     near-best quality, not too slow
00248                 5     good quality, fast
00249                 7     ok quality, really fast
00250 */
00251 int CDECL lame_set_quality(lame_global_flags *, int);
00252 int CDECL lame_get_quality(const lame_global_flags *);
00253 
00254 /*
00255   mode = 0,1,2,3 = stereo, jstereo, dual channel (not supported), mono
00256   default: lame picks based on compression ration and input channels
00257 */
00258 int CDECL lame_set_mode(lame_global_flags *, MPEG_mode);
00259 MPEG_mode CDECL lame_get_mode(const lame_global_flags *);
00260 
00261 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
00262 #else
00263 /*
00264   mode_automs.  Use a M/S mode with a switching threshold based on
00265   compression ratio
00266   DEPRECATED
00267 */
00268 int CDECL lame_set_mode_automs(lame_global_flags *, int);
00269 int CDECL lame_get_mode_automs(const lame_global_flags *);
00270 #endif
00271 
00272 /*
00273   force_ms.  Force M/S for all frames.  For testing only.
00274   default = 0 (disabled)
00275 */
00276 int CDECL lame_set_force_ms(lame_global_flags *, int);
00277 int CDECL lame_get_force_ms(const lame_global_flags *);
00278 
00279 /* use free_format?  default = 0 (disabled) */
00280 int CDECL lame_set_free_format(lame_global_flags *, int);
00281 int CDECL lame_get_free_format(const lame_global_flags *);
00282 
00283 /* perform ReplayGain analysis?  default = 0 (disabled) */
00284 int CDECL lame_set_findReplayGain(lame_global_flags *, int);
00285 int CDECL lame_get_findReplayGain(const lame_global_flags *);
00286 
00287 /* decode on the fly. Search for the peak sample. If the ReplayGain
00288  * analysis is enabled then perform the analysis on the decoded data
00289  * stream. default = 0 (disabled)
00290  * NOTE: if this option is set the build-in decoder should not be used */
00291 int CDECL lame_set_decode_on_the_fly(lame_global_flags *, int);
00292 int CDECL lame_get_decode_on_the_fly(const lame_global_flags *);
00293 
00294 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
00295 #else
00296 /* DEPRECATED: now does the same as lame_set_findReplayGain()
00297    default = 0 (disabled) */
00298 int CDECL lame_set_ReplayGain_input(lame_global_flags *, int);
00299 int CDECL lame_get_ReplayGain_input(const lame_global_flags *);
00300 
00301 /* DEPRECATED: now does the same as
00302    lame_set_decode_on_the_fly() && lame_set_findReplayGain()
00303    default = 0 (disabled) */
00304 int CDECL lame_set_ReplayGain_decode(lame_global_flags *, int);
00305 int CDECL lame_get_ReplayGain_decode(const lame_global_flags *);
00306 
00307 /* DEPRECATED: now does the same as lame_set_decode_on_the_fly()
00308    default = 0 (disabled) */
00309 int CDECL lame_set_findPeakSample(lame_global_flags *, int);
00310 int CDECL lame_get_findPeakSample(const lame_global_flags *);
00311 #endif
00312 
00313 /* counters for gapless encoding */
00314 int CDECL lame_set_nogap_total(lame_global_flags*, int);
00315 int CDECL lame_get_nogap_total(const lame_global_flags*);
00316 
00317 int CDECL lame_set_nogap_currentindex(lame_global_flags* , int);
00318 int CDECL lame_get_nogap_currentindex(const lame_global_flags*);
00319 
00320 
00321 /*
00322  * OPTIONAL:
00323  * Set printf like error/debug/message reporting functions.
00324  * The second argument has to be a pointer to a function which looks like
00325  *   void my_debugf(const char *format, va_list ap)
00326  *   {
00327  *       (void) vfprintf(stdout, format, ap);
00328  *   }
00329  * If you use NULL as the value of the pointer in the set function, the
00330  * lame buildin function will be used (prints to stderr).
00331  * To quiet any output you have to replace the body of the example function
00332  * with just "return;" and use it in the set function.
00333  */
00334 int CDECL lame_set_errorf(lame_global_flags *,
00335                           void (*func)(const char *, va_list));
00336 int CDECL lame_set_debugf(lame_global_flags *,
00337                           void (*func)(const char *, va_list));
00338 int CDECL lame_set_msgf  (lame_global_flags *,
00339                           void (*func)(const char *, va_list));
00340 
00341 
00342 
00343 /* set one of brate compression ratio.  default is compression ratio of 11.  */
00344 int CDECL lame_set_brate(lame_global_flags *, int);
00345 int CDECL lame_get_brate(const lame_global_flags *);
00346 int CDECL lame_set_compression_ratio(lame_global_flags *, float);
00347 float CDECL lame_get_compression_ratio(const lame_global_flags *);
00348 
00349 
00350 int CDECL lame_set_preset( lame_global_flags*  gfp, int );
00351 int CDECL lame_set_asm_optimizations( lame_global_flags*  gfp, int, int );
00352 
00353 
00354 
00355 /********************************************************************
00356  *  frame params
00357  ***********************************************************************/
00358 /* mark as copyright.  default=0 */
00359 int CDECL lame_set_copyright(lame_global_flags *, int);
00360 int CDECL lame_get_copyright(const lame_global_flags *);
00361 
00362 /* mark as original.  default=1 */
00363 int CDECL lame_set_original(lame_global_flags *, int);
00364 int CDECL lame_get_original(const lame_global_flags *);
00365 
00366 /* error_protection.  Use 2 bytes from each frame for CRC checksum. default=0 */
00367 int CDECL lame_set_error_protection(lame_global_flags *, int);
00368 int CDECL lame_get_error_protection(const lame_global_flags *);
00369 
00370 /* padding_type. 0=pad no frames  1=pad all frames 2=adjust padding(default) */
00371 int CDECL lame_set_padding_type(lame_global_flags *, Padding_type);
00372 Padding_type CDECL lame_get_padding_type(const lame_global_flags *);
00373 
00374 /* MP3 'private extension' bit  Meaningless.  default=0 */
00375 int CDECL lame_set_extension(lame_global_flags *, int);
00376 int CDECL lame_get_extension(const lame_global_flags *);
00377 
00378 /* enforce strict ISO compliance.  default=0 */
00379 int CDECL lame_set_strict_ISO(lame_global_flags *, int);
00380 int CDECL lame_get_strict_ISO(const lame_global_flags *);
00381 
00382 
00383 /********************************************************************
00384  * quantization/noise shaping
00385  ***********************************************************************/
00386 
00387 /* disable the bit reservoir. For testing only. default=0 */
00388 int CDECL lame_set_disable_reservoir(lame_global_flags *, int);
00389 int CDECL lame_get_disable_reservoir(const lame_global_flags *);
00390 
00391 /* select a different "best quantization" function. default=0  */
00392 int CDECL lame_set_quant_comp(lame_global_flags *, int);
00393 int CDECL lame_get_quant_comp(const lame_global_flags *);
00394 int CDECL lame_set_quant_comp_short(lame_global_flags *, int);
00395 int CDECL lame_get_quant_comp_short(const lame_global_flags *);
00396 
00397 int CDECL lame_set_experimentalX(lame_global_flags *, int); /* compatibility*/
00398 int CDECL lame_get_experimentalX(const lame_global_flags *);
00399 
00400 /* another experimental option.  for testing only */
00401 int CDECL lame_set_experimentalY(lame_global_flags *, int);
00402 int CDECL lame_get_experimentalY(const lame_global_flags *);
00403 
00404 /* another experimental option.  for testing only */
00405 int CDECL lame_set_experimentalZ(lame_global_flags *, int);
00406 int CDECL lame_get_experimentalZ(const lame_global_flags *);
00407 
00408 /* Naoki's psycho acoustic model.  default=0 */
00409 int CDECL lame_set_exp_nspsytune(lame_global_flags *, int);
00410 int CDECL lame_get_exp_nspsytune(const lame_global_flags *);
00411 
00412 void CDECL lame_set_msfix(lame_global_flags *, double);
00413 float CDECL lame_get_msfix(const lame_global_flags *);
00414 
00415 
00416 /********************************************************************
00417  * VBR control
00418  ***********************************************************************/
00419 /* Types of VBR.  default = vbr_off = CBR */
00420 int CDECL lame_set_VBR(lame_global_flags *, vbr_mode);
00421 vbr_mode CDECL lame_get_VBR(const lame_global_flags *);
00422 
00423 /* VBR quality level.  0=highest  9=lowest  */
00424 int CDECL lame_set_VBR_q(lame_global_flags *, int);
00425 int CDECL lame_get_VBR_q(const lame_global_flags *);
00426 
00427 /* Ignored except for VBR=vbr_abr (ABR mode) */
00428 int CDECL lame_set_VBR_mean_bitrate_kbps(lame_global_flags *, int);
00429 int CDECL lame_get_VBR_mean_bitrate_kbps(const lame_global_flags *);
00430 
00431 int CDECL lame_set_VBR_min_bitrate_kbps(lame_global_flags *, int);
00432 int CDECL lame_get_VBR_min_bitrate_kbps(const lame_global_flags *);
00433 
00434 int CDECL lame_set_VBR_max_bitrate_kbps(lame_global_flags *, int);
00435 int CDECL lame_get_VBR_max_bitrate_kbps(const lame_global_flags *);
00436 
00437 /*
00438   1=strictly enforce VBR_min_bitrate.  Normally it will be violated for
00439   analog silence
00440 */
00441 int CDECL lame_set_VBR_hard_min(lame_global_flags *, int);
00442 int CDECL lame_get_VBR_hard_min(const lame_global_flags *);
00443 
00444 /* for preset */
00445 int CDECL lame_set_preset_expopts(lame_global_flags *, int);
00446 
00447 
00448 /********************************************************************
00449  * Filtering control
00450  ***********************************************************************/
00451 /* freq in Hz to apply lowpass. Default = 0 = lame chooses.  -1 = disabled */
00452 int CDECL lame_set_lowpassfreq(lame_global_flags *, int);
00453 int CDECL lame_get_lowpassfreq(const lame_global_flags *);
00454 /* width of transition band, in Hz.  Default = one polyphase filter band */
00455 int CDECL lame_set_lowpasswidth(lame_global_flags *, int);
00456 int CDECL lame_get_lowpasswidth(const lame_global_flags *);
00457 
00458 /* freq in Hz to apply highpass. Default = 0 = lame chooses.  -1 = disabled */
00459 int CDECL lame_set_highpassfreq(lame_global_flags *, int);
00460 int CDECL lame_get_highpassfreq(const lame_global_flags *);
00461 /* width of transition band, in Hz.  Default = one polyphase filter band */
00462 int CDECL lame_set_highpasswidth(lame_global_flags *, int);
00463 int CDECL lame_get_highpasswidth(const lame_global_flags *);
00464 
00465 
00466 /********************************************************************
00467  * psycho acoustics and other arguments which you should not change
00468  * unless you know what you are doing
00469  ***********************************************************************/
00470 
00471 /* only use ATH for masking */
00472 int CDECL lame_set_ATHonly(lame_global_flags *, int);
00473 int CDECL lame_get_ATHonly(const lame_global_flags *);
00474 
00475 /* only use ATH for short blocks */
00476 int CDECL lame_set_ATHshort(lame_global_flags *, int);
00477 int CDECL lame_get_ATHshort(const lame_global_flags *);
00478 
00479 /* disable ATH */
00480 int CDECL lame_set_noATH(lame_global_flags *, int);
00481 int CDECL lame_get_noATH(const lame_global_flags *);
00482 
00483 /* select ATH formula */
00484 int CDECL lame_set_ATHtype(lame_global_flags *, int);
00485 int CDECL lame_get_ATHtype(const lame_global_flags *);
00486 
00487 /* lower ATH by this many db */
00488 int CDECL lame_set_ATHlower(lame_global_flags *, float);
00489 float CDECL lame_get_ATHlower(const lame_global_flags *);
00490 
00491 /* select ATH adaptive adjustment type */
00492 int CDECL lame_set_athaa_type( lame_global_flags *, int);
00493 int CDECL lame_get_athaa_type( const lame_global_flags *);
00494 
00495 /* select the loudness approximation used by the ATH adaptive auto-leveling  */
00496 int CDECL lame_set_athaa_loudapprox( lame_global_flags *, int);
00497 int CDECL lame_get_athaa_loudapprox( const lame_global_flags *);
00498 
00499 /* adjust (in dB) the point below which adaptive ATH level adjustment occurs */
00500 int CDECL lame_set_athaa_sensitivity( lame_global_flags *, float);
00501 float CDECL lame_get_athaa_sensitivity( const lame_global_flags* );
00502 
00503 /* predictability limit (ISO tonality formula) */
00504 int CDECL lame_set_cwlimit(lame_global_flags *, int);
00505 int CDECL lame_get_cwlimit(const lame_global_flags *);
00506 
00507 /*
00508   allow blocktypes to differ between channels?
00509   default: 0 for jstereo, 1 for stereo
00510 */
00511 int CDECL lame_set_allow_diff_short(lame_global_flags *, int);
00512 int CDECL lame_get_allow_diff_short(const lame_global_flags *);
00513 
00514 /* use temporal masking effect (default = 1) */
00515 int CDECL lame_set_useTemporal(lame_global_flags *, int);
00516 int CDECL lame_get_useTemporal(const lame_global_flags *);
00517 
00518 /* use temporal masking effect (default = 1) */
00519 int CDECL lame_set_interChRatio(lame_global_flags *, float);
00520 float CDECL lame_get_interChRatio(const lame_global_flags *);
00521 
00522 /* disable short blocks */
00523 int CDECL lame_set_no_short_blocks(lame_global_flags *, int);
00524 int CDECL lame_get_no_short_blocks(const lame_global_flags *);
00525 
00526 /* force short blocks */
00527 int CDECL lame_set_force_short_blocks(lame_global_flags *, int);
00528 int CDECL lame_get_force_short_blocks(const lame_global_flags *);
00529 
00530 /* Input PCM is emphased PCM (for instance from one of the rarely
00531    emphased CDs), it is STRONGLY not recommended to use this, because
00532    psycho does not take it into account, and last but not least many decoders
00533    ignore these bits */
00534 int CDECL lame_set_emphasis(lame_global_flags *, int);
00535 int CDECL lame_get_emphasis(const lame_global_flags *);
00536 
00537 
00538 
00539 /************************************************************************/
00540 /* internal variables, cannot be set...                                 */
00541 /* provided because they may be of use to calling application           */
00542 /************************************************************************/
00543 /* version  0=MPEG-2  1=MPEG-1  (2=MPEG-2.5)     */
00544 int CDECL lame_get_version(const lame_global_flags *);
00545 
00546 /* encoder delay   */
00547 int CDECL lame_get_encoder_delay(const lame_global_flags *);
00548 
00549 /*
00550   padding appended to the input to make sure decoder can fully decode
00551   all input.  Note that this value can only be calculated during the
00552   call to lame_encoder_flush().  Before lame_encoder_flush() has
00553   been called, the value of encoder_padding = 0.
00554 */
00555 int CDECL lame_get_encoder_padding(const lame_global_flags *);
00556 
00557 /* size of MPEG frame */
00558 int CDECL lame_get_framesize(const lame_global_flags *);
00559 
00560 /* number of PCM samples buffered, but not yet encoded to mp3 data. */
00561 int CDECL lame_get_mf_samples_to_encode( const lame_global_flags*  gfp );
00562 
00563 /*
00564   size (bytes) of mp3 data buffered, but not yet encoded.
00565   this is the number of bytes which would be output by a call to
00566   lame_encode_flush_nogap.  NOTE: lame_encode_flush() will return
00567   more bytes than this because it will encode the reamining buffered
00568   PCM samples before flushing the mp3 buffers.
00569 */
00570 int CDECL lame_get_size_mp3buffer( const lame_global_flags*  gfp );
00571 
00572 /* number of frames encoded so far */
00573 int CDECL lame_get_frameNum(const lame_global_flags *);
00574 
00575 /*
00576   lame's estimate of the total number of frames to be encoded
00577    only valid if calling program set num_samples
00578 */
00579 int CDECL lame_get_totalframes(const lame_global_flags *);
00580 
00581 /* RadioGain value. Multiplied by 10 and rounded to the nearest. */
00582 int CDECL lame_get_RadioGain(const lame_global_flags *);
00583 
00584 /* AudiophileGain value. Multipled by 10 and rounded to the nearest. */
00585 int CDECL lame_get_AudiophileGain(const lame_global_flags *);
00586 
00587 /* the peak sample */
00588 float CDECL lame_get_PeakSample(const lame_global_flags *);
00589 
00590 /* Gain change required for preventing clipping. The value is correct only if
00591    peak sample searching was enabled. If negative then the waveform
00592    already does not clip. The value is multiplied by 10 and rounded up. */
00593 int CDECL lame_get_noclipGainChange(const lame_global_flags *);
00594 
00595 /* user-specified scale factor required for preventing clipping. Value is
00596    correct only if peak sample searching was enabled and no user-specified
00597    scaling was performed. If negative then either the waveform already does
00598    not clip or the value cannot be determined */
00599 float CDECL lame_get_noclipScale(const lame_global_flags *);
00600 
00601 
00602 
00603 
00604 
00605 
00606 
00607 /*
00608  * REQUIRED:
00609  * sets more internal configuration based on data provided above.
00610  * returns -1 if something failed.
00611  */
00612 int CDECL lame_init_params(lame_global_flags * const );
00613 
00614 
00615 /*
00616  * OPTIONAL:
00617  * get the version number, in a string. of the form:
00618  * "3.63 (beta)" or just "3.63".
00619  */
00620 const char*  CDECL get_lame_version       ( void );
00621 const char*  CDECL get_lame_short_version ( void );
00622 const char*  CDECL get_lame_very_short_version ( void );
00623 const char*  CDECL get_psy_version        ( void );
00624 const char*  CDECL get_lame_url           ( void );
00625 
00626 /*
00627  * OPTIONAL:
00628  * get the version numbers in numerical form.
00629  */
00630 typedef struct {
00631     /* generic LAME version */
00632     int major;
00633     int minor;
00634     int alpha;               /* 0 if not an alpha version                  */
00635     int beta;                /* 0 if not a beta version                    */
00636 
00637     /* version of the psy model */
00638     int psy_major;
00639     int psy_minor;
00640     int psy_alpha;           /* 0 if not an alpha version                  */
00641     int psy_beta;            /* 0 if not a beta version                    */
00642 
00643     /* compile time features */
00644     const char *features;    /* Don't make assumptions about the contents! */
00645 } lame_version_t;
00646 void CDECL get_lame_version_numerical ( lame_version_t *const );
00647 
00648 
00649 /*
00650  * OPTIONAL:
00651  * print internal lame configuration to message handler
00652  */
00653 void CDECL lame_print_config(const lame_global_flags*  gfp);
00654 
00655 void CDECL lame_print_internals( const lame_global_flags *gfp);
00656 
00657 
00658 /*
00659  * input pcm data, output (maybe) mp3 frames.
00660  * This routine handles all buffering, resampling and filtering for you.
00661  *
00662  * return code     number of bytes output in mp3buf. Can be 0
00663  *                 -1:  mp3buf was too small
00664  *                 -2:  malloc() problem
00665  *                 -3:  lame_init_params() not called
00666  *                 -4:  psycho acoustic problems
00667  *
00668  * The required mp3buf_size can be computed from num_samples,
00669  * samplerate and encoding rate, but here is a worst case estimate:
00670  *
00671  * mp3buf_size in bytes = 1.25*num_samples + 7200
00672  *
00673  * I think a tighter bound could be:  (mt, March 2000)
00674  * MPEG1:
00675  *    num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
00676  * MPEG2:
00677  *    num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
00678  *
00679  * but test first if you use that!
00680  *
00681  * set mp3buf_size = 0 and LAME will not check if mp3buf_size is
00682  * large enough.
00683  *
00684  * NOTE:
00685  * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
00686  * will be averaged into the L channel before encoding only the L channel
00687  * This will overwrite the data in buffer_l[] and buffer_r[].
00688  *
00689 */
00690 int CDECL lame_encode_buffer (
00691         lame_global_flags*  gfp,           /* global context handle         */
00692         const short int     buffer_l [],   /* PCM data for left channel     */
00693         const short int     buffer_r [],   /* PCM data for right channel    */
00694         const int           nsamples,      /* number of samples per channel */
00695         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00696         const int           mp3buf_size ); /* number of valid octets in this
00697                                               stream                        */
00698 
00699 /*
00700  * as above, but input has L & R channel data interleaved.
00701  * NOTE:
00702  * num_samples = number of samples in the L (or R)
00703  * channel, not the total number of samples in pcm[]
00704  */
00705 int CDECL lame_encode_buffer_interleaved(
00706         lame_global_flags*  gfp,           /* global context handlei        */
00707         short int           pcm[],         /* PCM data for left and right
00708                                               channel, interleaved          */
00709         int                 num_samples,   /* number of samples per channel,
00710                                               _not_ number of samples in
00711                                               pcm[]                         */
00712         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00713         int                 mp3buf_size ); /* number of valid octets in this
00714                                               stream                        */
00715 
00716 
00717 /* as lame_encode_buffer, but for 'float's.
00718  * !! NOTE: !! data must still be scaled to be in the same range as
00719  * short int, +/- 32768
00720  */
00721 int CDECL lame_encode_buffer_float(
00722         lame_global_flags*  gfp,           /* global context handle         */
00723         const float     buffer_l [],       /* PCM data for left channel     */
00724         const float     buffer_r [],       /* PCM data for right channel    */
00725         const int           nsamples,      /* number of samples per channel */
00726         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00727         const int           mp3buf_size ); /* number of valid octets in this
00728                                               stream                        */
00729 
00730 
00731 /* as lame_encode_buffer, but for long's
00732  * !! NOTE: !! data must still be scaled to be in the same range as
00733  * short int, +/- 32768
00734  *
00735  * This scaling was a mistake (doesn't allow one to exploit full
00736  * precision of type 'long'.  Use lame_encode_buffer_long2() instead.
00737  *
00738  */
00739 int CDECL lame_encode_buffer_long(
00740         lame_global_flags*  gfp,           /* global context handle         */
00741         const long     buffer_l [],       /* PCM data for left channel     */
00742         const long     buffer_r [],       /* PCM data for right channel    */
00743         const int           nsamples,      /* number of samples per channel */
00744         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00745         const int           mp3buf_size ); /* number of valid octets in this
00746                                               stream                        */
00747 
00748 /* Same as lame_encode_buffer_long(), but with correct scaling.
00749  * !! NOTE: !! data must still be scaled to be in the same range as
00750  * type 'long'.   Data should be in the range:  +/- 2^(8*size(long)-1)
00751  *
00752  */
00753 int CDECL lame_encode_buffer_long2(
00754         lame_global_flags*  gfp,           /* global context handle         */
00755         const long     buffer_l [],       /* PCM data for left channel     */
00756         const long     buffer_r [],       /* PCM data for right channel    */
00757         const int           nsamples,      /* number of samples per channel */
00758         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00759         const int           mp3buf_size ); /* number of valid octets in this
00760                                               stream                        */
00761 
00762 /* as lame_encode_buffer, but for int's
00763  * !! NOTE: !! input should be scaled to the maximum range of 'int'
00764  * If int is 4 bytes, then the values should range from
00765  * +/- 2147483648.
00766  *
00767  * This routine does not (and cannot, without loosing precision) use
00768  * the same scaling as the rest of the lame_encode_buffer() routines.
00769  *
00770  */
00771 int CDECL lame_encode_buffer_int(
00772         lame_global_flags*  gfp,           /* global context handle         */
00773         const int      buffer_l [],       /* PCM data for left channel     */
00774         const int      buffer_r [],       /* PCM data for right channel    */
00775         const int           nsamples,      /* number of samples per channel */
00776         unsigned char*      mp3buf,        /* pointer to encoded MP3 stream */
00777         const int           mp3buf_size ); /* number of valid octets in this
00778                                               stream                        */
00779 
00780 
00781 
00782 
00783 
00784 /*
00785  * REQUIRED:
00786  * lame_encode_flush will flush the intenal PCM buffers, padding with
00787  * 0's to make sure the final frame is complete, and then flush
00788  * the internal MP3 buffers, and thus may return a
00789  * final few mp3 frames.  'mp3buf' should be at least 7200 bytes long
00790  * to hold all possible emitted data.
00791  *
00792  * will also write id3v1 tags (if any) into the bitstream
00793  *
00794  * return code = number of bytes output to mp3buf. Can be 0
00795  */
00796 int CDECL lame_encode_flush(
00797         lame_global_flags *  gfp,    /* global context handle                 */
00798         unsigned char*       mp3buf, /* pointer to encoded MP3 stream         */
00799         int                  size);  /* number of valid octets in this stream */
00800 
00801 /*
00802  * OPTIONAL:
00803  * lame_encode_flush_nogap will flush the internal mp3 buffers and pad
00804  * the last frame with ancillary data so it is a complete mp3 frame.
00805  *
00806  * 'mp3buf' should be at least 7200 bytes long
00807  * to hold all possible emitted data.
00808  *
00809  * After a call to this routine, the outputed mp3 data is complete, but
00810  * you may continue to encode new PCM samples and write future mp3 data
00811  * to a different file.  The two mp3 files will play back with no gaps
00812  * if they are concatenated together.
00813  *
00814  * This routine will NOT write id3v1 tags into the bitstream.
00815  *
00816  * return code = number of bytes output to mp3buf. Can be 0
00817  */
00818 int CDECL lame_encode_flush_nogap(
00819         lame_global_flags *  gfp,    /* global context handle                 */
00820         unsigned char*       mp3buf, /* pointer to encoded MP3 stream         */
00821         int                  size);  /* number of valid octets in this stream */
00822 
00823 /*
00824  * OPTIONAL:
00825  * Normally, this is called by lame_init_params().  It writes id3v2 and
00826  * Xing headers into the front of the bitstream, and sets frame counters
00827  * and bitrate histogram data to 0.  You can also call this after
00828  * lame_encode_flush_nogap().
00829  */
00830 int CDECL lame_init_bitstream(
00831         lame_global_flags *  gfp);    /* global context handle                 */
00832 
00833 
00834 
00835 /*
00836  * OPTIONAL:    some simple statistics
00837  * a bitrate histogram to visualize the distribution of used frame sizes
00838  * a stereo mode histogram to visualize the distribution of used stereo
00839  *   modes, useful in joint-stereo mode only
00840  *   0: LR    left-right encoded
00841  *   1: LR-I  left-right and intensity encoded (currently not supported)
00842  *   2: MS    mid-side encoded
00843  *   3: MS-I  mid-side and intensity encoded (currently not supported)
00844  *
00845  * attention: don't call them after lame_encode_finish
00846  * suggested: lame_encode_flush -> lame_*_hist -> lame_close
00847  */
00848 
00849 void CDECL lame_bitrate_hist(
00850         const lame_global_flags *const gfp,
00851               int                      bitrate_count[14] );
00852 void CDECL lame_bitrate_kbps(
00853         const lame_global_flags *const gfp,
00854               int                      bitrate_kbps [14] );
00855 void CDECL lame_stereo_mode_hist(
00856         const lame_global_flags *const gfp,
00857               int                      stereo_mode_count[4] );
00858 
00859 void CDECL lame_bitrate_stereo_mode_hist (
00860         const lame_global_flags * const gfp,
00861         int  bitrate_stmode_count [14] [4] );
00862 
00863 void CDECL lame_block_type_hist (
00864         const lame_global_flags * const gfp,
00865         int btype_count[6] );
00866 
00867 void CDECL lame_bitrate_block_type_hist (
00868         const lame_global_flags * const gfp,
00869         int bitrate_btype_count[14][6] );
00870 
00871 
00872 /*
00873  * OPTIONAL:
00874  * lame_mp3_tags_fid will rewrite a Xing VBR tag to the mp3 file with file
00875  * pointer fid.  These calls perform forward and backwards seeks, so make
00876  * sure fid is a real file.  Make sure lame_encode_flush has been called,
00877  * and all mp3 data has been written to the file before calling this
00878  * function.
00879  * NOTE:
00880  * if VBR  tags are turned off by the user, or turned off by LAME because
00881  * the output is not a regular file, this call does nothing
00882  * NOTE:
00883  * LAME wants to read from the file to skip an optional ID3v2 tag, so
00884  * make sure you opened the file for writing and reading.
00885 */
00886 void CDECL lame_mp3_tags_fid(lame_global_flags *,FILE* fid);
00887 
00888 
00889 /*
00890  * REQUIRED:
00891  * final call to free all remaining buffers
00892  */
00893 int  CDECL lame_close (lame_global_flags *);
00894 
00895 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
00896 #else
00897 /*
00898  * OBSOLETE:
00899  * lame_encode_finish combines lame_encode_flush() and lame_close() in
00900  * one call.  However, once this call is made, the statistics routines
00901  * will no longer work because the data will have been cleared, and
00902  * lame_mp3_tags_fid() cannot be called to add data to the VBR header
00903  */
00904 int CDECL lame_encode_finish(
00905         lame_global_flags*  gfp,
00906         unsigned char*      mp3buf,
00907         int                 size );
00908 #endif
00909 
00910 
00911 
00912 
00913 
00914 
00915 /*********************************************************************
00916  *
00917  * decoding
00918  *
00919  * a simple interface to mpglib, part of mpg123, is also included if
00920  * libmp3lame is compiled with HAVE_MPGLIB
00921  *
00922  *********************************************************************/
00923 typedef struct {
00924   int header_parsed;   /* 1 if header was parsed and following data was
00925                           computed                                       */
00926   int stereo;          /* number of channels                             */
00927   int samplerate;      /* sample rate                                    */
00928   int bitrate;         /* bitrate                                        */
00929   int mode;            /* mp3 frame type                                 */
00930   int mode_ext;        /* mp3 frame type                                 */
00931   int framesize;       /* number of samples per mp3 frame                */
00932 
00933   /* this data is only computed if mpglib detects a Xing VBR header */
00934   unsigned long nsamp; /* number of samples in mp3 file.                 */
00935   int totalframes;     /* total number of frames in mp3 file             */
00936 
00937   /* this data is not currently computed by the mpglib routines */
00938   int framenum;        /* frames decoded counter                         */
00939 } mp3data_struct;
00940 
00941 
00942 /* required call to initialize decoder
00943  * NOTE: the decoder should not be used when encoding is performed
00944  * with decoding on the fly */
00945 int CDECL lame_decode_init(void);
00946 
00947 /*********************************************************************
00948  * input 1 mp3 frame, output (maybe) pcm data.
00949  *
00950  *  nout = lame_decode(mp3buf,len,pcm_l,pcm_r);
00951  *
00952  * input:
00953  *    len          :  number of bytes of mp3 data in mp3buf
00954  *    mp3buf[len]  :  mp3 data to be decoded
00955  *
00956  * output:
00957  *    nout:  -1    : decoding error
00958  *            0    : need more data before we can complete the decode
00959  *           >0    : returned 'nout' samples worth of data in pcm_l,pcm_r
00960  *    pcm_l[nout]  : left channel data
00961  *    pcm_r[nout]  : right channel data
00962  *
00963  *********************************************************************/
00964 int CDECL lame_decode(
00965         unsigned char *  mp3buf,
00966         int              len,
00967         short            pcm_l[],
00968         short            pcm_r[] );
00969 
00970 /* same as lame_decode, and also returns mp3 header data */
00971 int CDECL lame_decode_headers(
00972         unsigned char*   mp3buf,
00973         int              len,
00974         short            pcm_l[],
00975         short            pcm_r[],
00976         mp3data_struct*  mp3data );
00977 
00978 /* same as lame_decode, but returns at most one frame */
00979 int CDECL lame_decode1(
00980         unsigned char*  mp3buf,
00981         int             len,
00982         short           pcm_l[],
00983         short           pcm_r[] );
00984 
00985 /* same as lame_decode1, but returns at most one frame and mp3 header data */
00986 int CDECL lame_decode1_headers(
00987         unsigned char*   mp3buf,
00988         int              len,
00989         short            pcm_l[],
00990         short            pcm_r[],
00991         mp3data_struct*  mp3data );
00992 
00993 /* same as lame_decode1_headers, but also returns enc_delay and enc_padding
00994    from VBR Info tag, (-1 if no info tag was found) */
00995 int CDECL lame_decode1_headersB(
00996         unsigned char*   mp3buf,
00997         int              len,
00998         short            pcm_l[],
00999         short            pcm_r[],
01000         mp3data_struct*  mp3data,
01001         int              *enc_delay,
01002         int              *enc_padding );
01003 
01004 
01005 /* cleanup call to exit decoder  */
01006 int CDECL lame_decode_exit(void);
01007 
01008 
01009 
01010 /*********************************************************************
01011  *
01012  * id3tag stuff
01013  *
01014  *********************************************************************/
01015 
01016 /*
01017  * id3tag.h -- Interface to write ID3 version 1 and 2 tags.
01018  *
01019  * Copyright (C) 2000 Don Melton.
01020  *
01021  * This library is free software; you can redistribute it and/or
01022  * modify it under the terms of the GNU Library General Public
01023  * License as published by the Free Software Foundation; either
01024  * version 2 of the License, or (at your option) any later version.
01025  *
01026  * This library is distributed in the hope that it will be useful,
01027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
01028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
01029  * Library General Public License for more details.
01030  *
01031  * You should have received a copy of the GNU Library General Public
01032  * License along with this library; if not, write to the Free Software
01033  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
01034  */
01035 
01036 /* utility to obtain alphabetically sorted list of genre names with numbers */
01037 extern void id3tag_genre_list(
01038         void (*handler)(int, const char *, void *),
01039         void*  cookie);
01040 
01041 extern void id3tag_init   (lame_global_flags *gfp);
01042 
01043 /* force addition of version 2 tag */
01044 extern void id3tag_add_v2   (lame_global_flags *gfp);
01045 
01046 /* add only a version 1 tag */
01047 extern void id3tag_v1_only  (lame_global_flags *gfp);
01048 
01049 /* add only a version 2 tag */
01050 extern void id3tag_v2_only  (lame_global_flags *gfp);
01051 
01052 /* pad version 1 tag with spaces instead of nulls */
01053 extern void id3tag_space_v1 (lame_global_flags *gfp);
01054 
01055 /* pad version 2 tag with extra 128 bytes */
01056 extern void id3tag_pad_v2   (lame_global_flags *gfp);
01057 
01058 extern void id3tag_set_title(
01059         lame_global_flags*  gfp,
01060         const char*         title );
01061 extern void id3tag_set_artist(
01062         lame_global_flags*  gfp,
01063         const char*         artist );
01064 extern void id3tag_set_album(
01065         lame_global_flags*  gfp,
01066         const char*         album );
01067 extern void id3tag_set_year(
01068         lame_global_flags*  gfp,
01069         const char*         year );
01070 extern void id3tag_set_comment(
01071         lame_global_flags*  gfp,
01072         const char*         comment );
01073             
01074 /* return -1 result if track number is out of ID3v1 range
01075                     and ignored for ID3v1 */
01076 extern int id3tag_set_track(
01077         lame_global_flags*  gfp,
01078         const char*         track );
01079 
01080 /* return non-zero result if genre name or number is invalid
01081   result 0: OK
01082   result -1: genre number out of range
01083   result -2: no valid ID3v1 genre name, mapped to ID3v1 'Other'
01084              but taken as-is for ID3v2 genre tag */
01085 extern int id3tag_set_genre(
01086         lame_global_flags*  gfp,
01087         const char*         genre );
01088 
01089 /* return non-zero result if field name is invalid */
01090 extern int id3tag_set_fieldvalue(
01091         lame_global_flags*  gfp,
01092         const char*         fieldvalue);
01093 
01094 /* return non-zero result if image type is invalid */
01095 extern int id3tag_set_albumart(
01096         lame_global_flags*  gfp,
01097         const char*         image,
01098         unsigned long       size );
01099 
01100 /***********************************************************************
01101 *
01102 *  list of valid bitrates [kbps] & sample frequencies [Hz].
01103 *  first index: 0: MPEG-2   values  (sample frequencies 16...24 kHz)
01104 *               1: MPEG-1   values  (sample frequencies 32...48 kHz)
01105 *               2: MPEG-2.5 values  (sample frequencies  8...12 kHz)
01106 ***********************************************************************/
01107 extern const int      bitrate_table    [3] [16];
01108 extern const int      samplerate_table [3] [ 4];
01109 
01110 
01111 
01112 /* maximum size of albumart image (128KB), which affects LAME_MAXMP3BUFFER
01113    as well since lame_encode_buffer() also returns ID3v2 tag data */
01114 #define LAME_MAXALBUMART    (128 * 1024)
01115 
01116 /* maximum size of mp3buffer needed if you encode at most 1152 samples for
01117    each call to lame_encode_buffer.  see lame_encode_buffer() below  
01118    (LAME_MAXMP3BUFFER is now obsolete)  */
01119 #define LAME_MAXMP3BUFFER   (16384 + LAME_MAXALBUMART)
01120 
01121 
01122 typedef enum {
01123     LAME_OKAY             =   0,
01124     LAME_NOERROR          =   0,
01125     LAME_GENERICERROR     =  -1,
01126     LAME_NOMEM            = -10,
01127     LAME_BADBITRATE       = -11,
01128     LAME_BADSAMPFREQ      = -12,
01129     LAME_INTERNALERROR    = -13,
01130 
01131     FRONTEND_READERROR    = -80,
01132     FRONTEND_WRITEERROR   = -81,
01133     FRONTEND_FILETOOLARGE = -82
01134 
01135 } lame_errorcodes_t;
01136 
01137 #if defined(__cplusplus)
01138 }
01139 #endif
01140 #endif /* LAME_LAME_H */
01141 

Generated on Sun Dec 2 11:34:18 2007 for LAME by  doxygen 1.5.2