polygon intersector: added horizontal line reconstruction
[swftools.git] / lib / lame / set_get.c
1 /* -*- mode: C; mode: fold -*- */
2 /*
3  * set/get functions for lame_global_flags
4  *
5  * Copyright (c) 2001 Alexander Leidinger
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /* $Id: set_get.c,v 1.2 2006/02/09 16:56:23 kramm Exp $ */
24
25 #include <stdlib.h>
26 #include "config_static.h"
27
28 #include <assert.h>
29 #include "util.h"
30 #include "bitstream.h"  /* because of compute_flushbits */
31
32 #ifdef WITH_DMALLOC
33 #include <dmalloc.h>
34 #endif
35
36
37 /*
38  * input stream description
39  */
40
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)
46 {
47     /* default = 2^32-1 */
48
49     gfp->num_samples = num_samples;
50
51     return 0;
52 }
53
54 unsigned long
55 lame_get_num_samples( const lame_global_flags* gfp )
56 {
57     return gfp->num_samples;
58 }
59
60
61 /* input samplerate */
62 int
63 lame_set_in_samplerate( lame_global_flags*  gfp,
64                         int                 in_samplerate )
65 {
66     /* input sample rate in Hz,  default = 44100 Hz */
67     gfp->in_samplerate = in_samplerate;
68
69     return 0;
70 }
71
72 int
73 lame_get_in_samplerate( const lame_global_flags*  gfp )
74 {
75     return gfp->in_samplerate;
76 }
77
78
79 /* number of channels in input stream */
80 int
81 lame_set_num_channels( lame_global_flags*  gfp,
82                        int                 num_channels )
83 {
84     /* default = 2 */
85
86     if ( 2 < num_channels || 0 == num_channels )
87         return -1;    /* we don't support more than 2 channels */
88
89     gfp->num_channels = num_channels;
90
91     return 0;
92 }
93
94 int
95 lame_get_num_channels( const lame_global_flags*  gfp )
96 {
97     return gfp->num_channels;
98 }
99
100
101 /* scale the input by this amount before encoding (not used for decoding) */
102 int
103 lame_set_scale( lame_global_flags*  gfp,
104                 float               scale )
105 {
106     /* default = 0 */
107     gfp->scale = scale;
108
109     return 0;
110 }
111
112 float
113 lame_get_scale( const lame_global_flags*  gfp )
114 {
115     return gfp->scale;
116 }
117
118
119 /* scale the channel 0 (left) input by this amount before 
120    encoding (not used for decoding) */
121 int
122 lame_set_scale_left( lame_global_flags*  gfp,
123                      float               scale )
124 {
125     /* default = 0 */
126     gfp->scale_left = scale;
127
128     return 0;
129 }
130
131 float
132 lame_get_scale_left( const lame_global_flags*  gfp )
133 {
134     return gfp->scale_left;
135 }
136
137
138 /* scale the channel 1 (right) input by this amount before 
139    encoding (not used for decoding) */
140 int
141 lame_set_scale_right( lame_global_flags*  gfp,
142                       float               scale )
143 {
144     /* default = 0 */
145     gfp->scale_right = scale;
146
147     return 0;
148 }
149
150 float
151 lame_get_scale_right( const lame_global_flags*  gfp )
152 {
153     return gfp->scale_right;
154 }
155
156
157 /* output sample rate in Hz */
158 int
159 lame_set_out_samplerate( lame_global_flags*  gfp,
160                          int                 out_samplerate )
161 {
162     /*
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
169      *
170      * (not used by decoding routines)
171      */
172     gfp->out_samplerate = out_samplerate;
173
174     return 0;
175 }
176
177 int
178 lame_get_out_samplerate( const lame_global_flags*  gfp )
179 {
180     return gfp->out_samplerate;
181 }
182
183
184
185
186 /*
187  * general control parameters
188  */
189
190 /* collect data for an MP3 frame analzyer */
191 int
192 lame_set_analysis( lame_global_flags*  gfp,
193                    int                 analysis )
194 {
195     /* default = 0 */
196
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;
202
203     gfp->analysis = analysis;
204
205     return 0;
206 }
207
208 int
209 lame_get_analysis( const lame_global_flags*  gfp )
210 {
211     assert( 0 <= gfp->analysis && 1 >= gfp->analysis );
212
213     return gfp->analysis;
214 }
215
216
217 /* write a Xing VBR header frame */
218 int
219 lame_set_bWriteVbrTag( lame_global_flags*  gfp,
220                        int bWriteVbrTag )
221 {
222     /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
223
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;
229
230     gfp->bWriteVbrTag = bWriteVbrTag;
231
232     return 0;
233 }
234
235 int
236 lame_get_bWriteVbrTag( const lame_global_flags*  gfp )
237 {
238     assert( 0 <= gfp->bWriteVbrTag && 1 >= gfp->bWriteVbrTag );
239
240     return gfp->bWriteVbrTag;
241 }
242
243
244
245 /* decode only, use lame/mpglib to convert mp3/ogg to wav */
246 int
247 lame_set_decode_only( lame_global_flags*  gfp,
248                       int                 decode_only )
249 {
250     /* default = 0 (disabled) */
251
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;
257
258     gfp->decode_only = decode_only;
259
260     return 0;
261 }
262
263 int
264 lame_get_decode_only( const lame_global_flags*  gfp )
265 {
266     assert( 0 <= gfp->decode_only && 1 >= gfp->decode_only );
267
268     return gfp->decode_only;
269 }
270
271
272 /* encode a Vorbis .ogg file */
273 int
274 lame_set_ogg( lame_global_flags*  gfp,
275               int                 ogg )
276 {
277     /* default = 0 (disabled) */
278
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;
284
285     gfp->ogg = ogg;
286
287     return 0;
288 }
289
290 int
291 lame_get_ogg( const lame_global_flags*  gfp )
292 {
293     assert( 0 <= gfp->ogg && 1 >= gfp->ogg );
294
295     return gfp->ogg;
296 }
297
298
299 /*
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
307  */
308 int
309 lame_set_quality( lame_global_flags*  gfp,
310                   int                 quality )
311 {
312     gfp->quality = quality;
313
314     return 0;
315 }
316
317 int
318 lame_get_quality( const lame_global_flags*  gfp )
319 {
320     return gfp->quality;
321 }
322
323
324 /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
325 int
326 lame_set_mode( lame_global_flags*  gfp,
327                MPEG_mode           mode )
328 {
329     /* default: lame chooses based on compression ratio and input channels */
330
331     if( 0 > mode || MAX_INDICATOR <= mode )
332         return -1;  /* Unknown MPEG mode! */
333
334     gfp->mode = mode;
335
336     return 0;
337 }
338
339 MPEG_mode
340 lame_get_mode( const lame_global_flags*  gfp )
341 {
342     assert( 0 <= gfp->mode && MAX_INDICATOR > gfp->mode );
343
344     return gfp->mode;
345 }
346
347
348 /* Us a M/S mode with a switching threshold based on compression ratio */
349 int
350 lame_set_mode_automs( lame_global_flags*  gfp,
351                       int                 mode_automs )
352 {
353     /* default = 0 (disabled) */
354
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;
360
361     gfp->mode_automs = mode_automs;
362
363     return 0;
364 }
365
366 int
367 lame_get_mode_automs( const lame_global_flags*  gfp )
368 {
369     assert( 0 <= gfp->mode_automs && 1 >= gfp->mode_automs );
370
371     return gfp->mode_automs;
372 }
373
374
375 /*
376  * Force M/S for all frames.  For testing only.
377  * Requires mode = 1.
378  */
379 int
380 lame_set_force_ms( lame_global_flags*  gfp,
381                    int                 force_ms )
382 {
383     /* default = 0 (disabled) */
384
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;
390
391     gfp->force_ms = force_ms;
392
393     return 0;
394 }
395
396 int
397 lame_get_force_ms( const lame_global_flags*  gfp )
398 {
399     assert( 0 <= gfp->force_ms && 1 >= gfp->force_ms );
400
401     return gfp->force_ms;
402 }
403
404
405 /* Use free_format. */
406 int
407 lame_set_free_format( lame_global_flags*  gfp,
408                       int                 free_format )
409 {
410     /* default = 0 (disabled) */
411
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;
417
418     gfp->free_format = free_format;
419
420     return 0;
421 }
422
423 int
424 lame_get_free_format( const lame_global_flags*  gfp )
425 {
426     assert( 0 <= gfp->free_format && 1 >= gfp->free_format );
427
428     return gfp->free_format;
429 }
430
431
432 /* message handlers */
433 int
434 lame_set_errorf( lame_global_flags*  gfp,
435                  void                (*func)( const char*, va_list ) )
436 {
437     gfp->report.errorf = func;
438
439     return 0;
440 }
441
442 int
443 lame_set_debugf( lame_global_flags*  gfp,
444                  void                (*func)( const char*, va_list ) )
445 {
446     gfp->report.debugf = func;
447
448     return 0;
449 }
450
451 int
452 lame_set_msgf( lame_global_flags*  gfp,
453                void                (*func)( const char *, va_list ) )
454 {
455     gfp->report.msgf = func;
456
457     return 0;
458 }
459
460
461 /*
462  * Set one of
463  *  - brate
464  *  - compression ratio.
465  *
466  * Default is compression ratio of 11.
467  */
468 int
469 lame_set_brate( lame_global_flags*  gfp,
470                 int                 brate )
471 {
472     gfp->brate = brate;
473
474     return 0;
475 }
476
477 int
478 lame_get_brate( const lame_global_flags*  gfp )
479 {
480     return gfp->brate;
481 }
482
483 int
484 lame_set_compression_ratio( lame_global_flags*  gfp,
485                             float               compression_ratio )
486 {
487     gfp->compression_ratio = compression_ratio;
488
489     return 0;
490 }
491
492 float
493 lame_get_compression_ratio( const lame_global_flags*  gfp )
494 {
495     return gfp->compression_ratio;
496 }
497
498
499
500
501 /*
502  * frame parameters
503  */
504
505 /* Mark as copyright protected. */
506 int
507 lame_set_copyright( lame_global_flags*  gfp,
508                     int                 copyright )
509 {
510     /* default = 0 (disabled) */
511
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;
517
518     gfp->copyright = copyright;
519
520     return 0;
521 }
522
523 int
524 lame_get_copyright( const lame_global_flags*  gfp )
525 {
526     assert( 0 <= gfp->copyright && 1 >= gfp->copyright );
527
528     return gfp->copyright;
529 }
530
531
532 /* Mark as original. */
533 int
534 lame_set_original( lame_global_flags*  gfp,
535                    int                 original )
536 {
537     /* default = 1 (enabled) */
538
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;
544
545     gfp->original = original;
546
547     return 0;
548 }
549
550 int
551 lame_get_original( const lame_global_flags*  gfp )
552 {
553     assert( 0 <= gfp->original && 1 >= gfp->original );
554
555     return gfp->original;
556 }
557
558
559 /*
560  * error_protection.
561  * Use 2 bytes from each frame for CRC checksum.
562  */
563 int
564 lame_set_error_protection( lame_global_flags*  gfp,
565                            int                 error_protection )
566 {
567     /* default = 0 (disabled) */
568
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;
574
575     gfp->error_protection = error_protection;
576
577     return 0;
578 }
579
580 int
581 lame_get_error_protection( const lame_global_flags*  gfp )
582 {
583     assert( 0 <= gfp->error_protection && 1 >= gfp->error_protection );
584
585     return gfp->error_protection;
586 }
587
588
589 /*
590  * padding_type.
591  *  PAD_NO     = pad no frames
592  *  PAD_ALL    = pad all frames
593  *  PAD_ADJUST = adjust padding
594  */
595 int
596 lame_set_padding_type( lame_global_flags*  gfp,
597                        Padding_type        padding_type )
598 {
599     /* default = 2 */
600
601     if ( 0 > padding_type || PAD_MAX_INDICATOR < padding_type )
602         return -1;  /* Unknown padding type */
603
604     gfp->padding_type = padding_type;
605
606     return 0;
607 }
608
609 Padding_type
610 lame_get_padding_type( const lame_global_flags*  gfp )
611 {
612     assert( 0 <= gfp->padding_type && PAD_MAX_INDICATOR > gfp->padding_type );
613
614     return gfp->padding_type;
615 }
616
617
618 /* MP3 'private extension' bit. Meaningless. */
619 int
620 lame_set_extension( lame_global_flags*  gfp,
621                     int                 extension )
622 {
623     /* default = 0 (disabled) */
624
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;
630
631     gfp->extension = extension;
632
633     return 0;
634 }
635
636 int
637 lame_get_extension( const lame_global_flags*  gfp )
638 {
639     assert( 0 <= gfp->extension && 1 >= gfp->extension );
640
641     return gfp->extension;
642 }
643
644
645 /* Enforce strict ISO compliance. */
646 int
647 lame_set_strict_ISO( lame_global_flags*  gfp,
648                      int                 strict_ISO )
649 {
650     /* default = 0 (disabled) */
651
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;
657
658     gfp->strict_ISO = strict_ISO;
659
660     return 0;
661 }
662
663 int
664 lame_get_strict_ISO( const lame_global_flags*  gfp )
665 {
666     assert( 0 <= gfp->strict_ISO && 1 >= gfp->strict_ISO );
667
668     return gfp->strict_ISO;
669 }
670  
671
672
673
674 /********************************************************************
675  * quantization/noise shaping 
676  ***********************************************************************/
677
678 /* Disable the bit reservoir. For testing only. */
679 int
680 lame_set_disable_reservoir( lame_global_flags*  gfp,
681                             int                 disable_reservoir )
682 {
683     /* default = 0 (disabled) */
684
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;
690
691     gfp->disable_reservoir = disable_reservoir;
692
693     return 0;
694 }
695
696 int
697 lame_get_disable_reservoir( const lame_global_flags*  gfp )
698 {
699     assert( 0 <= gfp->disable_reservoir && 1 >= gfp->disable_reservoir );
700
701     return gfp->disable_reservoir;
702 }
703
704
705
706
707 /* Select a different "best quantization" function. default = 0 */
708 int
709 lame_set_experimentalX( lame_global_flags*  gfp,
710                         int                 experimentalX )
711 {
712     gfp->experimentalX = experimentalX;
713
714     return 0;
715 }
716
717 int
718 lame_get_experimentalX( const lame_global_flags*  gfp )
719 {
720     return gfp->experimentalX;
721 }
722
723
724 /* Another experimental option. For testing only. */
725 int
726 lame_set_experimentalY( lame_global_flags*  gfp,
727                         int                 experimentalY )
728 {
729     gfp->experimentalY = experimentalY;
730
731     return 0;
732 }
733
734 int
735 lame_get_experimentalY( const lame_global_flags*  gfp )
736 {
737     return gfp->experimentalY;
738 }
739
740
741 /* Another experimental option. For testing only. */
742 int
743 lame_set_experimentalZ( lame_global_flags*  gfp,
744                         int                 experimentalZ )
745 {
746     gfp->experimentalZ += experimentalZ;
747
748     return 0;
749 }
750
751 int
752 lame_get_experimentalZ( const lame_global_flags*  gfp )
753 {
754     return gfp->experimentalZ;
755 }
756
757
758 /* Naoki's psycho acoustic model. */
759 int
760 lame_set_exp_nspsytune( lame_global_flags*  gfp,
761                         int                 exp_nspsytune )
762 {
763     /* default = 0 (disabled) */
764
765     gfp->exp_nspsytune = exp_nspsytune;
766
767     return 0;
768 }
769
770 int
771 lame_get_exp_nspsytune( const lame_global_flags*  gfp )
772 {
773     return gfp->exp_nspsytune;
774 }
775
776
777
778
779 /********************************************************************
780  * VBR control
781  ***********************************************************************/
782
783 // Types of VBR.  default = vbr_off = CBR
784 int
785 lame_set_VBR( lame_global_flags*  gfp,
786               vbr_mode            VBR )
787 {
788     if( 0 > VBR || vbr_max_indicator <= VBR )
789         return -1;  /* Unknown VBR mode! */
790
791     gfp->VBR = VBR;
792
793     return 0;
794 }
795
796 vbr_mode
797 lame_get_VBR( const lame_global_flags*  gfp )
798 {
799     assert( 0 <= gfp->VBR && vbr_max_indicator > gfp->VBR );
800
801     return gfp->VBR;
802 }
803
804
805 /*
806  * VBR quality level.
807  *  0 = highest
808  *  9 = lowest 
809  */
810 int
811 lame_set_VBR_q( lame_global_flags*  gfp,
812                 int                 VBR_q )
813 {
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. */
822
823
824     if( 0 > VBR_q || 10 <= VBR_q )
825         return -1;  /* Unknown VBR quality level! */
826
827     gfp->VBR_q = VBR_q;
828
829     return 0;
830 }
831
832 int
833 lame_get_VBR_q( const lame_global_flags*  gfp )
834 {
835     assert( 0 <= gfp->VBR_q && 10 > gfp->VBR_q );
836
837     return gfp->VBR_q;
838 }
839
840
841 /* Ignored except for VBR = vbr_abr (ABR mode) */
842 int
843 lame_set_VBR_mean_bitrate_kbps( lame_global_flags*  gfp,
844                                 int                 VBR_mean_bitrate_kbps )
845 {
846     gfp->VBR_mean_bitrate_kbps = VBR_mean_bitrate_kbps;
847
848     return 0;
849 }
850
851 int
852 lame_get_VBR_mean_bitrate_kbps( const lame_global_flags*  gfp )
853 {
854     return gfp->VBR_mean_bitrate_kbps;
855 }
856
857 int
858 lame_set_VBR_min_bitrate_kbps( lame_global_flags*  gfp,
859                                int                 VBR_min_bitrate_kbps )
860 {
861     gfp->VBR_min_bitrate_kbps = VBR_min_bitrate_kbps;
862
863     return 0;
864 }
865
866 int
867 lame_get_VBR_min_bitrate_kbps( const lame_global_flags*  gfp )
868 {
869     return gfp->VBR_min_bitrate_kbps;
870 }
871
872 int
873 lame_set_VBR_max_bitrate_kbps( lame_global_flags*  gfp,
874                                int                 VBR_max_bitrate_kbps )
875 {
876     gfp->VBR_max_bitrate_kbps = VBR_max_bitrate_kbps;
877
878     return 0;
879 }
880
881 int
882 lame_get_VBR_max_bitrate_kbps( const lame_global_flags*  gfp )
883 {
884     return gfp->VBR_max_bitrate_kbps;
885 }
886
887
888 /*
889  * Strictly enforce VBR_min_bitrate.
890  * Normally it will be violated for analog silence.
891  */
892 int
893 lame_set_VBR_hard_min( lame_global_flags*  gfp,
894                        int                 VBR_hard_min )
895 {
896     /* default = 0 (disabled) */
897
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;
903
904     gfp->VBR_hard_min = VBR_hard_min;
905
906     return 0;
907 }
908
909 int
910 lame_get_VBR_hard_min( const lame_global_flags*  gfp )
911 {
912     assert( 0 <= gfp->VBR_hard_min && 1 >= gfp->VBR_hard_min );
913
914     return gfp->VBR_hard_min;
915 }
916
917
918 /********************************************************************
919  * Filtering control
920  ***********************************************************************/
921
922 /*
923  * Freqency in Hz to apply lowpass.
924  *   0 = default = lame chooses
925  *  -1 = disabled
926  */
927 int
928 lame_set_lowpassfreq( lame_global_flags*  gfp,
929                       int                 lowpassfreq )
930 {
931     gfp->lowpassfreq = lowpassfreq;
932
933     return 0;
934 }
935
936 int
937 lame_get_lowpassfreq( const lame_global_flags*  gfp )
938 {
939     return gfp->lowpassfreq;
940 }
941
942
943 /*
944  * Width of transition band (in Hz).
945  *  default = one polyphase filter band
946  */
947 int
948 lame_set_lowpasswidth( lame_global_flags*  gfp,
949                        int                 lowpasswidth )
950 {
951     gfp->lowpasswidth = lowpasswidth;
952
953     return 0;
954 }
955
956 int
957 lame_get_lowpasswidth( const lame_global_flags*  gfp )
958 {
959     return gfp->lowpasswidth;
960 }
961
962
963 /*
964  * Frequency in Hz to apply highpass.
965  *   0 = default = lame chooses
966  *  -1 = disabled
967  */
968 int
969 lame_set_highpassfreq( lame_global_flags*  gfp,
970                        int                 highpassfreq )
971 {
972     gfp->highpassfreq = highpassfreq;
973
974     return 0;
975 }
976
977 int
978 lame_get_highpassfreq( const lame_global_flags*  gfp )
979 {
980     return gfp->highpassfreq;
981 }
982
983
984 /*
985  * Width of transition band (in Hz).
986  *  default = one polyphase filter band
987  */
988 int
989 lame_set_highpasswidth( lame_global_flags*  gfp,
990                         int                 highpasswidth )
991 {
992     gfp->highpasswidth = highpasswidth;
993
994     return 0;
995 }
996
997 int
998 lame_get_highpasswidth( const lame_global_flags*  gfp )
999 {
1000     return gfp->highpasswidth;
1001 }
1002
1003
1004
1005
1006 /*
1007  * psycho acoustics and other arguments which you should not change 
1008  * unless you know what you are doing
1009  */
1010
1011 /* Only use ATH for masking. */
1012 int
1013 lame_set_ATHonly( lame_global_flags*  gfp,
1014                   int                 ATHonly )
1015 {
1016     gfp->ATHonly = ATHonly;
1017
1018     return 0;
1019 }
1020
1021 int
1022 lame_get_ATHonly( const lame_global_flags*  gfp )
1023 {
1024     return gfp->ATHonly;
1025 }
1026
1027
1028 /* Only use ATH for short blocks. */
1029 int
1030 lame_set_ATHshort( lame_global_flags*  gfp,
1031                    int                 ATHshort )
1032 {
1033     gfp->ATHshort = ATHshort;
1034
1035     return 0;
1036 }
1037
1038 int
1039 lame_get_ATHshort( const lame_global_flags*  gfp )
1040 {
1041     return gfp->ATHshort;
1042 }
1043
1044
1045 /* Disable ATH. */
1046 int
1047 lame_set_noATH( lame_global_flags*  gfp,
1048                 int                 noATH )
1049 {
1050     gfp->noATH = noATH;
1051
1052     return 0;
1053 }
1054
1055 int
1056 lame_get_noATH( const lame_global_flags*  gfp )
1057 {
1058     return gfp->noATH;
1059 }
1060
1061
1062 /* Select ATH formula. */
1063 int
1064 lame_set_ATHtype( lame_global_flags*  gfp,
1065                   int                 ATHtype )
1066 {
1067     /* XXX: ATHtype should be converted to an enum. */
1068     gfp->ATHtype = ATHtype;
1069
1070     return 0;
1071 }
1072
1073 int
1074 lame_get_ATHtype( const lame_global_flags*  gfp )
1075 {
1076     return gfp->ATHtype;
1077 }
1078
1079
1080 /* Lower ATH by this many db. */
1081 int
1082 lame_set_ATHlower( lame_global_flags*  gfp,
1083                    float               ATHlower )
1084 {
1085     gfp->ATHlower = ATHlower;
1086     return 0;
1087 }
1088
1089 float
1090 lame_get_ATHlower( const lame_global_flags*  gfp )
1091 {
1092     return gfp->ATHlower;
1093 }
1094
1095
1096 /* Select ATH adaptive adjustment scheme. */
1097 int
1098 lame_set_athaa_type( lame_global_flags*  gfp,
1099                       int                athaa_type )
1100 {
1101     gfp->athaa_type = athaa_type;
1102
1103     return 0;
1104 }
1105
1106 int
1107 lame_get_athaa_type( const lame_global_flags*  gfp )
1108 {
1109     return gfp->athaa_type;
1110 }
1111
1112
1113 /* Select the loudness approximation used by the ATH adaptive auto-leveling. */
1114 int
1115 lame_set_athaa_loudapprox( lame_global_flags*  gfp,
1116                            int                 athaa_loudapprox )
1117 {
1118     gfp->athaa_loudapprox = athaa_loudapprox;
1119
1120     return 0;
1121 }
1122
1123 int
1124 lame_get_athaa_loudapprox( const lame_global_flags*  gfp )
1125 {
1126     return gfp->athaa_loudapprox;
1127 }
1128
1129
1130 /* Adjust (in dB) the point below which adaptive ATH level adjustment occurs. */
1131 int
1132 lame_set_athaa_sensitivity( lame_global_flags*  gfp,
1133                             float               athaa_sensitivity )
1134 {
1135     gfp->athaa_sensitivity = athaa_sensitivity;
1136
1137     return 0;
1138 }
1139
1140 float
1141 lame_get_athaa_sensitivity( const lame_global_flags*  gfp )
1142 {
1143     return gfp->athaa_sensitivity;
1144 }
1145
1146
1147 /* Predictability limit (ISO tonality formula) */
1148 int
1149 lame_set_cwlimit( lame_global_flags*  gfp,
1150                   int                 cwlimit )
1151 {
1152     gfp->cwlimit = cwlimit;
1153
1154     return 0;
1155 }
1156
1157 int
1158 lame_get_cwlimit( const lame_global_flags*  gfp )
1159 {
1160     return gfp->cwlimit;
1161 }
1162
1163
1164
1165 /*
1166  * Allow blocktypes to differ between channels.
1167  * default:
1168  *  0 for jstereo => block types coupled
1169  *  1 for stereo  => block types may differ
1170  */
1171 int
1172 lame_set_allow_diff_short( lame_global_flags*  gfp,
1173                            int                 allow_diff_short )
1174 {
1175     gfp->short_blocks = 
1176         allow_diff_short ? short_block_allowed : short_block_coupled;
1177
1178     return 0;
1179 }
1180
1181 int
1182 lame_get_allow_diff_short( const lame_global_flags*  gfp )
1183 {
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 */
1188 }
1189
1190
1191 /* Use temporal masking effect */
1192 int
1193 lame_set_useTemporal( lame_global_flags*  gfp,
1194                       int                 useTemporal )
1195 {
1196     /* default = 1 (enabled) */
1197
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;
1203
1204     gfp->useTemporal = useTemporal;
1205
1206     return 0;
1207 }
1208
1209 int
1210 lame_get_useTemporal( const lame_global_flags*  gfp )
1211 {
1212     assert( 0 <= gfp->useTemporal && 1 >= gfp->useTemporal );
1213
1214     return gfp->useTemporal;
1215 }
1216
1217
1218 /* Disable short blocks. */
1219 int
1220 lame_set_no_short_blocks( lame_global_flags*  gfp,
1221                           int                 no_short_blocks )
1222 {
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;
1228
1229     gfp->short_blocks = 
1230         no_short_blocks ? short_block_dispensed : short_block_allowed;
1231
1232     return 0;
1233 }
1234 int
1235 lame_get_no_short_blocks( const lame_global_flags*  gfp )
1236 {
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;
1244     }
1245 }
1246
1247
1248 /* Force short blocks. */
1249 int
1250 lame_set_force_short_blocks( lame_global_flags*  gfp,
1251                           int                 short_blocks )
1252 {
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;
1258
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;
1263
1264     return 0;
1265 }
1266 int
1267 lame_get_force_short_blocks( const lame_global_flags*  gfp )
1268 {
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;
1276     }
1277 }
1278
1279
1280 /*
1281  * Input PCM is emphased PCM
1282  * (for instance from one of the rarely emphased CDs).
1283  *
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
1287  */
1288 int
1289 lame_set_emphasis( lame_global_flags*  gfp,
1290                    int                 emphasis )
1291 {
1292     /* XXX: emphasis should be converted to an enum */
1293     if ( 0 > emphasis || 4 <= emphasis )
1294         return -1;
1295
1296     gfp->emphasis = emphasis;
1297
1298     return 0;
1299 }
1300
1301 int
1302 lame_get_emphasis( const lame_global_flags*  gfp )
1303 {
1304     assert( 0 <= gfp->emphasis && 4 > gfp->emphasis );
1305
1306     return gfp->emphasis;
1307 }
1308
1309
1310
1311
1312 /***************************************************************/
1313 /* internal variables, cannot be set...                        */
1314 /* provided because they may be of use to calling application  */
1315 /***************************************************************/
1316
1317 /* MPEG version.
1318  *  0 = MPEG-2
1319  *  1 = MPEG-1
1320  * (2 = MPEG-2.5)    
1321  */
1322 int
1323 lame_get_version( const lame_global_flags* gfp )
1324 {
1325     return gfp->version;
1326 }
1327
1328
1329 /* Encoder delay. */
1330 int
1331 lame_get_encoder_delay( const lame_global_flags*  gfp )
1332 {
1333     return gfp->encoder_delay;
1334 }
1335
1336 /* padding added to the end of the input */
1337 int
1338 lame_get_encoder_padding( const lame_global_flags*  gfp )
1339 {
1340     return gfp->encoder_padding;
1341 }
1342
1343
1344 /* Size of MPEG frame. */
1345 int
1346 lame_get_framesize( const lame_global_flags*  gfp )
1347 {
1348     return gfp->framesize;
1349 }
1350
1351
1352 /* Number of frames encoded so far. */
1353 int
1354 lame_get_frameNum( const lame_global_flags*  gfp )
1355 {
1356     return gfp->frameNum;
1357 }
1358
1359 int
1360 lame_get_mf_samples_to_encode( const lame_global_flags*  gfp )
1361 {
1362     lame_internal_flags *gfc = gfp->internal_flags;
1363     return gfc->mf_samples_to_encode;
1364 }
1365
1366
1367 int CDECL lame_get_size_mp3buffer( const lame_global_flags*  gfp )
1368 {
1369     int size;
1370     compute_flushbits(gfp,&size);
1371     return size;
1372 }
1373
1374
1375
1376 /*
1377  * LAME's estimate of the total number of frames to be encoded.
1378  * Only valid if calling program set num_samples.
1379  */
1380 int
1381 lame_get_totalframes( const lame_global_flags*  gfp )
1382 {
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);
1388
1389     /* check to see if we underestimated totalframes */
1390     //    if (totalframes < gfp->frameNum)
1391     //        totalframes = gfp->frameNum;
1392
1393     return totalframes;
1394 }
1395
1396
1397 /*
1398
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.  
1402
1403 */
1404
1405
1406 /*
1407  *  just another daily changing developer switch  
1408  */
1409 void lame_set_tune( lame_global_flags* gfp, float val ) 
1410 {
1411     gfp->tune_value_a = val;
1412     gfp->tune = 1;
1413 }
1414
1415 /* Custom msfix hack */
1416 void
1417 lame_set_msfix( lame_global_flags*  gfp, double msfix )
1418 {
1419     /* default = 0 */
1420     gfp->msfix = msfix;
1421
1422 }
1423
1424 int
1425 lame_set_preset_expopts( lame_global_flags*  gfp, int preset_expopts )
1426 {
1427
1428     lame_internal_flags *gfc = gfp->internal_flags;
1429
1430     gfc->presetTune.use = 1;
1431
1432     /* default = 0 (disabled) */
1433     gfp->preset_expopts = preset_expopts;
1434
1435     switch (preset_expopts)
1436     {
1437         case 1:
1438
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);
1443
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
1450
1451           break;
1452
1453         case 2:
1454
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;
1462           }
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;
1469           }
1470
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));
1478
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;
1484
1485           break;
1486
1487         case 3:
1488
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;
1496           }
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 );
1502           }
1503
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));
1513
1514           gfc->presetTune.attackthre   = 35;
1515           gfc->presetTune.attackthre_s = 150;
1516           gfc->presetTune.ms_maskadjust = .5;
1517           gfc->presetTune.athadjust_switch_level = 1;
1518
1519           break;
1520     }
1521     return 0;
1522 }
1523
1524 int
1525 lame_set_preset_notune( lame_global_flags*  gfp, int preset_notune )
1526 {
1527     lame_internal_flags *gfc = gfp->internal_flags;
1528
1529     gfc->presetTune.use = 0;  // Turn off specialized preset tunings
1530
1531     return 0;
1532 }
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551