1 /* -*- mode: C; mode: fold -*- */
3 * set/get functions for lame_global_flags
5 * Copyright (c) 2001-2005 Alexander Leidinger
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* $Id: set_get.c,v 1.98 2011/05/07 16:05:17 rbrito Exp $ */
33 #include "bitstream.h" /* because of compute_flushbits */
36 #include "lame_global_flags.h"
39 * input stream description
43 /* number of samples */
44 /* it's unlikely for this function to return an error */
46 lame_set_num_samples(lame_global_flags * gfp, unsigned long num_samples)
48 if (is_lame_global_flags_valid(gfp)) {
49 /* default = 2^32-1 */
50 gfp->num_samples = num_samples;
57 lame_get_num_samples(const lame_global_flags * gfp)
59 if (is_lame_global_flags_valid(gfp)) {
60 return gfp->num_samples;
66 /* input samplerate */
68 lame_set_in_samplerate(lame_global_flags * gfp, int in_samplerate)
70 if (is_lame_global_flags_valid(gfp)) {
71 /* input sample rate in Hz, default = 44100 Hz */
72 gfp->samplerate_in = in_samplerate;
79 lame_get_in_samplerate(const lame_global_flags * gfp)
81 if (is_lame_global_flags_valid(gfp)) {
82 return gfp->samplerate_in;
88 /* number of channels in input stream */
90 lame_set_num_channels(lame_global_flags * gfp, int num_channels)
92 if (is_lame_global_flags_valid(gfp)) {
94 if (2 < num_channels || 0 == num_channels) {
95 return -1; /* we don't support more than 2 channels */
97 gfp->num_channels = num_channels;
104 lame_get_num_channels(const lame_global_flags * gfp)
106 if (is_lame_global_flags_valid(gfp)) {
107 return gfp->num_channels;
113 /* scale the input by this amount before encoding (not used for decoding) */
115 lame_set_scale(lame_global_flags * gfp, float scale)
117 if (is_lame_global_flags_valid(gfp)) {
126 lame_get_scale(const lame_global_flags * gfp)
128 if (is_lame_global_flags_valid(gfp)) {
135 /* scale the channel 0 (left) input by this amount before
136 encoding (not used for decoding) */
138 lame_set_scale_left(lame_global_flags * gfp, float scale)
140 if (is_lame_global_flags_valid(gfp)) {
142 gfp->scale_left = scale;
149 lame_get_scale_left(const lame_global_flags * gfp)
151 if (is_lame_global_flags_valid(gfp)) {
152 return gfp->scale_left;
158 /* scale the channel 1 (right) input by this amount before
159 encoding (not used for decoding) */
161 lame_set_scale_right(lame_global_flags * gfp, float scale)
163 if (is_lame_global_flags_valid(gfp)) {
165 gfp->scale_right = scale;
172 lame_get_scale_right(const lame_global_flags * gfp)
174 if (is_lame_global_flags_valid(gfp)) {
175 return gfp->scale_right;
181 /* output sample rate in Hz */
183 lame_set_out_samplerate(lame_global_flags * gfp, int out_samplerate)
185 if (is_lame_global_flags_valid(gfp)) {
187 * default = 0: LAME picks best value based on the amount
190 * MPEG1 32, 44.1, 48khz
191 * MPEG2 16, 22.05, 24
192 * MPEG2.5 8, 11.025, 12
194 * (not used by decoding routines)
196 gfp->samplerate_out = out_samplerate;
203 lame_get_out_samplerate(const lame_global_flags * gfp)
205 if (is_lame_global_flags_valid(gfp)) {
206 return gfp->samplerate_out;
215 * general control parameters
218 /* collect data for an MP3 frame analzyer */
220 lame_set_analysis(lame_global_flags * gfp, int analysis)
222 if (is_lame_global_flags_valid(gfp)) {
225 /* enforce disable/enable meaning, if we need more than two values
226 we need to switch to an enum to have an apropriate representation
227 of the possible meanings of the value */
228 if (0 > analysis || 1 < analysis)
230 gfp->analysis = analysis;
237 lame_get_analysis(const lame_global_flags * gfp)
239 if (is_lame_global_flags_valid(gfp)) {
240 assert(0 <= gfp->analysis && 1 >= gfp->analysis);
241 return gfp->analysis;
247 /* write a Xing VBR header frame */
249 lame_set_bWriteVbrTag(lame_global_flags * gfp, int bWriteVbrTag)
251 if (is_lame_global_flags_valid(gfp)) {
252 /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
254 /* enforce disable/enable meaning, if we need more than two values
255 we need to switch to an enum to have an apropriate representation
256 of the possible meanings of the value */
257 if (0 > bWriteVbrTag || 1 < bWriteVbrTag)
259 gfp->write_lame_tag = bWriteVbrTag;
266 lame_get_bWriteVbrTag(const lame_global_flags * gfp)
268 if (is_lame_global_flags_valid(gfp)) {
269 assert(0 <= gfp->write_lame_tag && 1 >= gfp->write_lame_tag);
270 return gfp->write_lame_tag;
277 /* decode only, use lame/mpglib to convert mp3 to wav */
279 lame_set_decode_only(lame_global_flags * gfp, int decode_only)
281 if (is_lame_global_flags_valid(gfp)) {
282 /* default = 0 (disabled) */
284 /* enforce disable/enable meaning, if we need more than two values
285 we need to switch to an enum to have an apropriate representation
286 of the possible meanings of the value */
287 if (0 > decode_only || 1 < decode_only)
289 gfp->decode_only = decode_only;
296 lame_get_decode_only(const lame_global_flags * gfp)
298 if (is_lame_global_flags_valid(gfp)) {
299 assert(0 <= gfp->decode_only && 1 >= gfp->decode_only);
300 return gfp->decode_only;
306 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
307 /* 1=encode a Vorbis .ogg file. default=0 */
309 int CDECL lame_set_ogg(lame_global_flags *, int);
310 int CDECL lame_get_ogg(const lame_global_flags *);
314 /* encode a Vorbis .ogg file */
317 lame_set_ogg(lame_global_flags * gfp, int ogg)
325 lame_get_ogg(const lame_global_flags * gfp)
333 * Internal algorithm selection.
334 * True quality is determined by the bitrate but this variable will effect
335 * quality by selecting expensive or cheap algorithms.
336 * quality=0..9. 0=best (very slow). 9=worst.
337 * recommended: 3 near-best quality, not too slow
338 * 5 good quality, fast
339 * 7 ok quality, really fast
342 lame_set_quality(lame_global_flags * gfp, int quality)
344 if (is_lame_global_flags_valid(gfp)) {
348 else if (quality > 9) {
352 gfp->quality = quality;
360 lame_get_quality(const lame_global_flags * gfp)
362 if (is_lame_global_flags_valid(gfp)) {
369 /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
371 lame_set_mode(lame_global_flags * gfp, MPEG_mode mode)
373 if (is_lame_global_flags_valid(gfp)) {
375 /* default: lame chooses based on compression ratio and input channels */
376 if (mpg_mode < 0 || MAX_INDICATOR <= mpg_mode)
377 return -1; /* Unknown MPEG mode! */
385 lame_get_mode(const lame_global_flags * gfp)
387 if (is_lame_global_flags_valid(gfp)) {
388 assert(gfp->mode < MAX_INDICATOR);
395 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
397 mode_automs. Use a M/S mode with a switching threshold based on
401 int CDECL lame_set_mode_automs(lame_global_flags *, int);
402 int CDECL lame_get_mode_automs(const lame_global_flags *);
406 /* Us a M/S mode with a switching threshold based on compression ratio */
409 lame_set_mode_automs(lame_global_flags * gfp, int mode_automs)
411 if (is_lame_global_flags_valid(gfp)) {
412 /* default = 0 (disabled) */
414 /* enforce disable/enable meaning, if we need more than two values
415 we need to switch to an enum to have an apropriate representation
416 of the possible meanings of the value */
417 if (0 > mode_automs || 1 < mode_automs)
419 lame_set_mode(gfp, JOINT_STEREO);
426 lame_get_mode_automs(const lame_global_flags * gfp)
434 * Force M/S for all frames. For testing only.
438 lame_set_force_ms(lame_global_flags * gfp, int force_ms)
440 if (is_lame_global_flags_valid(gfp)) {
441 /* default = 0 (disabled) */
443 /* enforce disable/enable meaning, if we need more than two values
444 we need to switch to an enum to have an apropriate representation
445 of the possible meanings of the value */
446 if (0 > force_ms || 1 < force_ms)
448 gfp->force_ms = force_ms;
455 lame_get_force_ms(const lame_global_flags * gfp)
457 if (is_lame_global_flags_valid(gfp)) {
458 assert(0 <= gfp->force_ms && 1 >= gfp->force_ms);
459 return gfp->force_ms;
465 /* Use free_format. */
467 lame_set_free_format(lame_global_flags * gfp, int free_format)
469 if (is_lame_global_flags_valid(gfp)) {
470 /* default = 0 (disabled) */
472 /* enforce disable/enable meaning, if we need more than two values
473 we need to switch to an enum to have an apropriate representation
474 of the possible meanings of the value */
475 if (0 > free_format || 1 < free_format)
477 gfp->free_format = free_format;
484 lame_get_free_format(const lame_global_flags * gfp)
486 if (is_lame_global_flags_valid(gfp)) {
487 assert(0 <= gfp->free_format && 1 >= gfp->free_format);
488 return gfp->free_format;
495 /* Perform ReplayGain analysis */
497 lame_set_findReplayGain(lame_global_flags * gfp, int findReplayGain)
499 if (is_lame_global_flags_valid(gfp)) {
500 /* default = 0 (disabled) */
502 /* enforce disable/enable meaning, if we need more than two values
503 we need to switch to an enum to have an apropriate representation
504 of the possible meanings of the value */
505 if (0 > findReplayGain || 1 < findReplayGain)
507 gfp->findReplayGain = findReplayGain;
514 lame_get_findReplayGain(const lame_global_flags * gfp)
516 if (is_lame_global_flags_valid(gfp)) {
517 assert(0 <= gfp->findReplayGain && 1 >= gfp->findReplayGain);
518 return gfp->findReplayGain;
524 /* Decode on the fly. Find the peak sample. If ReplayGain analysis is
525 enabled then perform it on the decoded data. */
527 lame_set_decode_on_the_fly(lame_global_flags * gfp, int decode_on_the_fly)
529 if (is_lame_global_flags_valid(gfp)) {
530 #ifndef DECODE_ON_THE_FLY
533 /* default = 0 (disabled) */
535 /* enforce disable/enable meaning, if we need more than two values
536 we need to switch to an enum to have an apropriate representation
537 of the possible meanings of the value */
538 if (0 > decode_on_the_fly || 1 < decode_on_the_fly)
541 gfp->decode_on_the_fly = decode_on_the_fly;
550 lame_get_decode_on_the_fly(const lame_global_flags * gfp)
552 if (is_lame_global_flags_valid(gfp)) {
553 assert(0 <= gfp->decode_on_the_fly && 1 >= gfp->decode_on_the_fly);
554 return gfp->decode_on_the_fly;
559 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
560 /* DEPRECATED: now does the same as lame_set_findReplayGain()
561 default = 0 (disabled) */
562 int CDECL lame_set_ReplayGain_input(lame_global_flags *, int);
563 int CDECL lame_get_ReplayGain_input(const lame_global_flags *);
565 /* DEPRECATED: now does the same as
566 lame_set_decode_on_the_fly() && lame_set_findReplayGain()
567 default = 0 (disabled) */
568 int CDECL lame_set_ReplayGain_decode(lame_global_flags *, int);
569 int CDECL lame_get_ReplayGain_decode(const lame_global_flags *);
571 /* DEPRECATED: now does the same as lame_set_decode_on_the_fly()
572 default = 0 (disabled) */
573 int CDECL lame_set_findPeakSample(lame_global_flags *, int);
574 int CDECL lame_get_findPeakSample(const lame_global_flags *);
578 /* DEPRECATED. same as lame_set_decode_on_the_fly() */
580 lame_set_findPeakSample(lame_global_flags * gfp, int arg)
582 return lame_set_decode_on_the_fly(gfp, arg);
586 lame_get_findPeakSample(const lame_global_flags * gfp)
588 return lame_get_decode_on_the_fly(gfp);
591 /* DEPRECATED. same as lame_set_findReplayGain() */
593 lame_set_ReplayGain_input(lame_global_flags * gfp, int arg)
595 return lame_set_findReplayGain(gfp, arg);
599 lame_get_ReplayGain_input(const lame_global_flags * gfp)
601 return lame_get_findReplayGain(gfp);
604 /* DEPRECATED. same as lame_set_decode_on_the_fly() &&
605 lame_set_findReplayGain() */
607 lame_set_ReplayGain_decode(lame_global_flags * gfp, int arg)
609 if (lame_set_decode_on_the_fly(gfp, arg) < 0 || lame_set_findReplayGain(gfp, arg) < 0)
616 lame_get_ReplayGain_decode(const lame_global_flags * gfp)
618 if (lame_get_decode_on_the_fly(gfp) > 0 && lame_get_findReplayGain(gfp) > 0)
625 /* set and get some gapless encoding flags */
628 lame_set_nogap_total(lame_global_flags * gfp, int the_nogap_total)
630 if (is_lame_global_flags_valid(gfp)) {
631 gfp->nogap_total = the_nogap_total;
638 lame_get_nogap_total(const lame_global_flags * gfp)
640 if (is_lame_global_flags_valid(gfp)) {
641 return gfp->nogap_total;
647 lame_set_nogap_currentindex(lame_global_flags * gfp, int the_nogap_index)
649 if (is_lame_global_flags_valid(gfp)) {
650 gfp->nogap_current = the_nogap_index;
657 lame_get_nogap_currentindex(const lame_global_flags * gfp)
659 if (is_lame_global_flags_valid(gfp)) {
660 return gfp->nogap_current;
666 /* message handlers */
668 lame_set_errorf(lame_global_flags * gfp, void (*func) (const char *, va_list))
670 if (is_lame_global_flags_valid(gfp)) {
671 gfp->report.errorf = func;
678 lame_set_debugf(lame_global_flags * gfp, void (*func) (const char *, va_list))
680 if (is_lame_global_flags_valid(gfp)) {
681 gfp->report.debugf = func;
688 lame_set_msgf(lame_global_flags * gfp, void (*func) (const char *, va_list))
690 if (is_lame_global_flags_valid(gfp)) {
691 gfp->report.msgf = func;
701 * - compression ratio.
703 * Default is compression ratio of 11.
706 lame_set_brate(lame_global_flags * gfp, int brate)
708 if (is_lame_global_flags_valid(gfp)) {
711 gfp->disable_reservoir = 1;
719 lame_get_brate(const lame_global_flags * gfp)
721 if (is_lame_global_flags_valid(gfp)) {
728 lame_set_compression_ratio(lame_global_flags * gfp, float compression_ratio)
730 if (is_lame_global_flags_valid(gfp)) {
731 gfp->compression_ratio = compression_ratio;
738 lame_get_compression_ratio(const lame_global_flags * gfp)
740 if (is_lame_global_flags_valid(gfp)) {
741 return gfp->compression_ratio;
753 /* Mark as copyright protected. */
755 lame_set_copyright(lame_global_flags * gfp, int copyright)
757 if (is_lame_global_flags_valid(gfp)) {
758 /* default = 0 (disabled) */
760 /* enforce disable/enable meaning, if we need more than two values
761 we need to switch to an enum to have an apropriate representation
762 of the possible meanings of the value */
763 if (0 > copyright || 1 < copyright)
765 gfp->copyright = copyright;
772 lame_get_copyright(const lame_global_flags * gfp)
774 if (is_lame_global_flags_valid(gfp)) {
775 assert(0 <= gfp->copyright && 1 >= gfp->copyright);
776 return gfp->copyright;
782 /* Mark as original. */
784 lame_set_original(lame_global_flags * gfp, int original)
786 if (is_lame_global_flags_valid(gfp)) {
787 /* default = 1 (enabled) */
789 /* enforce disable/enable meaning, if we need more than two values
790 we need to switch to an enum to have an apropriate representation
791 of the possible meanings of the value */
792 if (0 > original || 1 < original)
794 gfp->original = original;
801 lame_get_original(const lame_global_flags * gfp)
803 if (is_lame_global_flags_valid(gfp)) {
804 assert(0 <= gfp->original && 1 >= gfp->original);
805 return gfp->original;
813 * Use 2 bytes from each frame for CRC checksum.
816 lame_set_error_protection(lame_global_flags * gfp, int error_protection)
818 if (is_lame_global_flags_valid(gfp)) {
819 /* default = 0 (disabled) */
821 /* enforce disable/enable meaning, if we need more than two values
822 we need to switch to an enum to have an apropriate representation
823 of the possible meanings of the value */
824 if (0 > error_protection || 1 < error_protection)
826 gfp->error_protection = error_protection;
833 lame_get_error_protection(const lame_global_flags * gfp)
835 if (is_lame_global_flags_valid(gfp)) {
836 assert(0 <= gfp->error_protection && 1 >= gfp->error_protection);
837 return gfp->error_protection;
843 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
844 /* padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default) */
845 int CDECL lame_set_padding_type(lame_global_flags *, Padding_type);
846 Padding_type CDECL lame_get_padding_type(const lame_global_flags *);
852 * PAD_NO = pad no frames
853 * PAD_ALL = pad all frames
854 * PAD_ADJUST = adjust padding
857 lame_set_padding_type(lame_global_flags * gfp, Padding_type padding_type)
865 lame_get_padding_type(const lame_global_flags * gfp)
872 /* MP3 'private extension' bit. Meaningless. */
874 lame_set_extension(lame_global_flags * gfp, int extension)
876 if (is_lame_global_flags_valid(gfp)) {
877 /* default = 0 (disabled) */
878 /* enforce disable/enable meaning, if we need more than two values
879 we need to switch to an enum to have an apropriate representation
880 of the possible meanings of the value */
881 if (0 > extension || 1 < extension)
883 gfp->extension = extension;
890 lame_get_extension(const lame_global_flags * gfp)
892 if (is_lame_global_flags_valid(gfp)) {
893 assert(0 <= gfp->extension && 1 >= gfp->extension);
894 return gfp->extension;
900 /* Enforce strict ISO compliance. */
902 lame_set_strict_ISO(lame_global_flags * gfp, int val)
904 if (is_lame_global_flags_valid(gfp)) {
905 /* default = 0 (disabled) */
906 /* enforce disable/enable meaning, if we need more than two values
907 we need to switch to an enum to have an apropriate representation
908 of the possible meanings of the value */
909 if (val < MDB_DEFAULT || MDB_MAXIMUM < val)
911 gfp->strict_ISO = val;
918 lame_get_strict_ISO(const lame_global_flags * gfp)
920 if (is_lame_global_flags_valid(gfp)) {
921 return gfp->strict_ISO;
929 /********************************************************************
930 * quantization/noise shaping
931 ***********************************************************************/
933 /* Disable the bit reservoir. For testing only. */
935 lame_set_disable_reservoir(lame_global_flags * gfp, int disable_reservoir)
937 if (is_lame_global_flags_valid(gfp)) {
938 /* default = 0 (disabled) */
940 /* enforce disable/enable meaning, if we need more than two values
941 we need to switch to an enum to have an apropriate representation
942 of the possible meanings of the value */
943 if (0 > disable_reservoir || 1 < disable_reservoir)
945 gfp->disable_reservoir = disable_reservoir;
952 lame_get_disable_reservoir(const lame_global_flags * gfp)
954 if (is_lame_global_flags_valid(gfp)) {
955 assert(0 <= gfp->disable_reservoir && 1 >= gfp->disable_reservoir);
956 return gfp->disable_reservoir;
965 lame_set_experimentalX(lame_global_flags * gfp, int experimentalX)
967 if (is_lame_global_flags_valid(gfp)) {
968 lame_set_quant_comp(gfp, experimentalX);
969 lame_set_quant_comp_short(gfp, experimentalX);
976 lame_get_experimentalX(const lame_global_flags * gfp)
978 return lame_get_quant_comp(gfp);
982 /* Select a different "best quantization" function. default = 0 */
984 lame_set_quant_comp(lame_global_flags * gfp, int quant_type)
986 if (is_lame_global_flags_valid(gfp)) {
987 gfp->quant_comp = quant_type;
994 lame_get_quant_comp(const lame_global_flags * gfp)
996 if (is_lame_global_flags_valid(gfp)) {
997 return gfp->quant_comp;
1003 /* Select a different "best quantization" function. default = 0 */
1005 lame_set_quant_comp_short(lame_global_flags * gfp, int quant_type)
1007 if (is_lame_global_flags_valid(gfp)) {
1008 gfp->quant_comp_short = quant_type;
1015 lame_get_quant_comp_short(const lame_global_flags * gfp)
1017 if (is_lame_global_flags_valid(gfp)) {
1018 return gfp->quant_comp_short;
1024 /* Another experimental option. For testing only. */
1026 lame_set_experimentalY(lame_global_flags * gfp, int experimentalY)
1028 if (is_lame_global_flags_valid(gfp)) {
1029 gfp->experimentalY = experimentalY;
1036 lame_get_experimentalY(const lame_global_flags * gfp)
1038 if (is_lame_global_flags_valid(gfp)) {
1039 return gfp->experimentalY;
1046 lame_set_experimentalZ(lame_global_flags * gfp, int experimentalZ)
1048 if (is_lame_global_flags_valid(gfp)) {
1049 gfp->experimentalZ = experimentalZ;
1056 lame_get_experimentalZ(const lame_global_flags * gfp)
1058 if (is_lame_global_flags_valid(gfp)) {
1059 return gfp->experimentalZ;
1065 /* Naoki's psycho acoustic model. */
1067 lame_set_exp_nspsytune(lame_global_flags * gfp, int exp_nspsytune)
1069 if (is_lame_global_flags_valid(gfp)) {
1070 /* default = 0 (disabled) */
1071 gfp->exp_nspsytune = exp_nspsytune;
1078 lame_get_exp_nspsytune(const lame_global_flags * gfp)
1080 if (is_lame_global_flags_valid(gfp)) {
1081 return gfp->exp_nspsytune;
1089 /********************************************************************
1091 ***********************************************************************/
1093 /* Types of VBR. default = vbr_off = CBR */
1095 lame_set_VBR(lame_global_flags * gfp, vbr_mode VBR)
1097 if (is_lame_global_flags_valid(gfp)) {
1099 if (0 > vbr_q || vbr_max_indicator <= vbr_q)
1100 return -1; /* Unknown VBR mode! */
1108 lame_get_VBR(const lame_global_flags * gfp)
1110 if (is_lame_global_flags_valid(gfp)) {
1111 assert(gfp->VBR < vbr_max_indicator);
1119 * VBR quality level.
1124 lame_set_VBR_q(lame_global_flags * gfp, int VBR_q)
1126 if (is_lame_global_flags_valid(gfp)) {
1130 ret = -1; /* Unknown VBR quality level! */
1138 gfp->VBR_q_frac = 0;
1145 lame_get_VBR_q(const lame_global_flags * gfp)
1147 if (is_lame_global_flags_valid(gfp)) {
1148 assert(0 <= gfp->VBR_q && 10 > gfp->VBR_q);
1155 lame_set_VBR_quality(lame_global_flags * gfp, float VBR_q)
1157 if (is_lame_global_flags_valid(gfp)) {
1161 ret = -1; /* Unknown VBR quality level! */
1164 if (9.999 < VBR_q) {
1169 gfp->VBR_q = (int) VBR_q;
1170 gfp->VBR_q_frac = VBR_q - gfp->VBR_q;
1178 lame_get_VBR_quality(const lame_global_flags * gfp)
1180 if (is_lame_global_flags_valid(gfp)) {
1181 return gfp->VBR_q + gfp->VBR_q_frac;
1187 /* Ignored except for VBR = vbr_abr (ABR mode) */
1189 lame_set_VBR_mean_bitrate_kbps(lame_global_flags * gfp, int VBR_mean_bitrate_kbps)
1191 if (is_lame_global_flags_valid(gfp)) {
1192 gfp->VBR_mean_bitrate_kbps = VBR_mean_bitrate_kbps;
1199 lame_get_VBR_mean_bitrate_kbps(const lame_global_flags * gfp)
1201 if (is_lame_global_flags_valid(gfp)) {
1202 return gfp->VBR_mean_bitrate_kbps;
1208 lame_set_VBR_min_bitrate_kbps(lame_global_flags * gfp, int VBR_min_bitrate_kbps)
1210 if (is_lame_global_flags_valid(gfp)) {
1211 gfp->VBR_min_bitrate_kbps = VBR_min_bitrate_kbps;
1218 lame_get_VBR_min_bitrate_kbps(const lame_global_flags * gfp)
1220 if (is_lame_global_flags_valid(gfp)) {
1221 return gfp->VBR_min_bitrate_kbps;
1227 lame_set_VBR_max_bitrate_kbps(lame_global_flags * gfp, int VBR_max_bitrate_kbps)
1229 if (is_lame_global_flags_valid(gfp)) {
1230 gfp->VBR_max_bitrate_kbps = VBR_max_bitrate_kbps;
1237 lame_get_VBR_max_bitrate_kbps(const lame_global_flags * gfp)
1239 if (is_lame_global_flags_valid(gfp)) {
1240 return gfp->VBR_max_bitrate_kbps;
1247 * Strictly enforce VBR_min_bitrate.
1248 * Normally it will be violated for analog silence.
1251 lame_set_VBR_hard_min(lame_global_flags * gfp, int VBR_hard_min)
1253 if (is_lame_global_flags_valid(gfp)) {
1254 /* default = 0 (disabled) */
1256 /* enforce disable/enable meaning, if we need more than two values
1257 we need to switch to an enum to have an apropriate representation
1258 of the possible meanings of the value */
1259 if (0 > VBR_hard_min || 1 < VBR_hard_min)
1262 gfp->VBR_hard_min = VBR_hard_min;
1270 lame_get_VBR_hard_min(const lame_global_flags * gfp)
1272 if (is_lame_global_flags_valid(gfp)) {
1273 assert(0 <= gfp->VBR_hard_min && 1 >= gfp->VBR_hard_min);
1274 return gfp->VBR_hard_min;
1280 /********************************************************************
1282 ***********************************************************************/
1285 * Freqency in Hz to apply lowpass.
1286 * 0 = default = lame chooses
1290 lame_set_lowpassfreq(lame_global_flags * gfp, int lowpassfreq)
1292 if (is_lame_global_flags_valid(gfp)) {
1293 gfp->lowpassfreq = lowpassfreq;
1300 lame_get_lowpassfreq(const lame_global_flags * gfp)
1302 if (is_lame_global_flags_valid(gfp)) {
1303 return gfp->lowpassfreq;
1310 * Width of transition band (in Hz).
1311 * default = one polyphase filter band
1314 lame_set_lowpasswidth(lame_global_flags * gfp, int lowpasswidth)
1316 if (is_lame_global_flags_valid(gfp)) {
1317 gfp->lowpasswidth = lowpasswidth;
1324 lame_get_lowpasswidth(const lame_global_flags * gfp)
1326 if (is_lame_global_flags_valid(gfp)) {
1327 return gfp->lowpasswidth;
1334 * Frequency in Hz to apply highpass.
1335 * 0 = default = lame chooses
1339 lame_set_highpassfreq(lame_global_flags * gfp, int highpassfreq)
1341 if (is_lame_global_flags_valid(gfp)) {
1342 gfp->highpassfreq = highpassfreq;
1349 lame_get_highpassfreq(const lame_global_flags * gfp)
1351 if (is_lame_global_flags_valid(gfp)) {
1352 return gfp->highpassfreq;
1359 * Width of transition band (in Hz).
1360 * default = one polyphase filter band
1363 lame_set_highpasswidth(lame_global_flags * gfp, int highpasswidth)
1365 if (is_lame_global_flags_valid(gfp)) {
1366 gfp->highpasswidth = highpasswidth;
1373 lame_get_highpasswidth(const lame_global_flags * gfp)
1375 if (is_lame_global_flags_valid(gfp)) {
1376 return gfp->highpasswidth;
1385 * psycho acoustics and other arguments which you should not change
1386 * unless you know what you are doing
1390 /* Adjust masking values. */
1392 lame_set_maskingadjust(lame_global_flags * gfp, float adjust)
1394 if (is_lame_global_flags_valid(gfp)) {
1395 gfp->maskingadjust = adjust;
1402 lame_get_maskingadjust(const lame_global_flags * gfp)
1404 if (is_lame_global_flags_valid(gfp)) {
1405 return gfp->maskingadjust;
1411 lame_set_maskingadjust_short(lame_global_flags * gfp, float adjust)
1413 if (is_lame_global_flags_valid(gfp)) {
1414 gfp->maskingadjust_short = adjust;
1421 lame_get_maskingadjust_short(const lame_global_flags * gfp)
1423 if (is_lame_global_flags_valid(gfp)) {
1424 return gfp->maskingadjust_short;
1429 /* Only use ATH for masking. */
1431 lame_set_ATHonly(lame_global_flags * gfp, int ATHonly)
1433 if (is_lame_global_flags_valid(gfp)) {
1434 gfp->ATHonly = ATHonly;
1441 lame_get_ATHonly(const lame_global_flags * gfp)
1443 if (is_lame_global_flags_valid(gfp)) {
1444 return gfp->ATHonly;
1450 /* Only use ATH for short blocks. */
1452 lame_set_ATHshort(lame_global_flags * gfp, int ATHshort)
1454 if (is_lame_global_flags_valid(gfp)) {
1455 gfp->ATHshort = ATHshort;
1462 lame_get_ATHshort(const lame_global_flags * gfp)
1464 if (is_lame_global_flags_valid(gfp)) {
1465 return gfp->ATHshort;
1473 lame_set_noATH(lame_global_flags * gfp, int noATH)
1475 if (is_lame_global_flags_valid(gfp)) {
1483 lame_get_noATH(const lame_global_flags * gfp)
1485 if (is_lame_global_flags_valid(gfp)) {
1492 /* Select ATH formula. */
1494 lame_set_ATHtype(lame_global_flags * gfp, int ATHtype)
1496 if (is_lame_global_flags_valid(gfp)) {
1497 /* XXX: ATHtype should be converted to an enum. */
1498 gfp->ATHtype = ATHtype;
1505 lame_get_ATHtype(const lame_global_flags * gfp)
1507 if (is_lame_global_flags_valid(gfp)) {
1508 return gfp->ATHtype;
1514 /* Select ATH formula 4 shape. */
1516 lame_set_ATHcurve(lame_global_flags * gfp, float ATHcurve)
1518 if (is_lame_global_flags_valid(gfp)) {
1519 gfp->ATHcurve = ATHcurve;
1526 lame_get_ATHcurve(const lame_global_flags * gfp)
1528 if (is_lame_global_flags_valid(gfp)) {
1529 return gfp->ATHcurve;
1535 /* Lower ATH by this many db. */
1537 lame_set_ATHlower(lame_global_flags * gfp, float ATHlower)
1539 if (is_lame_global_flags_valid(gfp)) {
1540 gfp->ATH_lower_db = ATHlower;
1547 lame_get_ATHlower(const lame_global_flags * gfp)
1549 if (is_lame_global_flags_valid(gfp)) {
1550 return gfp->ATH_lower_db;
1556 /* Select ATH adaptive adjustment scheme. */
1558 lame_set_athaa_type(lame_global_flags * gfp, int athaa_type)
1560 if (is_lame_global_flags_valid(gfp)) {
1561 gfp->athaa_type = athaa_type;
1568 lame_get_athaa_type(const lame_global_flags * gfp)
1570 if (is_lame_global_flags_valid(gfp)) {
1571 return gfp->athaa_type;
1577 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
1578 int CDECL lame_set_athaa_loudapprox(lame_global_flags * gfp, int athaa_loudapprox);
1579 int CDECL lame_get_athaa_loudapprox(const lame_global_flags * gfp);
1583 /* Select the loudness approximation used by the ATH adaptive auto-leveling. */
1585 lame_set_athaa_loudapprox(lame_global_flags * gfp, int athaa_loudapprox)
1588 (void) athaa_loudapprox;
1593 lame_get_athaa_loudapprox(const lame_global_flags * gfp)
1596 /* obsolete, the type known under number 2 is the only survival */
1601 /* Adjust (in dB) the point below which adaptive ATH level adjustment occurs. */
1603 lame_set_athaa_sensitivity(lame_global_flags * gfp, float athaa_sensitivity)
1605 if (is_lame_global_flags_valid(gfp)) {
1606 gfp->athaa_sensitivity = athaa_sensitivity;
1613 lame_get_athaa_sensitivity(const lame_global_flags * gfp)
1615 if (is_lame_global_flags_valid(gfp)) {
1616 return gfp->athaa_sensitivity;
1622 /* Predictability limit (ISO tonality formula) */
1623 int lame_set_cwlimit(lame_global_flags * gfp, int cwlimit);
1624 int lame_get_cwlimit(const lame_global_flags * gfp);
1627 lame_set_cwlimit(lame_global_flags * gfp, int cwlimit)
1635 lame_get_cwlimit(const lame_global_flags * gfp)
1644 * Allow blocktypes to differ between channels.
1646 * 0 for jstereo => block types coupled
1647 * 1 for stereo => block types may differ
1650 lame_set_allow_diff_short(lame_global_flags * gfp, int allow_diff_short)
1652 if (is_lame_global_flags_valid(gfp)) {
1653 gfp->short_blocks = allow_diff_short ? short_block_allowed : short_block_coupled;
1660 lame_get_allow_diff_short(const lame_global_flags * gfp)
1662 if (is_lame_global_flags_valid(gfp)) {
1663 if (gfp->short_blocks == short_block_allowed)
1664 return 1; /* short blocks allowed to differ */
1666 return 0; /* not set, dispensed, forced or coupled */
1672 /* Use temporal masking effect */
1674 lame_set_useTemporal(lame_global_flags * gfp, int useTemporal)
1676 if (is_lame_global_flags_valid(gfp)) {
1677 /* default = 1 (enabled) */
1679 /* enforce disable/enable meaning, if we need more than two values
1680 we need to switch to an enum to have an apropriate representation
1681 of the possible meanings of the value */
1682 if (0 <= useTemporal && useTemporal <= 1) {
1683 gfp->useTemporal = useTemporal;
1691 lame_get_useTemporal(const lame_global_flags * gfp)
1693 if (is_lame_global_flags_valid(gfp)) {
1694 assert(0 <= gfp->useTemporal && 1 >= gfp->useTemporal);
1695 return gfp->useTemporal;
1701 /* Use inter-channel masking effect */
1703 lame_set_interChRatio(lame_global_flags * gfp, float ratio)
1705 if (is_lame_global_flags_valid(gfp)) {
1706 /* default = 0.0 (no inter-channel maskin) */
1707 if (0 <= ratio && ratio <= 1.0) {
1708 gfp->interChRatio = ratio;
1716 lame_get_interChRatio(const lame_global_flags * gfp)
1718 if (is_lame_global_flags_valid(gfp)) {
1719 assert((0 <= gfp->interChRatio && gfp->interChRatio <= 1.0) || EQ(gfp->interChRatio, -1));
1720 return gfp->interChRatio;
1726 /* Use pseudo substep shaping method */
1728 lame_set_substep(lame_global_flags * gfp, int method)
1730 if (is_lame_global_flags_valid(gfp)) {
1731 /* default = 0.0 (no substep noise shaping) */
1732 if (0 <= method && method <= 7) {
1733 gfp->substep_shaping = method;
1741 lame_get_substep(const lame_global_flags * gfp)
1743 if (is_lame_global_flags_valid(gfp)) {
1744 assert(0 <= gfp->substep_shaping && gfp->substep_shaping <= 7);
1745 return gfp->substep_shaping;
1750 /* scalefactors scale */
1752 lame_set_sfscale(lame_global_flags * gfp, int val)
1754 if (is_lame_global_flags_valid(gfp)) {
1755 gfp->noise_shaping = (val != 0) ? 2 : 1;
1762 lame_get_sfscale(const lame_global_flags * gfp)
1764 if (is_lame_global_flags_valid(gfp)) {
1765 return (gfp->noise_shaping == 2) ? 1 : 0;
1772 lame_set_subblock_gain(lame_global_flags * gfp, int sbgain)
1774 if (is_lame_global_flags_valid(gfp)) {
1775 gfp->subblock_gain = sbgain;
1782 lame_get_subblock_gain(const lame_global_flags * gfp)
1784 if (is_lame_global_flags_valid(gfp)) {
1785 return gfp->subblock_gain;
1791 /* Disable short blocks. */
1793 lame_set_no_short_blocks(lame_global_flags * gfp, int no_short_blocks)
1795 if (is_lame_global_flags_valid(gfp)) {
1796 /* enforce disable/enable meaning, if we need more than two values
1797 we need to switch to an enum to have an apropriate representation
1798 of the possible meanings of the value */
1799 if (0 <= no_short_blocks && no_short_blocks <= 1) {
1800 gfp->short_blocks = no_short_blocks ? short_block_dispensed : short_block_allowed;
1808 lame_get_no_short_blocks(const lame_global_flags * gfp)
1810 if (is_lame_global_flags_valid(gfp)) {
1811 switch (gfp->short_blocks) {
1813 case short_block_not_set:
1815 case short_block_dispensed:
1817 case short_block_allowed:
1818 case short_block_coupled:
1819 case short_block_forced:
1827 /* Force short blocks. */
1829 lame_set_force_short_blocks(lame_global_flags * gfp, int short_blocks)
1831 if (is_lame_global_flags_valid(gfp)) {
1832 /* enforce disable/enable meaning, if we need more than two values
1833 we need to switch to an enum to have an apropriate representation
1834 of the possible meanings of the value */
1835 if (0 > short_blocks || 1 < short_blocks)
1838 if (short_blocks == 1)
1839 gfp->short_blocks = short_block_forced;
1840 else if (gfp->short_blocks == short_block_forced)
1841 gfp->short_blocks = short_block_allowed;
1849 lame_get_force_short_blocks(const lame_global_flags * gfp)
1851 if (is_lame_global_flags_valid(gfp)) {
1852 switch (gfp->short_blocks) {
1854 case short_block_not_set:
1856 case short_block_dispensed:
1857 case short_block_allowed:
1858 case short_block_coupled:
1860 case short_block_forced:
1868 lame_set_short_threshold_lrm(lame_global_flags * gfp, float lrm)
1870 if (is_lame_global_flags_valid(gfp)) {
1871 gfp->attackthre = lrm;
1878 lame_get_short_threshold_lrm(const lame_global_flags * gfp)
1880 if (is_lame_global_flags_valid(gfp)) {
1881 return gfp->attackthre;
1887 lame_set_short_threshold_s(lame_global_flags * gfp, float s)
1889 if (is_lame_global_flags_valid(gfp)) {
1890 gfp->attackthre_s = s;
1897 lame_get_short_threshold_s(const lame_global_flags * gfp)
1899 if (is_lame_global_flags_valid(gfp)) {
1900 return gfp->attackthre_s;
1906 lame_set_short_threshold(lame_global_flags * gfp, float lrm, float s)
1908 if (is_lame_global_flags_valid(gfp)) {
1909 lame_set_short_threshold_lrm(gfp, lrm);
1910 lame_set_short_threshold_s(gfp, s);
1918 * Input PCM is emphased PCM
1919 * (for instance from one of the rarely emphased CDs).
1921 * It is STRONGLY not recommended to use this, because psycho does not
1922 * take it into account, and last but not least many decoders
1926 lame_set_emphasis(lame_global_flags * gfp, int emphasis)
1928 if (is_lame_global_flags_valid(gfp)) {
1929 /* XXX: emphasis should be converted to an enum */
1930 if (0 <= emphasis && emphasis < 4) {
1931 gfp->emphasis = emphasis;
1939 lame_get_emphasis(const lame_global_flags * gfp)
1941 if (is_lame_global_flags_valid(gfp)) {
1942 assert(0 <= gfp->emphasis && gfp->emphasis < 4);
1943 return gfp->emphasis;
1951 /***************************************************************/
1952 /* internal variables, cannot be set... */
1953 /* provided because they may be of use to calling application */
1954 /***************************************************************/
1962 lame_get_version(const lame_global_flags * gfp)
1964 if (is_lame_global_flags_valid(gfp)) {
1965 lame_internal_flags const *const gfc = gfp->internal_flags;
1966 if (is_lame_internal_flags_valid(gfc)) {
1967 return gfc->cfg.version;
1974 /* Encoder delay. */
1976 lame_get_encoder_delay(const lame_global_flags * gfp)
1978 if (is_lame_global_flags_valid(gfp)) {
1979 lame_internal_flags const *const gfc = gfp->internal_flags;
1980 if (is_lame_internal_flags_valid(gfc)) {
1981 return gfc->ov_enc.encoder_delay;
1987 /* padding added to the end of the input */
1989 lame_get_encoder_padding(const lame_global_flags * gfp)
1991 if (is_lame_global_flags_valid(gfp)) {
1992 lame_internal_flags const *const gfc = gfp->internal_flags;
1993 if (is_lame_internal_flags_valid(gfc)) {
1994 return gfc->ov_enc.encoder_padding;
2001 /* Size of MPEG frame. */
2003 lame_get_framesize(const lame_global_flags * gfp)
2005 if (is_lame_global_flags_valid(gfp)) {
2006 lame_internal_flags const *const gfc = gfp->internal_flags;
2007 if (is_lame_internal_flags_valid(gfc)) {
2008 SessionConfig_t const *const cfg = &gfc->cfg;
2009 return 576 * cfg->mode_gr;
2016 /* Number of frames encoded so far. */
2018 lame_get_frameNum(const lame_global_flags * gfp)
2020 if (is_lame_global_flags_valid(gfp)) {
2021 lame_internal_flags const *const gfc = gfp->internal_flags;
2022 if (is_lame_internal_flags_valid(gfc)) {
2023 return gfc->ov_enc.frame_number;
2030 lame_get_mf_samples_to_encode(const lame_global_flags * gfp)
2032 if (is_lame_global_flags_valid(gfp)) {
2033 lame_internal_flags const *const gfc = gfp->internal_flags;
2034 if (is_lame_internal_flags_valid(gfc)) {
2035 return gfc->sv_enc.mf_samples_to_encode;
2042 lame_get_size_mp3buffer(const lame_global_flags * gfp)
2044 if (is_lame_global_flags_valid(gfp)) {
2045 lame_internal_flags const *const gfc = gfp->internal_flags;
2046 if (is_lame_internal_flags_valid(gfc)) {
2048 compute_flushbits(gfc, &size);
2056 lame_get_RadioGain(const lame_global_flags * gfp)
2058 if (is_lame_global_flags_valid(gfp)) {
2059 lame_internal_flags const *const gfc = gfp->internal_flags;
2060 if (is_lame_internal_flags_valid(gfc)) {
2061 return gfc->ov_rpg.RadioGain;
2068 lame_get_AudiophileGain(const lame_global_flags * gfp)
2070 if (is_lame_global_flags_valid(gfp)) {
2071 lame_internal_flags const *const gfc = gfp->internal_flags;
2072 if (is_lame_internal_flags_valid(gfc)) {
2080 lame_get_PeakSample(const lame_global_flags * gfp)
2082 if (is_lame_global_flags_valid(gfp)) {
2083 lame_internal_flags const *const gfc = gfp->internal_flags;
2084 if (is_lame_internal_flags_valid(gfc)) {
2085 return (float) gfc->ov_rpg.PeakSample;
2092 lame_get_noclipGainChange(const lame_global_flags * gfp)
2094 if (is_lame_global_flags_valid(gfp)) {
2095 lame_internal_flags const *const gfc = gfp->internal_flags;
2096 if (is_lame_internal_flags_valid(gfc)) {
2097 return gfc->ov_rpg.noclipGainChange;
2104 lame_get_noclipScale(const lame_global_flags * gfp)
2106 if (is_lame_global_flags_valid(gfp)) {
2107 lame_internal_flags const *const gfc = gfp->internal_flags;
2108 if (is_lame_internal_flags_valid(gfc)) {
2109 return gfc->ov_rpg.noclipScale;
2117 * LAME's estimate of the total number of frames to be encoded.
2118 * Only valid if calling program set num_samples.
2121 lame_get_totalframes(const lame_global_flags * gfp)
2123 if (is_lame_global_flags_valid(gfp)) {
2124 lame_internal_flags const *const gfc = gfp->internal_flags;
2125 if (is_lame_internal_flags_valid(gfc)) {
2126 SessionConfig_t const *const cfg = &gfc->cfg;
2127 unsigned long const pcm_samples_per_frame = 576 * cfg->mode_gr;
2128 unsigned long pcm_samples_to_encode = gfp->num_samples;
2129 unsigned long end_padding = 0;
2131 /* estimate based on user set num_samples: */
2132 if (pcm_samples_to_encode == (0ul-1ul)) {
2135 if (gfp->samplerate_in != gfp->samplerate_out && gfp->samplerate_in > 0) {
2136 double const q = (double)gfp->samplerate_out / gfp->samplerate_in;
2137 pcm_samples_to_encode *= q;
2139 pcm_samples_to_encode += 576;
2140 end_padding = pcm_samples_per_frame - (pcm_samples_to_encode % pcm_samples_per_frame);
2141 if (end_padding < 576) {
2142 end_padding += pcm_samples_per_frame;
2144 pcm_samples_to_encode += end_padding;
2145 /* check to see if we underestimated totalframes */
2146 /* if (totalframes < gfp->frameNum) */
2147 /* totalframes = gfp->frameNum; */
2148 return pcm_samples_to_encode / pcm_samples_per_frame;
2159 lame_set_preset(lame_global_flags * gfp, int preset)
2161 if (is_lame_global_flags_valid(gfp)) {
2162 gfp->preset = preset;
2163 return apply_preset(gfp, preset, 1);
2171 lame_set_asm_optimizations(lame_global_flags * gfp, int optim, int mode)
2173 if (is_lame_global_flags_valid(gfp)) {
2174 mode = (mode == 1 ? 1 : 0);
2177 gfp->asm_optimizations.mmx = mode;
2181 gfp->asm_optimizations.amd3dnow = mode;
2185 gfp->asm_optimizations.sse = mode;
2197 lame_set_write_id3tag_automatic(lame_global_flags * gfp, int v)
2199 if (is_lame_global_flags_valid(gfp)) {
2200 gfp->write_id3tag_automatic = v;
2206 lame_get_write_id3tag_automatic(lame_global_flags const *gfp)
2208 if (is_lame_global_flags_valid(gfp)) {
2209 return gfp->write_id3tag_automatic;
2217 UNDOCUMENTED, experimental settings. These routines are not prototyped
2218 in lame.h. You should not use them, they are experimental and may
2225 * just another daily changing developer switch
2227 void CDECL lame_set_tune(lame_global_flags *, float);
2230 lame_set_tune(lame_global_flags * gfp, float val)
2232 if (is_lame_global_flags_valid(gfp)) {
2233 gfp->tune_value_a = val;
2238 /* Custom msfix hack */
2240 lame_set_msfix(lame_global_flags * gfp, double msfix)
2242 if (is_lame_global_flags_valid(gfp)) {
2249 lame_get_msfix(const lame_global_flags * gfp)
2251 if (is_lame_global_flags_valid(gfp)) {
2257 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
2258 int CDECL lame_set_preset_expopts(lame_global_flags *, int);
2263 lame_set_preset_expopts(lame_global_flags * gfp, int preset_expopts)
2266 (void) preset_expopts;
2272 lame_set_preset_notune(lame_global_flags * gfp, int preset_notune)
2275 (void) preset_notune;