don't use int32_t types in bitio.h
[swftools.git] / lib / lame / set_get.c
blob36dda2db6f8b8a5936c6ba3255db878026f6c869
1 /* -*- mode: C; mode: fold -*- */
2 /*
3 * set/get functions for lame_global_flags
5 * Copyright (c) 2001 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.2 2006/02/09 16:56:23 kramm Exp $ */
25 #include <stdlib.h>
26 #include "config_static.h"
28 #include <assert.h>
29 #include "util.h"
30 #include "bitstream.h" /* because of compute_flushbits */
32 #ifdef WITH_DMALLOC
33 #include <dmalloc.h>
34 #endif
38 * input stream description
41 /* number of samples */
42 /* it's unlikely for this function to return an error */
43 int
44 lame_set_num_samples( lame_global_flags* gfp,
45 unsigned long num_samples)
47 /* default = 2^32-1 */
49 gfp->num_samples = num_samples;
51 return 0;
54 unsigned long
55 lame_get_num_samples( const lame_global_flags* gfp )
57 return gfp->num_samples;
61 /* input samplerate */
62 int
63 lame_set_in_samplerate( lame_global_flags* gfp,
64 int in_samplerate )
66 /* input sample rate in Hz, default = 44100 Hz */
67 gfp->in_samplerate = in_samplerate;
69 return 0;
72 int
73 lame_get_in_samplerate( const lame_global_flags* gfp )
75 return gfp->in_samplerate;
79 /* number of channels in input stream */
80 int
81 lame_set_num_channels( lame_global_flags* gfp,
82 int num_channels )
84 /* default = 2 */
86 if ( 2 < num_channels || 0 == num_channels )
87 return -1; /* we don't support more than 2 channels */
89 gfp->num_channels = num_channels;
91 return 0;
94 int
95 lame_get_num_channels( const lame_global_flags* gfp )
97 return gfp->num_channels;
101 /* scale the input by this amount before encoding (not used for decoding) */
103 lame_set_scale( lame_global_flags* gfp,
104 float scale )
106 /* default = 0 */
107 gfp->scale = scale;
109 return 0;
112 float
113 lame_get_scale( const lame_global_flags* gfp )
115 return gfp->scale;
119 /* scale the channel 0 (left) input by this amount before
120 encoding (not used for decoding) */
122 lame_set_scale_left( lame_global_flags* gfp,
123 float scale )
125 /* default = 0 */
126 gfp->scale_left = scale;
128 return 0;
131 float
132 lame_get_scale_left( const lame_global_flags* gfp )
134 return gfp->scale_left;
138 /* scale the channel 1 (right) input by this amount before
139 encoding (not used for decoding) */
141 lame_set_scale_right( lame_global_flags* gfp,
142 float scale )
144 /* default = 0 */
145 gfp->scale_right = scale;
147 return 0;
150 float
151 lame_get_scale_right( const lame_global_flags* gfp )
153 return gfp->scale_right;
157 /* output sample rate in Hz */
159 lame_set_out_samplerate( lame_global_flags* gfp,
160 int out_samplerate )
163 * default = 0: LAME picks best value based on the amount
164 * of compression
165 * MPEG only allows:
166 * MPEG1 32, 44.1, 48khz
167 * MPEG2 16, 22.05, 24
168 * MPEG2.5 8, 11.025, 12
170 * (not used by decoding routines)
172 gfp->out_samplerate = out_samplerate;
174 return 0;
178 lame_get_out_samplerate( const lame_global_flags* gfp )
180 return gfp->out_samplerate;
187 * general control parameters
190 /* collect data for an MP3 frame analzyer */
192 lame_set_analysis( lame_global_flags* gfp,
193 int analysis )
195 /* default = 0 */
197 /* enforce disable/enable meaning, if we need more than two values
198 we need to switch to an enum to have an apropriate representation
199 of the possible meanings of the value */
200 if ( 0 > analysis || 1 < analysis )
201 return -1;
203 gfp->analysis = analysis;
205 return 0;
209 lame_get_analysis( const lame_global_flags* gfp )
211 assert( 0 <= gfp->analysis && 1 >= gfp->analysis );
213 return gfp->analysis;
217 /* write a Xing VBR header frame */
219 lame_set_bWriteVbrTag( lame_global_flags* gfp,
220 int bWriteVbrTag )
222 /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
224 /* enforce disable/enable meaning, if we need more than two values
225 we need to switch to an enum to have an apropriate representation
226 of the possible meanings of the value */
227 if ( 0 > bWriteVbrTag || 1 < bWriteVbrTag )
228 return -1;
230 gfp->bWriteVbrTag = bWriteVbrTag;
232 return 0;
236 lame_get_bWriteVbrTag( const lame_global_flags* gfp )
238 assert( 0 <= gfp->bWriteVbrTag && 1 >= gfp->bWriteVbrTag );
240 return gfp->bWriteVbrTag;
245 /* decode only, use lame/mpglib to convert mp3/ogg to wav */
247 lame_set_decode_only( lame_global_flags* gfp,
248 int decode_only )
250 /* default = 0 (disabled) */
252 /* enforce disable/enable meaning, if we need more than two values
253 we need to switch to an enum to have an apropriate representation
254 of the possible meanings of the value */
255 if ( 0 > decode_only || 1 < decode_only )
256 return -1;
258 gfp->decode_only = decode_only;
260 return 0;
264 lame_get_decode_only( const lame_global_flags* gfp )
266 assert( 0 <= gfp->decode_only && 1 >= gfp->decode_only );
268 return gfp->decode_only;
272 /* encode a Vorbis .ogg file */
274 lame_set_ogg( lame_global_flags* gfp,
275 int ogg )
277 /* default = 0 (disabled) */
279 /* enforce disable/enable meaning, if we need more than two values
280 we need to switch to an enum to have an apropriate representation
281 of the possible meanings of the value */
282 if ( 0 > ogg || 1 < ogg )
283 return -1;
285 gfp->ogg = ogg;
287 return 0;
291 lame_get_ogg( const lame_global_flags* gfp )
293 assert( 0 <= gfp->ogg && 1 >= gfp->ogg );
295 return gfp->ogg;
300 * Internal algorithm selection.
301 * True quality is determined by the bitrate but this variable will effect
302 * quality by selecting expensive or cheap algorithms.
303 * quality=0..9. 0=best (very slow). 9=worst.
304 * recommended: 2 near-best quality, not too slow
305 * 5 good quality, fast
306 * 7 ok quality, really fast
309 lame_set_quality( lame_global_flags* gfp,
310 int quality )
312 gfp->quality = quality;
314 return 0;
318 lame_get_quality( const lame_global_flags* gfp )
320 return gfp->quality;
324 /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
326 lame_set_mode( lame_global_flags* gfp,
327 MPEG_mode mode )
329 /* default: lame chooses based on compression ratio and input channels */
331 if( 0 > mode || MAX_INDICATOR <= mode )
332 return -1; /* Unknown MPEG mode! */
334 gfp->mode = mode;
336 return 0;
339 MPEG_mode
340 lame_get_mode( const lame_global_flags* gfp )
342 assert( 0 <= gfp->mode && MAX_INDICATOR > gfp->mode );
344 return gfp->mode;
348 /* Us a M/S mode with a switching threshold based on compression ratio */
350 lame_set_mode_automs( lame_global_flags* gfp,
351 int mode_automs )
353 /* default = 0 (disabled) */
355 /* enforce disable/enable meaning, if we need more than two values
356 we need to switch to an enum to have an apropriate representation
357 of the possible meanings of the value */
358 if ( 0 > mode_automs || 1 < mode_automs )
359 return -1;
361 gfp->mode_automs = mode_automs;
363 return 0;
367 lame_get_mode_automs( const lame_global_flags* gfp )
369 assert( 0 <= gfp->mode_automs && 1 >= gfp->mode_automs );
371 return gfp->mode_automs;
376 * Force M/S for all frames. For testing only.
377 * Requires mode = 1.
380 lame_set_force_ms( lame_global_flags* gfp,
381 int force_ms )
383 /* default = 0 (disabled) */
385 /* enforce disable/enable meaning, if we need more than two values
386 we need to switch to an enum to have an apropriate representation
387 of the possible meanings of the value */
388 if ( 0 > force_ms || 1 < force_ms )
389 return -1;
391 gfp->force_ms = force_ms;
393 return 0;
397 lame_get_force_ms( const lame_global_flags* gfp )
399 assert( 0 <= gfp->force_ms && 1 >= gfp->force_ms );
401 return gfp->force_ms;
405 /* Use free_format. */
407 lame_set_free_format( lame_global_flags* gfp,
408 int free_format )
410 /* default = 0 (disabled) */
412 /* enforce disable/enable meaning, if we need more than two values
413 we need to switch to an enum to have an apropriate representation
414 of the possible meanings of the value */
415 if ( 0 > free_format || 1 < free_format )
416 return -1;
418 gfp->free_format = free_format;
420 return 0;
424 lame_get_free_format( const lame_global_flags* gfp )
426 assert( 0 <= gfp->free_format && 1 >= gfp->free_format );
428 return gfp->free_format;
432 /* message handlers */
434 lame_set_errorf( lame_global_flags* gfp,
435 void (*func)( const char*, va_list ) )
437 gfp->report.errorf = func;
439 return 0;
443 lame_set_debugf( lame_global_flags* gfp,
444 void (*func)( const char*, va_list ) )
446 gfp->report.debugf = func;
448 return 0;
452 lame_set_msgf( lame_global_flags* gfp,
453 void (*func)( const char *, va_list ) )
455 gfp->report.msgf = func;
457 return 0;
462 * Set one of
463 * - brate
464 * - compression ratio.
466 * Default is compression ratio of 11.
469 lame_set_brate( lame_global_flags* gfp,
470 int brate )
472 gfp->brate = brate;
474 return 0;
478 lame_get_brate( const lame_global_flags* gfp )
480 return gfp->brate;
484 lame_set_compression_ratio( lame_global_flags* gfp,
485 float compression_ratio )
487 gfp->compression_ratio = compression_ratio;
489 return 0;
492 float
493 lame_get_compression_ratio( const lame_global_flags* gfp )
495 return gfp->compression_ratio;
502 * frame parameters
505 /* Mark as copyright protected. */
507 lame_set_copyright( lame_global_flags* gfp,
508 int copyright )
510 /* default = 0 (disabled) */
512 /* enforce disable/enable meaning, if we need more than two values
513 we need to switch to an enum to have an apropriate representation
514 of the possible meanings of the value */
515 if ( 0 > copyright || 1 < copyright )
516 return -1;
518 gfp->copyright = copyright;
520 return 0;
524 lame_get_copyright( const lame_global_flags* gfp )
526 assert( 0 <= gfp->copyright && 1 >= gfp->copyright );
528 return gfp->copyright;
532 /* Mark as original. */
534 lame_set_original( lame_global_flags* gfp,
535 int original )
537 /* default = 1 (enabled) */
539 /* enforce disable/enable meaning, if we need more than two values
540 we need to switch to an enum to have an apropriate representation
541 of the possible meanings of the value */
542 if ( 0 > original || 1 < original )
543 return -1;
545 gfp->original = original;
547 return 0;
551 lame_get_original( const lame_global_flags* gfp )
553 assert( 0 <= gfp->original && 1 >= gfp->original );
555 return gfp->original;
560 * error_protection.
561 * Use 2 bytes from each frame for CRC checksum.
564 lame_set_error_protection( lame_global_flags* gfp,
565 int error_protection )
567 /* default = 0 (disabled) */
569 /* enforce disable/enable meaning, if we need more than two values
570 we need to switch to an enum to have an apropriate representation
571 of the possible meanings of the value */
572 if ( 0 > error_protection || 1 < error_protection )
573 return -1;
575 gfp->error_protection = error_protection;
577 return 0;
581 lame_get_error_protection( const lame_global_flags* gfp )
583 assert( 0 <= gfp->error_protection && 1 >= gfp->error_protection );
585 return gfp->error_protection;
590 * padding_type.
591 * PAD_NO = pad no frames
592 * PAD_ALL = pad all frames
593 * PAD_ADJUST = adjust padding
596 lame_set_padding_type( lame_global_flags* gfp,
597 Padding_type padding_type )
599 /* default = 2 */
601 if ( 0 > padding_type || PAD_MAX_INDICATOR < padding_type )
602 return -1; /* Unknown padding type */
604 gfp->padding_type = padding_type;
606 return 0;
609 Padding_type
610 lame_get_padding_type( const lame_global_flags* gfp )
612 assert( 0 <= gfp->padding_type && PAD_MAX_INDICATOR > gfp->padding_type );
614 return gfp->padding_type;
618 /* MP3 'private extension' bit. Meaningless. */
620 lame_set_extension( lame_global_flags* gfp,
621 int extension )
623 /* default = 0 (disabled) */
625 /* enforce disable/enable meaning, if we need more than two values
626 we need to switch to an enum to have an apropriate representation
627 of the possible meanings of the value */
628 if ( 0 > extension || 1 < extension )
629 return -1;
631 gfp->extension = extension;
633 return 0;
637 lame_get_extension( const lame_global_flags* gfp )
639 assert( 0 <= gfp->extension && 1 >= gfp->extension );
641 return gfp->extension;
645 /* Enforce strict ISO compliance. */
647 lame_set_strict_ISO( lame_global_flags* gfp,
648 int strict_ISO )
650 /* default = 0 (disabled) */
652 /* enforce disable/enable meaning, if we need more than two values
653 we need to switch to an enum to have an apropriate representation
654 of the possible meanings of the value */
655 if ( 0 > strict_ISO || 1 < strict_ISO )
656 return -1;
658 gfp->strict_ISO = strict_ISO;
660 return 0;
664 lame_get_strict_ISO( const lame_global_flags* gfp )
666 assert( 0 <= gfp->strict_ISO && 1 >= gfp->strict_ISO );
668 return gfp->strict_ISO;
674 /********************************************************************
675 * quantization/noise shaping
676 ***********************************************************************/
678 /* Disable the bit reservoir. For testing only. */
680 lame_set_disable_reservoir( lame_global_flags* gfp,
681 int disable_reservoir )
683 /* default = 0 (disabled) */
685 /* enforce disable/enable meaning, if we need more than two values
686 we need to switch to an enum to have an apropriate representation
687 of the possible meanings of the value */
688 if ( 0 > disable_reservoir || 1 < disable_reservoir )
689 return -1;
691 gfp->disable_reservoir = disable_reservoir;
693 return 0;
697 lame_get_disable_reservoir( const lame_global_flags* gfp )
699 assert( 0 <= gfp->disable_reservoir && 1 >= gfp->disable_reservoir );
701 return gfp->disable_reservoir;
707 /* Select a different "best quantization" function. default = 0 */
709 lame_set_experimentalX( lame_global_flags* gfp,
710 int experimentalX )
712 gfp->experimentalX = experimentalX;
714 return 0;
718 lame_get_experimentalX( const lame_global_flags* gfp )
720 return gfp->experimentalX;
724 /* Another experimental option. For testing only. */
726 lame_set_experimentalY( lame_global_flags* gfp,
727 int experimentalY )
729 gfp->experimentalY = experimentalY;
731 return 0;
735 lame_get_experimentalY( const lame_global_flags* gfp )
737 return gfp->experimentalY;
741 /* Another experimental option. For testing only. */
743 lame_set_experimentalZ( lame_global_flags* gfp,
744 int experimentalZ )
746 gfp->experimentalZ += experimentalZ;
748 return 0;
752 lame_get_experimentalZ( const lame_global_flags* gfp )
754 return gfp->experimentalZ;
758 /* Naoki's psycho acoustic model. */
760 lame_set_exp_nspsytune( lame_global_flags* gfp,
761 int exp_nspsytune )
763 /* default = 0 (disabled) */
765 gfp->exp_nspsytune = exp_nspsytune;
767 return 0;
771 lame_get_exp_nspsytune( const lame_global_flags* gfp )
773 return gfp->exp_nspsytune;
779 /********************************************************************
780 * VBR control
781 ***********************************************************************/
783 // Types of VBR. default = vbr_off = CBR
785 lame_set_VBR( lame_global_flags* gfp,
786 vbr_mode VBR )
788 if( 0 > VBR || vbr_max_indicator <= VBR )
789 return -1; /* Unknown VBR mode! */
791 gfp->VBR = VBR;
793 return 0;
796 vbr_mode
797 lame_get_VBR( const lame_global_flags* gfp )
799 assert( 0 <= gfp->VBR && vbr_max_indicator > gfp->VBR );
801 return gfp->VBR;
806 * VBR quality level.
807 * 0 = highest
808 * 9 = lowest
811 lame_set_VBR_q( lame_global_flags* gfp,
812 int VBR_q )
814 /* XXX: This should be an enum */
815 /* to whoever added this note: why should it be an enum?
816 do you want to call a specific setting by name?
817 say VBR quality level red? */
818 /* No, but VBR_Q_HIGHEST, VBR_Q_HIGH, ..., VBR_Q_MID, ...
819 VBR_Q_LOW, VBR_Q_LOWEST (or something like that )and a
820 VBR_Q_DEFAULT, which aliases the default setting of
821 e.g. VBR_Q_MID. */
824 if( 0 > VBR_q || 10 <= VBR_q )
825 return -1; /* Unknown VBR quality level! */
827 gfp->VBR_q = VBR_q;
829 return 0;
833 lame_get_VBR_q( const lame_global_flags* gfp )
835 assert( 0 <= gfp->VBR_q && 10 > gfp->VBR_q );
837 return gfp->VBR_q;
841 /* Ignored except for VBR = vbr_abr (ABR mode) */
843 lame_set_VBR_mean_bitrate_kbps( lame_global_flags* gfp,
844 int VBR_mean_bitrate_kbps )
846 gfp->VBR_mean_bitrate_kbps = VBR_mean_bitrate_kbps;
848 return 0;
852 lame_get_VBR_mean_bitrate_kbps( const lame_global_flags* gfp )
854 return gfp->VBR_mean_bitrate_kbps;
858 lame_set_VBR_min_bitrate_kbps( lame_global_flags* gfp,
859 int VBR_min_bitrate_kbps )
861 gfp->VBR_min_bitrate_kbps = VBR_min_bitrate_kbps;
863 return 0;
867 lame_get_VBR_min_bitrate_kbps( const lame_global_flags* gfp )
869 return gfp->VBR_min_bitrate_kbps;
873 lame_set_VBR_max_bitrate_kbps( lame_global_flags* gfp,
874 int VBR_max_bitrate_kbps )
876 gfp->VBR_max_bitrate_kbps = VBR_max_bitrate_kbps;
878 return 0;
882 lame_get_VBR_max_bitrate_kbps( const lame_global_flags* gfp )
884 return gfp->VBR_max_bitrate_kbps;
889 * Strictly enforce VBR_min_bitrate.
890 * Normally it will be violated for analog silence.
893 lame_set_VBR_hard_min( lame_global_flags* gfp,
894 int VBR_hard_min )
896 /* default = 0 (disabled) */
898 /* enforce disable/enable meaning, if we need more than two values
899 we need to switch to an enum to have an apropriate representation
900 of the possible meanings of the value */
901 if ( 0 > VBR_hard_min || 1 < VBR_hard_min )
902 return -1;
904 gfp->VBR_hard_min = VBR_hard_min;
906 return 0;
910 lame_get_VBR_hard_min( const lame_global_flags* gfp )
912 assert( 0 <= gfp->VBR_hard_min && 1 >= gfp->VBR_hard_min );
914 return gfp->VBR_hard_min;
918 /********************************************************************
919 * Filtering control
920 ***********************************************************************/
923 * Freqency in Hz to apply lowpass.
924 * 0 = default = lame chooses
925 * -1 = disabled
928 lame_set_lowpassfreq( lame_global_flags* gfp,
929 int lowpassfreq )
931 gfp->lowpassfreq = lowpassfreq;
933 return 0;
937 lame_get_lowpassfreq( const lame_global_flags* gfp )
939 return gfp->lowpassfreq;
944 * Width of transition band (in Hz).
945 * default = one polyphase filter band
948 lame_set_lowpasswidth( lame_global_flags* gfp,
949 int lowpasswidth )
951 gfp->lowpasswidth = lowpasswidth;
953 return 0;
957 lame_get_lowpasswidth( const lame_global_flags* gfp )
959 return gfp->lowpasswidth;
964 * Frequency in Hz to apply highpass.
965 * 0 = default = lame chooses
966 * -1 = disabled
969 lame_set_highpassfreq( lame_global_flags* gfp,
970 int highpassfreq )
972 gfp->highpassfreq = highpassfreq;
974 return 0;
978 lame_get_highpassfreq( const lame_global_flags* gfp )
980 return gfp->highpassfreq;
985 * Width of transition band (in Hz).
986 * default = one polyphase filter band
989 lame_set_highpasswidth( lame_global_flags* gfp,
990 int highpasswidth )
992 gfp->highpasswidth = highpasswidth;
994 return 0;
998 lame_get_highpasswidth( const lame_global_flags* gfp )
1000 return gfp->highpasswidth;
1007 * psycho acoustics and other arguments which you should not change
1008 * unless you know what you are doing
1011 /* Only use ATH for masking. */
1013 lame_set_ATHonly( lame_global_flags* gfp,
1014 int ATHonly )
1016 gfp->ATHonly = ATHonly;
1018 return 0;
1022 lame_get_ATHonly( const lame_global_flags* gfp )
1024 return gfp->ATHonly;
1028 /* Only use ATH for short blocks. */
1030 lame_set_ATHshort( lame_global_flags* gfp,
1031 int ATHshort )
1033 gfp->ATHshort = ATHshort;
1035 return 0;
1039 lame_get_ATHshort( const lame_global_flags* gfp )
1041 return gfp->ATHshort;
1045 /* Disable ATH. */
1047 lame_set_noATH( lame_global_flags* gfp,
1048 int noATH )
1050 gfp->noATH = noATH;
1052 return 0;
1056 lame_get_noATH( const lame_global_flags* gfp )
1058 return gfp->noATH;
1062 /* Select ATH formula. */
1064 lame_set_ATHtype( lame_global_flags* gfp,
1065 int ATHtype )
1067 /* XXX: ATHtype should be converted to an enum. */
1068 gfp->ATHtype = ATHtype;
1070 return 0;
1074 lame_get_ATHtype( const lame_global_flags* gfp )
1076 return gfp->ATHtype;
1080 /* Lower ATH by this many db. */
1082 lame_set_ATHlower( lame_global_flags* gfp,
1083 float ATHlower )
1085 gfp->ATHlower = ATHlower;
1086 return 0;
1089 float
1090 lame_get_ATHlower( const lame_global_flags* gfp )
1092 return gfp->ATHlower;
1096 /* Select ATH adaptive adjustment scheme. */
1098 lame_set_athaa_type( lame_global_flags* gfp,
1099 int athaa_type )
1101 gfp->athaa_type = athaa_type;
1103 return 0;
1107 lame_get_athaa_type( const lame_global_flags* gfp )
1109 return gfp->athaa_type;
1113 /* Select the loudness approximation used by the ATH adaptive auto-leveling. */
1115 lame_set_athaa_loudapprox( lame_global_flags* gfp,
1116 int athaa_loudapprox )
1118 gfp->athaa_loudapprox = athaa_loudapprox;
1120 return 0;
1124 lame_get_athaa_loudapprox( const lame_global_flags* gfp )
1126 return gfp->athaa_loudapprox;
1130 /* Adjust (in dB) the point below which adaptive ATH level adjustment occurs. */
1132 lame_set_athaa_sensitivity( lame_global_flags* gfp,
1133 float athaa_sensitivity )
1135 gfp->athaa_sensitivity = athaa_sensitivity;
1137 return 0;
1140 float
1141 lame_get_athaa_sensitivity( const lame_global_flags* gfp )
1143 return gfp->athaa_sensitivity;
1147 /* Predictability limit (ISO tonality formula) */
1149 lame_set_cwlimit( lame_global_flags* gfp,
1150 int cwlimit )
1152 gfp->cwlimit = cwlimit;
1154 return 0;
1158 lame_get_cwlimit( const lame_global_flags* gfp )
1160 return gfp->cwlimit;
1166 * Allow blocktypes to differ between channels.
1167 * default:
1168 * 0 for jstereo => block types coupled
1169 * 1 for stereo => block types may differ
1172 lame_set_allow_diff_short( lame_global_flags* gfp,
1173 int allow_diff_short )
1175 gfp->short_blocks =
1176 allow_diff_short ? short_block_allowed : short_block_coupled;
1178 return 0;
1182 lame_get_allow_diff_short( const lame_global_flags* gfp )
1184 if ( gfp->short_blocks == short_block_allowed )
1185 return 1; /* short blocks allowed to differ */
1186 else
1187 return 0; /* not set, dispensed, forced or coupled */
1191 /* Use temporal masking effect */
1193 lame_set_useTemporal( lame_global_flags* gfp,
1194 int useTemporal )
1196 /* default = 1 (enabled) */
1198 /* enforce disable/enable meaning, if we need more than two values
1199 we need to switch to an enum to have an apropriate representation
1200 of the possible meanings of the value */
1201 if ( 0 > useTemporal || 1 < useTemporal )
1202 return -1;
1204 gfp->useTemporal = useTemporal;
1206 return 0;
1210 lame_get_useTemporal( const lame_global_flags* gfp )
1212 assert( 0 <= gfp->useTemporal && 1 >= gfp->useTemporal );
1214 return gfp->useTemporal;
1218 /* Disable short blocks. */
1220 lame_set_no_short_blocks( lame_global_flags* gfp,
1221 int no_short_blocks )
1223 /* enforce disable/enable meaning, if we need more than two values
1224 we need to switch to an enum to have an apropriate representation
1225 of the possible meanings of the value */
1226 if ( 0 > no_short_blocks || 1 < no_short_blocks )
1227 return -1;
1229 gfp->short_blocks =
1230 no_short_blocks ? short_block_dispensed : short_block_allowed;
1232 return 0;
1235 lame_get_no_short_blocks( const lame_global_flags* gfp )
1237 switch ( gfp->short_blocks ) {
1238 default:
1239 case short_block_not_set: return -1;
1240 case short_block_dispensed: return 1;
1241 case short_block_allowed:
1242 case short_block_coupled:
1243 case short_block_forced: return 0;
1248 /* Force short blocks. */
1250 lame_set_force_short_blocks( lame_global_flags* gfp,
1251 int short_blocks )
1253 /* enforce disable/enable meaning, if we need more than two values
1254 we need to switch to an enum to have an apropriate representation
1255 of the possible meanings of the value */
1256 if ( 0 > short_blocks || 1 < short_blocks )
1257 return -1;
1259 if (short_blocks == 1)
1260 gfp->short_blocks = short_block_forced;
1261 else if (gfp->short_blocks == short_block_forced)
1262 gfp->short_blocks = short_block_allowed;
1264 return 0;
1267 lame_get_force_short_blocks( const lame_global_flags* gfp )
1269 switch ( gfp->short_blocks ) {
1270 default:
1271 case short_block_not_set: return -1;
1272 case short_block_dispensed:
1273 case short_block_allowed:
1274 case short_block_coupled: return 0;
1275 case short_block_forced: return 1;
1281 * Input PCM is emphased PCM
1282 * (for instance from one of the rarely emphased CDs).
1284 * It is STRONGLY not recommended to use this, because psycho does not
1285 * take it into account, and last but not least many decoders
1286 * ignore these bits
1289 lame_set_emphasis( lame_global_flags* gfp,
1290 int emphasis )
1292 /* XXX: emphasis should be converted to an enum */
1293 if ( 0 > emphasis || 4 <= emphasis )
1294 return -1;
1296 gfp->emphasis = emphasis;
1298 return 0;
1302 lame_get_emphasis( const lame_global_flags* gfp )
1304 assert( 0 <= gfp->emphasis && 4 > gfp->emphasis );
1306 return gfp->emphasis;
1312 /***************************************************************/
1313 /* internal variables, cannot be set... */
1314 /* provided because they may be of use to calling application */
1315 /***************************************************************/
1317 /* MPEG version.
1318 * 0 = MPEG-2
1319 * 1 = MPEG-1
1320 * (2 = MPEG-2.5)
1323 lame_get_version( const lame_global_flags* gfp )
1325 return gfp->version;
1329 /* Encoder delay. */
1331 lame_get_encoder_delay( const lame_global_flags* gfp )
1333 return gfp->encoder_delay;
1336 /* padding added to the end of the input */
1338 lame_get_encoder_padding( const lame_global_flags* gfp )
1340 return gfp->encoder_padding;
1344 /* Size of MPEG frame. */
1346 lame_get_framesize( const lame_global_flags* gfp )
1348 return gfp->framesize;
1352 /* Number of frames encoded so far. */
1354 lame_get_frameNum( const lame_global_flags* gfp )
1356 return gfp->frameNum;
1360 lame_get_mf_samples_to_encode( const lame_global_flags* gfp )
1362 lame_internal_flags *gfc = gfp->internal_flags;
1363 return gfc->mf_samples_to_encode;
1367 int CDECL lame_get_size_mp3buffer( const lame_global_flags* gfp )
1369 int size;
1370 compute_flushbits(gfp,&size);
1371 return size;
1377 * LAME's estimate of the total number of frames to be encoded.
1378 * Only valid if calling program set num_samples.
1381 lame_get_totalframes( const lame_global_flags* gfp )
1383 int totalframes;
1384 /* estimate based on user set num_samples: */
1385 totalframes =
1386 2 + ((double)gfp->num_samples * gfp->out_samplerate) /
1387 ((double)gfp->in_samplerate * gfp->framesize);
1389 /* check to see if we underestimated totalframes */
1390 // if (totalframes < gfp->frameNum)
1391 // totalframes = gfp->frameNum;
1393 return totalframes;
1399 UNDOCUMENTED, experimental settings. These routines are not prototyped
1400 in lame.h. You should not use them, they are experimental and may
1401 change.
1407 * just another daily changing developer switch
1409 void lame_set_tune( lame_global_flags* gfp, float val )
1411 gfp->tune_value_a = val;
1412 gfp->tune = 1;
1415 /* Custom msfix hack */
1416 void
1417 lame_set_msfix( lame_global_flags* gfp, double msfix )
1419 /* default = 0 */
1420 gfp->msfix = msfix;
1425 lame_set_preset_expopts( lame_global_flags* gfp, int preset_expopts )
1428 lame_internal_flags *gfc = gfp->internal_flags;
1430 gfc->presetTune.use = 1;
1432 /* default = 0 (disabled) */
1433 gfp->preset_expopts = preset_expopts;
1435 switch (preset_expopts)
1437 case 1:
1439 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 1);
1440 lame_set_experimentalX(gfp, 3);
1441 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); // safejoint
1442 lame_set_ATHtype(gfp, 2);
1444 gfc->presetTune.attackthre = 35;
1445 gfc->presetTune.attackthre_s = 150;
1446 gfc->presetTune.ms_maskadjust = .5;
1447 gfc->presetTune.quantcomp_type_s = 3;
1448 gfc->presetTune.quantcomp_alt_type = 3;
1449 gfc->presetTune.athadjust_switch_level = 2; // Always switch
1451 break;
1453 case 2:
1455 if (gfp->VBR == vbr_mtrh) {
1456 lame_set_experimentalX(gfp, 2);
1457 gfc->presetTune.quantcomp_adjust_mtrh = 9;
1458 gfc->presetTune.quantcomp_type_s = 4;
1459 gfc->presetTune.quantcomp_alt_type = 0;
1460 gfc->presetTune.athadjust_safe_noiseshaping_thre = 0.0;
1461 gfc->presetTune.athadjust_safe_athaasensitivity = 8.0;
1463 else {
1464 lame_set_experimentalX(gfp, 3);
1465 gfc->presetTune.quantcomp_adjust_rh_tot = 600;
1466 gfc->presetTune.quantcomp_adjust_rh_max = 60;
1467 gfc->presetTune.quantcomp_type_s = 3;
1468 gfc->presetTune.quantcomp_alt_type = 1;
1471 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 1);
1472 lame_set_experimentalZ(gfp, 1);
1473 lame_set_VBR_q(gfp, 2);
1474 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); // safejoint
1475 lame_set_ATHtype(gfp, 2);
1476 // modify sfb21 by 3 dB plus ns-treble=0
1477 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (12 << 20));
1479 gfc->presetTune.attackthre = 35;
1480 gfc->presetTune.attackthre_s = 150;
1481 gfc->presetTune.ms_maskadjust = .5;
1482 gfc->presetTune.athadjust_switch_level = 1;
1483 gfc->presetTune.athadjust_msfix = 2.13;
1485 break;
1487 case 3:
1489 if (gfp->VBR == vbr_mtrh) {
1490 gfc->presetTune.quantcomp_type_s = 4;
1491 gfc->presetTune.quantcomp_adjust_mtrh = 9;
1492 gfc->presetTune.quantcomp_alt_type = 0;
1493 (void) lame_set_ATHlower( gfp, -2 );
1494 gfc->presetTune.athadjust_safe_noiseshaping_thre = 0.0;
1495 gfc->presetTune.athadjust_safe_athaasensitivity = 8.0;
1497 else {
1498 gfc->presetTune.quantcomp_type_s = 3;
1499 gfc->presetTune.quantcomp_adjust_rh_tot = 600;
1500 gfc->presetTune.quantcomp_adjust_rh_max = 60;
1501 (void) lame_set_ATHlower( gfp, -1 );
1504 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 1);
1505 lame_set_experimentalZ(gfp, 1);
1506 lame_set_experimentalX(gfp, 1);
1507 lame_set_VBR_q(gfp, 2);
1508 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); // safejoint
1509 (void) lame_set_msfix( gfp, 2.13 );
1510 lame_set_ATHtype(gfp, 4);
1511 // modify sfb21 by 3.75 dB plus ns-treble=0
1512 lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (15 << 20));
1514 gfc->presetTune.attackthre = 35;
1515 gfc->presetTune.attackthre_s = 150;
1516 gfc->presetTune.ms_maskadjust = .5;
1517 gfc->presetTune.athadjust_switch_level = 1;
1519 break;
1521 return 0;
1525 lame_set_preset_notune( lame_global_flags* gfp, int preset_notune )
1527 lame_internal_flags *gfc = gfp->internal_flags;
1529 gfc->presetTune.use = 0; // Turn off specialized preset tunings
1531 return 0;