]> 4ch.mooo.com Git - 16.git/blob - src/lib/dl/ext/lame/set_get.c
refresh wwww
[16.git] / src / lib / dl / ext / lame / set_get.c
1 /* -*- mode: C; mode: fold -*- */
2 /*
3  * set/get functions for lame_global_flags
4  *
5  * Copyright (c) 2001-2005 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.98 2011/05/07 16:05:17 rbrito Exp $ */
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 #include "lame.h"
30 #include "machine.h"
31 #include "encoder.h"
32 #include "util.h"
33 #include "bitstream.h"  /* because of compute_flushbits */
34
35 #include "set_get.h"
36 #include "lame_global_flags.h"
37
38 /*
39  * input stream description
40  */
41
42
43 /* number of samples */
44 /* it's unlikely for this function to return an error */
45 int
46 lame_set_num_samples(lame_global_flags * gfp, unsigned long num_samples)
47 {
48     if (is_lame_global_flags_valid(gfp)) {
49         /* default = 2^32-1 */
50         gfp->num_samples = num_samples;
51         return 0;
52     }
53     return -1;
54 }
55
56 unsigned long
57 lame_get_num_samples(const lame_global_flags * gfp)
58 {
59     if (is_lame_global_flags_valid(gfp)) {
60         return gfp->num_samples;
61     }
62     return 0;
63 }
64
65
66 /* input samplerate */
67 int
68 lame_set_in_samplerate(lame_global_flags * gfp, int in_samplerate)
69 {
70     if (is_lame_global_flags_valid(gfp)) {
71         /* input sample rate in Hz,  default = 44100 Hz */
72         gfp->samplerate_in = in_samplerate;
73         return 0;
74     }
75     return -1;
76 }
77
78 int
79 lame_get_in_samplerate(const lame_global_flags * gfp)
80 {
81     if (is_lame_global_flags_valid(gfp)) {
82         return gfp->samplerate_in;
83     }
84     return 0;
85 }
86
87
88 /* number of channels in input stream */
89 int
90 lame_set_num_channels(lame_global_flags * gfp, int num_channels)
91 {
92     if (is_lame_global_flags_valid(gfp)) {
93         /* default = 2 */
94         if (2 < num_channels || 0 == num_channels) {
95             return -1;  /* we don't support more than 2 channels */
96         }
97         gfp->num_channels = num_channels;
98         return 0;
99     }
100     return -1;
101 }
102
103 int
104 lame_get_num_channels(const lame_global_flags * gfp)
105 {
106     if (is_lame_global_flags_valid(gfp)) {
107         return gfp->num_channels;
108     }
109     return 0;
110 }
111
112
113 /* scale the input by this amount before encoding (not used for decoding) */
114 int
115 lame_set_scale(lame_global_flags * gfp, float scale)
116 {
117     if (is_lame_global_flags_valid(gfp)) {
118         /* default = 1 */
119         gfp->scale = scale;
120         return 0;
121     }
122     return -1;
123 }
124
125 float
126 lame_get_scale(const lame_global_flags * gfp)
127 {
128     if (is_lame_global_flags_valid(gfp)) {
129         return gfp->scale;
130     }
131     return 0;
132 }
133
134
135 /* scale the channel 0 (left) input by this amount before 
136    encoding (not used for decoding) */
137 int
138 lame_set_scale_left(lame_global_flags * gfp, float scale)
139 {
140     if (is_lame_global_flags_valid(gfp)) {
141         /* default = 1 */
142         gfp->scale_left = scale;
143         return 0;
144     }
145     return -1;
146 }
147
148 float
149 lame_get_scale_left(const lame_global_flags * gfp)
150 {
151     if (is_lame_global_flags_valid(gfp)) {
152         return gfp->scale_left;
153     }
154     return 0;
155 }
156
157
158 /* scale the channel 1 (right) input by this amount before 
159    encoding (not used for decoding) */
160 int
161 lame_set_scale_right(lame_global_flags * gfp, float scale)
162 {
163     if (is_lame_global_flags_valid(gfp)) {
164         /* default = 1 */
165         gfp->scale_right = scale;
166         return 0;
167     }
168     return -1;
169 }
170
171 float
172 lame_get_scale_right(const lame_global_flags * gfp)
173 {
174     if (is_lame_global_flags_valid(gfp)) {
175         return gfp->scale_right;
176     }
177     return 0;
178 }
179
180
181 /* output sample rate in Hz */
182 int
183 lame_set_out_samplerate(lame_global_flags * gfp, int out_samplerate)
184 {
185     if (is_lame_global_flags_valid(gfp)) {
186         /*
187          * default = 0: LAME picks best value based on the amount
188          *              of compression
189          * MPEG only allows:
190          *  MPEG1    32, 44.1,   48khz
191          *  MPEG2    16, 22.05,  24
192          *  MPEG2.5   8, 11.025, 12
193          *
194          * (not used by decoding routines)
195          */
196         gfp->samplerate_out = out_samplerate;
197         return 0;
198     }
199     return -1;
200 }
201
202 int
203 lame_get_out_samplerate(const lame_global_flags * gfp)
204 {
205     if (is_lame_global_flags_valid(gfp)) {
206         return gfp->samplerate_out;
207     }
208     return 0;
209 }
210
211
212
213
214 /*
215  * general control parameters
216  */
217
218 /* collect data for an MP3 frame analzyer */
219 int
220 lame_set_analysis(lame_global_flags * gfp, int analysis)
221 {
222     if (is_lame_global_flags_valid(gfp)) {
223         /* default = 0 */
224
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)
229             return -1;
230         gfp->analysis = analysis;
231         return 0;
232     }
233     return -1;
234 }
235
236 int
237 lame_get_analysis(const lame_global_flags * gfp)
238 {
239     if (is_lame_global_flags_valid(gfp)) {
240         assert(0 <= gfp->analysis && 1 >= gfp->analysis);
241         return gfp->analysis;
242     }
243     return 0;
244 }
245
246
247 /* write a Xing VBR header frame */
248 int
249 lame_set_bWriteVbrTag(lame_global_flags * gfp, int bWriteVbrTag)
250 {
251     if (is_lame_global_flags_valid(gfp)) {
252         /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
253
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)
258             return -1;
259         gfp->write_lame_tag = bWriteVbrTag;
260         return 0;
261     }
262     return -1;
263 }
264
265 int
266 lame_get_bWriteVbrTag(const lame_global_flags * gfp)
267 {
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;
271     }
272     return 0;
273 }
274
275
276
277 /* decode only, use lame/mpglib to convert mp3 to wav */
278 int
279 lame_set_decode_only(lame_global_flags * gfp, int decode_only)
280 {
281     if (is_lame_global_flags_valid(gfp)) {
282         /* default = 0 (disabled) */
283
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)
288             return -1;
289         gfp->decode_only = decode_only;
290         return 0;
291     }
292     return -1;
293 }
294
295 int
296 lame_get_decode_only(const lame_global_flags * gfp)
297 {
298     if (is_lame_global_flags_valid(gfp)) {
299         assert(0 <= gfp->decode_only && 1 >= gfp->decode_only);
300         return gfp->decode_only;
301     }
302     return 0;
303 }
304
305
306 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
307 /* 1=encode a Vorbis .ogg file.  default=0 */
308 /* DEPRECATED */
309 int CDECL lame_set_ogg(lame_global_flags *, int);
310 int CDECL lame_get_ogg(const lame_global_flags *);
311 #else
312 #endif
313
314 /* encode a Vorbis .ogg file */
315 /* DEPRECATED */
316 int
317 lame_set_ogg(lame_global_flags * gfp, int ogg)
318 {
319     (void) gfp;
320     (void) ogg;
321     return -1;
322 }
323
324 int
325 lame_get_ogg(const lame_global_flags * gfp)
326 {
327     (void) gfp;
328     return 0;
329 }
330
331
332 /*
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
340  */
341 int
342 lame_set_quality(lame_global_flags * gfp, int quality)
343 {
344     if (is_lame_global_flags_valid(gfp)) {
345         if (quality < 0) {
346             gfp->quality = 0;
347         }
348         else if (quality > 9) {
349             gfp->quality = 9;
350         }
351         else {
352             gfp->quality = quality;
353         }
354         return 0;
355     }
356     return -1;
357 }
358
359 int
360 lame_get_quality(const lame_global_flags * gfp)
361 {
362     if (is_lame_global_flags_valid(gfp)) {
363         return gfp->quality;
364     }
365     return 0;
366 }
367
368
369 /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
370 int
371 lame_set_mode(lame_global_flags * gfp, MPEG_mode mode)
372 {
373     if (is_lame_global_flags_valid(gfp)) {
374         int     mpg_mode = mode;
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! */
378         gfp->mode = mode;
379         return 0;
380     }
381     return -1;
382 }
383
384 MPEG_mode
385 lame_get_mode(const lame_global_flags * gfp)
386 {
387     if (is_lame_global_flags_valid(gfp)) {
388         assert(gfp->mode < MAX_INDICATOR);
389         return gfp->mode;
390     }
391     return NOT_SET;
392 }
393
394
395 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
396 /*
397   mode_automs.  Use a M/S mode with a switching threshold based on
398   compression ratio
399   DEPRECATED
400 */
401 int CDECL lame_set_mode_automs(lame_global_flags *, int);
402 int CDECL lame_get_mode_automs(const lame_global_flags *);
403 #else
404 #endif
405
406 /* Us a M/S mode with a switching threshold based on compression ratio */
407 /* DEPRECATED */
408 int
409 lame_set_mode_automs(lame_global_flags * gfp, int mode_automs)
410 {
411     if (is_lame_global_flags_valid(gfp)) {
412         /* default = 0 (disabled) */
413
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)
418             return -1;
419         lame_set_mode(gfp, JOINT_STEREO);
420         return 0;
421     }
422     return -1;
423 }
424
425 int
426 lame_get_mode_automs(const lame_global_flags * gfp)
427 {
428     (void) gfp;
429     return 1;
430 }
431
432
433 /*
434  * Force M/S for all frames.  For testing only.
435  * Requires mode = 1.
436  */
437 int
438 lame_set_force_ms(lame_global_flags * gfp, int force_ms)
439 {
440     if (is_lame_global_flags_valid(gfp)) {
441         /* default = 0 (disabled) */
442
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)
447             return -1;
448         gfp->force_ms = force_ms;
449         return 0;
450     }
451     return -1;
452 }
453
454 int
455 lame_get_force_ms(const lame_global_flags * gfp)
456 {
457     if (is_lame_global_flags_valid(gfp)) {
458         assert(0 <= gfp->force_ms && 1 >= gfp->force_ms);
459         return gfp->force_ms;
460     }
461     return 0;
462 }
463
464
465 /* Use free_format. */
466 int
467 lame_set_free_format(lame_global_flags * gfp, int free_format)
468 {
469     if (is_lame_global_flags_valid(gfp)) {
470         /* default = 0 (disabled) */
471
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)
476             return -1;
477         gfp->free_format = free_format;
478         return 0;
479     }
480     return -1;
481 }
482
483 int
484 lame_get_free_format(const lame_global_flags * gfp)
485 {
486     if (is_lame_global_flags_valid(gfp)) {
487         assert(0 <= gfp->free_format && 1 >= gfp->free_format);
488         return gfp->free_format;
489     }
490     return 0;
491 }
492
493
494
495 /* Perform ReplayGain analysis */
496 int
497 lame_set_findReplayGain(lame_global_flags * gfp, int findReplayGain)
498 {
499     if (is_lame_global_flags_valid(gfp)) {
500         /* default = 0 (disabled) */
501
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)
506             return -1;
507         gfp->findReplayGain = findReplayGain;
508         return 0;
509     }
510     return -1;
511 }
512
513 int
514 lame_get_findReplayGain(const lame_global_flags * gfp)
515 {
516     if (is_lame_global_flags_valid(gfp)) {
517         assert(0 <= gfp->findReplayGain && 1 >= gfp->findReplayGain);
518         return gfp->findReplayGain;
519     }
520     return 0;
521 }
522
523
524 /* Decode on the fly. Find the peak sample. If ReplayGain analysis is 
525    enabled then perform it on the decoded data. */
526 int
527 lame_set_decode_on_the_fly(lame_global_flags * gfp, int decode_on_the_fly)
528 {
529     if (is_lame_global_flags_valid(gfp)) {
530 #ifndef DECODE_ON_THE_FLY
531         return -1;
532 #else
533         /* default = 0 (disabled) */
534
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)
539             return -1;
540
541         gfp->decode_on_the_fly = decode_on_the_fly;
542
543         return 0;
544 #endif
545     }
546     return -1;
547 }
548
549 int
550 lame_get_decode_on_the_fly(const lame_global_flags * gfp)
551 {
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;
555     }
556     return 0;
557 }
558
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 *);
564
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 *);
570
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 *);
575 #else
576 #endif
577
578 /* DEPRECATED. same as lame_set_decode_on_the_fly() */
579 int
580 lame_set_findPeakSample(lame_global_flags * gfp, int arg)
581 {
582     return lame_set_decode_on_the_fly(gfp, arg);
583 }
584
585 int
586 lame_get_findPeakSample(const lame_global_flags * gfp)
587 {
588     return lame_get_decode_on_the_fly(gfp);
589 }
590
591 /* DEPRECATED. same as lame_set_findReplayGain() */
592 int
593 lame_set_ReplayGain_input(lame_global_flags * gfp, int arg)
594 {
595     return lame_set_findReplayGain(gfp, arg);
596 }
597
598 int
599 lame_get_ReplayGain_input(const lame_global_flags * gfp)
600 {
601     return lame_get_findReplayGain(gfp);
602 }
603
604 /* DEPRECATED. same as lame_set_decode_on_the_fly() &&
605    lame_set_findReplayGain() */
606 int
607 lame_set_ReplayGain_decode(lame_global_flags * gfp, int arg)
608 {
609     if (lame_set_decode_on_the_fly(gfp, arg) < 0 || lame_set_findReplayGain(gfp, arg) < 0)
610         return -1;
611     else
612         return 0;
613 }
614
615 int
616 lame_get_ReplayGain_decode(const lame_global_flags * gfp)
617 {
618     if (lame_get_decode_on_the_fly(gfp) > 0 && lame_get_findReplayGain(gfp) > 0)
619         return 1;
620     else
621         return 0;
622 }
623
624
625 /* set and get some gapless encoding flags */
626
627 int
628 lame_set_nogap_total(lame_global_flags * gfp, int the_nogap_total)
629 {
630     if (is_lame_global_flags_valid(gfp)) {
631         gfp->nogap_total = the_nogap_total;
632         return 0;
633     }
634     return -1;
635 }
636
637 int
638 lame_get_nogap_total(const lame_global_flags * gfp)
639 {
640     if (is_lame_global_flags_valid(gfp)) {
641         return gfp->nogap_total;
642     }
643     return 0;
644 }
645
646 int
647 lame_set_nogap_currentindex(lame_global_flags * gfp, int the_nogap_index)
648 {
649     if (is_lame_global_flags_valid(gfp)) {
650         gfp->nogap_current = the_nogap_index;
651         return 0;
652     }
653     return -1;
654 }
655
656 int
657 lame_get_nogap_currentindex(const lame_global_flags * gfp)
658 {
659     if (is_lame_global_flags_valid(gfp)) {
660         return gfp->nogap_current;
661     }
662     return 0;
663 }
664
665
666 /* message handlers */
667 int
668 lame_set_errorf(lame_global_flags * gfp, void (*func) (const char *, va_list))
669 {
670     if (is_lame_global_flags_valid(gfp)) {
671         gfp->report.errorf = func;
672         return 0;
673     }
674     return -1;
675 }
676
677 int
678 lame_set_debugf(lame_global_flags * gfp, void (*func) (const char *, va_list))
679 {
680     if (is_lame_global_flags_valid(gfp)) {
681         gfp->report.debugf = func;
682         return 0;
683     }
684     return -1;
685 }
686
687 int
688 lame_set_msgf(lame_global_flags * gfp, void (*func) (const char *, va_list))
689 {
690     if (is_lame_global_flags_valid(gfp)) {
691         gfp->report.msgf = func;
692         return 0;
693     }
694     return -1;
695 }
696
697
698 /*
699  * Set one of
700  *  - brate
701  *  - compression ratio.
702  *
703  * Default is compression ratio of 11.
704  */
705 int
706 lame_set_brate(lame_global_flags * gfp, int brate)
707 {
708     if (is_lame_global_flags_valid(gfp)) {
709         gfp->brate = brate;
710         if (brate > 320) {
711             gfp->disable_reservoir = 1;
712         }
713         return 0;
714     }
715     return -1;
716 }
717
718 int
719 lame_get_brate(const lame_global_flags * gfp)
720 {
721     if (is_lame_global_flags_valid(gfp)) {
722         return gfp->brate;
723     }
724     return 0;
725 }
726
727 int
728 lame_set_compression_ratio(lame_global_flags * gfp, float compression_ratio)
729 {
730     if (is_lame_global_flags_valid(gfp)) {
731         gfp->compression_ratio = compression_ratio;
732         return 0;
733     }
734     return -1;
735 }
736
737 float
738 lame_get_compression_ratio(const lame_global_flags * gfp)
739 {
740     if (is_lame_global_flags_valid(gfp)) {
741         return gfp->compression_ratio;
742     }
743     return 0;
744 }
745
746
747
748
749 /*
750  * frame parameters
751  */
752
753 /* Mark as copyright protected. */
754 int
755 lame_set_copyright(lame_global_flags * gfp, int copyright)
756 {
757     if (is_lame_global_flags_valid(gfp)) {
758         /* default = 0 (disabled) */
759
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)
764             return -1;
765         gfp->copyright = copyright;
766         return 0;
767     }
768     return -1;
769 }
770
771 int
772 lame_get_copyright(const lame_global_flags * gfp)
773 {
774     if (is_lame_global_flags_valid(gfp)) {
775         assert(0 <= gfp->copyright && 1 >= gfp->copyright);
776         return gfp->copyright;
777     }
778     return 0;
779 }
780
781
782 /* Mark as original. */
783 int
784 lame_set_original(lame_global_flags * gfp, int original)
785 {
786     if (is_lame_global_flags_valid(gfp)) {
787         /* default = 1 (enabled) */
788
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)
793             return -1;
794         gfp->original = original;
795         return 0;
796     }
797     return -1;
798 }
799
800 int
801 lame_get_original(const lame_global_flags * gfp)
802 {
803     if (is_lame_global_flags_valid(gfp)) {
804         assert(0 <= gfp->original && 1 >= gfp->original);
805         return gfp->original;
806     }
807     return 0;
808 }
809
810
811 /*
812  * error_protection.
813  * Use 2 bytes from each frame for CRC checksum.
814  */
815 int
816 lame_set_error_protection(lame_global_flags * gfp, int error_protection)
817 {
818     if (is_lame_global_flags_valid(gfp)) {
819         /* default = 0 (disabled) */
820
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)
825             return -1;
826         gfp->error_protection = error_protection;
827         return 0;
828     }
829     return -1;
830 }
831
832 int
833 lame_get_error_protection(const lame_global_flags * gfp)
834 {
835     if (is_lame_global_flags_valid(gfp)) {
836         assert(0 <= gfp->error_protection && 1 >= gfp->error_protection);
837         return gfp->error_protection;
838     }
839     return 0;
840 }
841
842
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 *);
847 #else
848 #endif
849
850 /*
851  * padding_type.
852  *  PAD_NO     = pad no frames
853  *  PAD_ALL    = pad all frames
854  *  PAD_ADJUST = adjust padding
855  */
856 int
857 lame_set_padding_type(lame_global_flags * gfp, Padding_type padding_type)
858 {
859     (void) gfp;
860     (void) padding_type;
861     return 0;
862 }
863
864 Padding_type
865 lame_get_padding_type(const lame_global_flags * gfp)
866 {
867     (void) gfp;
868     return PAD_ADJUST;
869 }
870
871
872 /* MP3 'private extension' bit. Meaningless. */
873 int
874 lame_set_extension(lame_global_flags * gfp, int extension)
875 {
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)
882             return -1;
883         gfp->extension = extension;
884         return 0;
885     }
886     return -1;
887 }
888
889 int
890 lame_get_extension(const lame_global_flags * gfp)
891 {
892     if (is_lame_global_flags_valid(gfp)) {
893         assert(0 <= gfp->extension && 1 >= gfp->extension);
894         return gfp->extension;
895     }
896     return 0;
897 }
898
899
900 /* Enforce strict ISO compliance. */
901 int
902 lame_set_strict_ISO(lame_global_flags * gfp, int val)
903 {
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)
910             return -1;
911         gfp->strict_ISO = val;
912         return 0;
913     }
914     return -1;
915 }
916
917 int
918 lame_get_strict_ISO(const lame_global_flags * gfp)
919 {
920     if (is_lame_global_flags_valid(gfp)) {
921         return gfp->strict_ISO;
922     }
923     return 0;
924 }
925
926
927
928
929 /********************************************************************
930  * quantization/noise shaping 
931  ***********************************************************************/
932
933 /* Disable the bit reservoir. For testing only. */
934 int
935 lame_set_disable_reservoir(lame_global_flags * gfp, int disable_reservoir)
936 {
937     if (is_lame_global_flags_valid(gfp)) {
938         /* default = 0 (disabled) */
939
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)
944             return -1;
945         gfp->disable_reservoir = disable_reservoir;
946         return 0;
947     }
948     return -1;
949 }
950
951 int
952 lame_get_disable_reservoir(const lame_global_flags * gfp)
953 {
954     if (is_lame_global_flags_valid(gfp)) {
955         assert(0 <= gfp->disable_reservoir && 1 >= gfp->disable_reservoir);
956         return gfp->disable_reservoir;
957     }
958     return 0;
959 }
960
961
962
963
964 int
965 lame_set_experimentalX(lame_global_flags * gfp, int experimentalX)
966 {
967     if (is_lame_global_flags_valid(gfp)) {
968         lame_set_quant_comp(gfp, experimentalX);
969         lame_set_quant_comp_short(gfp, experimentalX);
970         return 0;
971     }
972     return -1;
973 }
974
975 int
976 lame_get_experimentalX(const lame_global_flags * gfp)
977 {
978     return lame_get_quant_comp(gfp);
979 }
980
981
982 /* Select a different "best quantization" function. default = 0 */
983 int
984 lame_set_quant_comp(lame_global_flags * gfp, int quant_type)
985 {
986     if (is_lame_global_flags_valid(gfp)) {
987         gfp->quant_comp = quant_type;
988         return 0;
989     }
990     return -1;
991 }
992
993 int
994 lame_get_quant_comp(const lame_global_flags * gfp)
995 {
996     if (is_lame_global_flags_valid(gfp)) {
997         return gfp->quant_comp;
998     }
999     return 0;
1000 }
1001
1002
1003 /* Select a different "best quantization" function. default = 0 */
1004 int
1005 lame_set_quant_comp_short(lame_global_flags * gfp, int quant_type)
1006 {
1007     if (is_lame_global_flags_valid(gfp)) {
1008         gfp->quant_comp_short = quant_type;
1009         return 0;
1010     }
1011     return -1;
1012 }
1013
1014 int
1015 lame_get_quant_comp_short(const lame_global_flags * gfp)
1016 {
1017     if (is_lame_global_flags_valid(gfp)) {
1018         return gfp->quant_comp_short;
1019     }
1020     return 0;
1021 }
1022
1023
1024 /* Another experimental option. For testing only. */
1025 int
1026 lame_set_experimentalY(lame_global_flags * gfp, int experimentalY)
1027 {
1028     if (is_lame_global_flags_valid(gfp)) {
1029         gfp->experimentalY = experimentalY;
1030         return 0;
1031     }
1032     return -1;
1033 }
1034
1035 int
1036 lame_get_experimentalY(const lame_global_flags * gfp)
1037 {
1038     if (is_lame_global_flags_valid(gfp)) {
1039         return gfp->experimentalY;
1040     }
1041     return 0;
1042 }
1043
1044
1045 int
1046 lame_set_experimentalZ(lame_global_flags * gfp, int experimentalZ)
1047 {
1048     if (is_lame_global_flags_valid(gfp)) {
1049         gfp->experimentalZ = experimentalZ;
1050         return 0;
1051     }
1052     return -1;
1053 }
1054
1055 int
1056 lame_get_experimentalZ(const lame_global_flags * gfp)
1057 {
1058     if (is_lame_global_flags_valid(gfp)) {
1059         return gfp->experimentalZ;
1060     }
1061     return 0;
1062 }
1063
1064
1065 /* Naoki's psycho acoustic model. */
1066 int
1067 lame_set_exp_nspsytune(lame_global_flags * gfp, int exp_nspsytune)
1068 {
1069     if (is_lame_global_flags_valid(gfp)) {
1070         /* default = 0 (disabled) */
1071         gfp->exp_nspsytune = exp_nspsytune;
1072         return 0;
1073     }
1074     return -1;
1075 }
1076
1077 int
1078 lame_get_exp_nspsytune(const lame_global_flags * gfp)
1079 {
1080     if (is_lame_global_flags_valid(gfp)) {
1081         return gfp->exp_nspsytune;
1082     }
1083     return 0;
1084 }
1085
1086
1087
1088
1089 /********************************************************************
1090  * VBR control
1091  ***********************************************************************/
1092
1093 /* Types of VBR.  default = vbr_off = CBR */
1094 int
1095 lame_set_VBR(lame_global_flags * gfp, vbr_mode VBR)
1096 {
1097     if (is_lame_global_flags_valid(gfp)) {
1098         int     vbr_q = VBR;
1099         if (0 > vbr_q || vbr_max_indicator <= vbr_q)
1100             return -1;  /* Unknown VBR mode! */
1101         gfp->VBR = VBR;
1102         return 0;
1103     }
1104     return -1;
1105 }
1106
1107 vbr_mode
1108 lame_get_VBR(const lame_global_flags * gfp)
1109 {
1110     if (is_lame_global_flags_valid(gfp)) {
1111         assert(gfp->VBR < vbr_max_indicator);
1112         return gfp->VBR;
1113     }
1114     return vbr_off;
1115 }
1116
1117
1118 /*
1119  * VBR quality level.
1120  *  0 = highest
1121  *  9 = lowest 
1122  */
1123 int
1124 lame_set_VBR_q(lame_global_flags * gfp, int VBR_q)
1125 {
1126     if (is_lame_global_flags_valid(gfp)) {
1127         int     ret = 0;
1128
1129         if (0 > VBR_q) {
1130             ret = -1;   /* Unknown VBR quality level! */
1131             VBR_q = 0;
1132         }
1133         if (9 < VBR_q) {
1134             ret = -1;
1135             VBR_q = 9;
1136         }
1137         gfp->VBR_q = VBR_q;
1138         gfp->VBR_q_frac = 0;
1139         return ret;
1140     }
1141     return -1;
1142 }
1143
1144 int
1145 lame_get_VBR_q(const lame_global_flags * gfp)
1146 {
1147     if (is_lame_global_flags_valid(gfp)) {
1148         assert(0 <= gfp->VBR_q && 10 > gfp->VBR_q);
1149         return gfp->VBR_q;
1150     }
1151     return 0;
1152 }
1153
1154 int
1155 lame_set_VBR_quality(lame_global_flags * gfp, float VBR_q)
1156 {
1157     if (is_lame_global_flags_valid(gfp)) {
1158         int     ret = 0;
1159
1160         if (0 > VBR_q) {
1161             ret = -1;   /* Unknown VBR quality level! */
1162             VBR_q = 0;
1163         }
1164         if (9.999 < VBR_q) {
1165             ret = -1;
1166             VBR_q = 9.999;
1167         }
1168
1169         gfp->VBR_q = (int) VBR_q;
1170         gfp->VBR_q_frac = VBR_q - gfp->VBR_q;
1171
1172         return ret;
1173     }
1174     return -1;
1175 }
1176
1177 float
1178 lame_get_VBR_quality(const lame_global_flags * gfp)
1179 {
1180     if (is_lame_global_flags_valid(gfp)) {
1181         return gfp->VBR_q + gfp->VBR_q_frac;
1182     }
1183     return 0;
1184 }
1185
1186
1187 /* Ignored except for VBR = vbr_abr (ABR mode) */
1188 int
1189 lame_set_VBR_mean_bitrate_kbps(lame_global_flags * gfp, int VBR_mean_bitrate_kbps)
1190 {
1191     if (is_lame_global_flags_valid(gfp)) {
1192         gfp->VBR_mean_bitrate_kbps = VBR_mean_bitrate_kbps;
1193         return 0;
1194     }
1195     return -1;
1196 }
1197
1198 int
1199 lame_get_VBR_mean_bitrate_kbps(const lame_global_flags * gfp)
1200 {
1201     if (is_lame_global_flags_valid(gfp)) {
1202         return gfp->VBR_mean_bitrate_kbps;
1203     }
1204     return 0;
1205 }
1206
1207 int
1208 lame_set_VBR_min_bitrate_kbps(lame_global_flags * gfp, int VBR_min_bitrate_kbps)
1209 {
1210     if (is_lame_global_flags_valid(gfp)) {
1211         gfp->VBR_min_bitrate_kbps = VBR_min_bitrate_kbps;
1212         return 0;
1213     }
1214     return -1;
1215 }
1216
1217 int
1218 lame_get_VBR_min_bitrate_kbps(const lame_global_flags * gfp)
1219 {
1220     if (is_lame_global_flags_valid(gfp)) {
1221         return gfp->VBR_min_bitrate_kbps;
1222     }
1223     return 0;
1224 }
1225
1226 int
1227 lame_set_VBR_max_bitrate_kbps(lame_global_flags * gfp, int VBR_max_bitrate_kbps)
1228 {
1229     if (is_lame_global_flags_valid(gfp)) {
1230         gfp->VBR_max_bitrate_kbps = VBR_max_bitrate_kbps;
1231         return 0;
1232     }
1233     return -1;
1234 }
1235
1236 int
1237 lame_get_VBR_max_bitrate_kbps(const lame_global_flags * gfp)
1238 {
1239     if (is_lame_global_flags_valid(gfp)) {
1240         return gfp->VBR_max_bitrate_kbps;
1241     }
1242     return 0;
1243 }
1244
1245
1246 /*
1247  * Strictly enforce VBR_min_bitrate.
1248  * Normally it will be violated for analog silence.
1249  */
1250 int
1251 lame_set_VBR_hard_min(lame_global_flags * gfp, int VBR_hard_min)
1252 {
1253     if (is_lame_global_flags_valid(gfp)) {
1254         /* default = 0 (disabled) */
1255
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)
1260             return -1;
1261
1262         gfp->VBR_hard_min = VBR_hard_min;
1263
1264         return 0;
1265     }
1266     return -1;
1267 }
1268
1269 int
1270 lame_get_VBR_hard_min(const lame_global_flags * gfp)
1271 {
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;
1275     }
1276     return 0;
1277 }
1278
1279
1280 /********************************************************************
1281  * Filtering control
1282  ***********************************************************************/
1283
1284 /*
1285  * Freqency in Hz to apply lowpass.
1286  *   0 = default = lame chooses
1287  *  -1 = disabled
1288  */
1289 int
1290 lame_set_lowpassfreq(lame_global_flags * gfp, int lowpassfreq)
1291 {
1292     if (is_lame_global_flags_valid(gfp)) {
1293         gfp->lowpassfreq = lowpassfreq;
1294         return 0;
1295     }
1296     return -1;
1297 }
1298
1299 int
1300 lame_get_lowpassfreq(const lame_global_flags * gfp)
1301 {
1302     if (is_lame_global_flags_valid(gfp)) {
1303         return gfp->lowpassfreq;
1304     }
1305     return 0;
1306 }
1307
1308
1309 /*
1310  * Width of transition band (in Hz).
1311  *  default = one polyphase filter band
1312  */
1313 int
1314 lame_set_lowpasswidth(lame_global_flags * gfp, int lowpasswidth)
1315 {
1316     if (is_lame_global_flags_valid(gfp)) {
1317         gfp->lowpasswidth = lowpasswidth;
1318         return 0;
1319     }
1320     return -1;
1321 }
1322
1323 int
1324 lame_get_lowpasswidth(const lame_global_flags * gfp)
1325 {
1326     if (is_lame_global_flags_valid(gfp)) {
1327         return gfp->lowpasswidth;
1328     }
1329     return 0;
1330 }
1331
1332
1333 /*
1334  * Frequency in Hz to apply highpass.
1335  *   0 = default = lame chooses
1336  *  -1 = disabled
1337  */
1338 int
1339 lame_set_highpassfreq(lame_global_flags * gfp, int highpassfreq)
1340 {
1341     if (is_lame_global_flags_valid(gfp)) {
1342         gfp->highpassfreq = highpassfreq;
1343         return 0;
1344     }
1345     return -1;
1346 }
1347
1348 int
1349 lame_get_highpassfreq(const lame_global_flags * gfp)
1350 {
1351     if (is_lame_global_flags_valid(gfp)) {
1352         return gfp->highpassfreq;
1353     }
1354     return 0;
1355 }
1356
1357
1358 /*
1359  * Width of transition band (in Hz).
1360  *  default = one polyphase filter band
1361  */
1362 int
1363 lame_set_highpasswidth(lame_global_flags * gfp, int highpasswidth)
1364 {
1365     if (is_lame_global_flags_valid(gfp)) {
1366         gfp->highpasswidth = highpasswidth;
1367         return 0;
1368     }
1369     return -1;
1370 }
1371
1372 int
1373 lame_get_highpasswidth(const lame_global_flags * gfp)
1374 {
1375     if (is_lame_global_flags_valid(gfp)) {
1376         return gfp->highpasswidth;
1377     }
1378     return 0;
1379 }
1380
1381
1382
1383
1384 /*
1385  * psycho acoustics and other arguments which you should not change 
1386  * unless you know what you are doing
1387  */
1388
1389
1390 /* Adjust masking values. */
1391 int
1392 lame_set_maskingadjust(lame_global_flags * gfp, float adjust)
1393 {
1394     if (is_lame_global_flags_valid(gfp)) {
1395         gfp->maskingadjust = adjust;
1396         return 0;
1397     }
1398     return -1;
1399 }
1400
1401 float
1402 lame_get_maskingadjust(const lame_global_flags * gfp)
1403 {
1404     if (is_lame_global_flags_valid(gfp)) {
1405         return gfp->maskingadjust;
1406     }
1407     return 0;
1408 }
1409
1410 int
1411 lame_set_maskingadjust_short(lame_global_flags * gfp, float adjust)
1412 {
1413     if (is_lame_global_flags_valid(gfp)) {
1414         gfp->maskingadjust_short = adjust;
1415         return 0;
1416     }
1417     return -1;
1418 }
1419
1420 float
1421 lame_get_maskingadjust_short(const lame_global_flags * gfp)
1422 {
1423     if (is_lame_global_flags_valid(gfp)) {
1424         return gfp->maskingadjust_short;
1425     }
1426     return 0;
1427 }
1428
1429 /* Only use ATH for masking. */
1430 int
1431 lame_set_ATHonly(lame_global_flags * gfp, int ATHonly)
1432 {
1433     if (is_lame_global_flags_valid(gfp)) {
1434         gfp->ATHonly = ATHonly;
1435         return 0;
1436     }
1437     return -1;
1438 }
1439
1440 int
1441 lame_get_ATHonly(const lame_global_flags * gfp)
1442 {
1443     if (is_lame_global_flags_valid(gfp)) {
1444         return gfp->ATHonly;
1445     }
1446     return 0;
1447 }
1448
1449
1450 /* Only use ATH for short blocks. */
1451 int
1452 lame_set_ATHshort(lame_global_flags * gfp, int ATHshort)
1453 {
1454     if (is_lame_global_flags_valid(gfp)) {
1455         gfp->ATHshort = ATHshort;
1456         return 0;
1457     }
1458     return -1;
1459 }
1460
1461 int
1462 lame_get_ATHshort(const lame_global_flags * gfp)
1463 {
1464     if (is_lame_global_flags_valid(gfp)) {
1465         return gfp->ATHshort;
1466     }
1467     return 0;
1468 }
1469
1470
1471 /* Disable ATH. */
1472 int
1473 lame_set_noATH(lame_global_flags * gfp, int noATH)
1474 {
1475     if (is_lame_global_flags_valid(gfp)) {
1476         gfp->noATH = noATH;
1477         return 0;
1478     }
1479     return -1;
1480 }
1481
1482 int
1483 lame_get_noATH(const lame_global_flags * gfp)
1484 {
1485     if (is_lame_global_flags_valid(gfp)) {
1486         return gfp->noATH;
1487     }
1488     return 0;
1489 }
1490
1491
1492 /* Select ATH formula. */
1493 int
1494 lame_set_ATHtype(lame_global_flags * gfp, int ATHtype)
1495 {
1496     if (is_lame_global_flags_valid(gfp)) {
1497         /* XXX: ATHtype should be converted to an enum. */
1498         gfp->ATHtype = ATHtype;
1499         return 0;
1500     }
1501     return -1;
1502 }
1503
1504 int
1505 lame_get_ATHtype(const lame_global_flags * gfp)
1506 {
1507     if (is_lame_global_flags_valid(gfp)) {
1508         return gfp->ATHtype;
1509     }
1510     return 0;
1511 }
1512
1513
1514 /* Select ATH formula 4 shape. */
1515 int
1516 lame_set_ATHcurve(lame_global_flags * gfp, float ATHcurve)
1517 {
1518     if (is_lame_global_flags_valid(gfp)) {
1519         gfp->ATHcurve = ATHcurve;
1520         return 0;
1521     }
1522     return -1;
1523 }
1524
1525 float
1526 lame_get_ATHcurve(const lame_global_flags * gfp)
1527 {
1528     if (is_lame_global_flags_valid(gfp)) {
1529         return gfp->ATHcurve;
1530     }
1531     return 0;
1532 }
1533
1534
1535 /* Lower ATH by this many db. */
1536 int
1537 lame_set_ATHlower(lame_global_flags * gfp, float ATHlower)
1538 {
1539     if (is_lame_global_flags_valid(gfp)) {
1540         gfp->ATH_lower_db = ATHlower;
1541         return 0;
1542     }
1543     return -1;
1544 }
1545
1546 float
1547 lame_get_ATHlower(const lame_global_flags * gfp)
1548 {
1549     if (is_lame_global_flags_valid(gfp)) {
1550         return gfp->ATH_lower_db;
1551     }
1552     return 0;
1553 }
1554
1555
1556 /* Select ATH adaptive adjustment scheme. */
1557 int
1558 lame_set_athaa_type(lame_global_flags * gfp, int athaa_type)
1559 {
1560     if (is_lame_global_flags_valid(gfp)) {
1561         gfp->athaa_type = athaa_type;
1562         return 0;
1563     }
1564     return -1;
1565 }
1566
1567 int
1568 lame_get_athaa_type(const lame_global_flags * gfp)
1569 {
1570     if (is_lame_global_flags_valid(gfp)) {
1571         return gfp->athaa_type;
1572     }
1573     return 0;
1574 }
1575
1576
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);
1580 #else
1581 #endif
1582
1583 /* Select the loudness approximation used by the ATH adaptive auto-leveling. */
1584 int
1585 lame_set_athaa_loudapprox(lame_global_flags * gfp, int athaa_loudapprox)
1586 {
1587     (void) gfp;
1588     (void) athaa_loudapprox;
1589     return 0;
1590 }
1591
1592 int
1593 lame_get_athaa_loudapprox(const lame_global_flags * gfp)
1594 {
1595     (void) gfp;
1596     /* obsolete, the type known under number 2 is the only survival */
1597     return 2;
1598 }
1599
1600
1601 /* Adjust (in dB) the point below which adaptive ATH level adjustment occurs. */
1602 int
1603 lame_set_athaa_sensitivity(lame_global_flags * gfp, float athaa_sensitivity)
1604 {
1605     if (is_lame_global_flags_valid(gfp)) {
1606         gfp->athaa_sensitivity = athaa_sensitivity;
1607         return 0;
1608     }
1609     return -1;
1610 }
1611
1612 float
1613 lame_get_athaa_sensitivity(const lame_global_flags * gfp)
1614 {
1615     if (is_lame_global_flags_valid(gfp)) {
1616         return gfp->athaa_sensitivity;
1617     }
1618     return 0;
1619 }
1620
1621
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);
1625
1626 int
1627 lame_set_cwlimit(lame_global_flags * gfp, int cwlimit)
1628 {
1629     (void) gfp;
1630     (void) cwlimit;
1631     return 0;
1632 }
1633
1634 int
1635 lame_get_cwlimit(const lame_global_flags * gfp)
1636 {
1637     (void) gfp;
1638     return 0;
1639 }
1640
1641
1642
1643 /*
1644  * Allow blocktypes to differ between channels.
1645  * default:
1646  *  0 for jstereo => block types coupled
1647  *  1 for stereo  => block types may differ
1648  */
1649 int
1650 lame_set_allow_diff_short(lame_global_flags * gfp, int allow_diff_short)
1651 {
1652     if (is_lame_global_flags_valid(gfp)) {
1653         gfp->short_blocks = allow_diff_short ? short_block_allowed : short_block_coupled;
1654         return 0;
1655     }
1656     return -1;
1657 }
1658
1659 int
1660 lame_get_allow_diff_short(const lame_global_flags * gfp)
1661 {
1662     if (is_lame_global_flags_valid(gfp)) {
1663         if (gfp->short_blocks == short_block_allowed)
1664             return 1;   /* short blocks allowed to differ */
1665         else
1666             return 0;   /* not set, dispensed, forced or coupled */
1667     }
1668     return 0;
1669 }
1670
1671
1672 /* Use temporal masking effect */
1673 int
1674 lame_set_useTemporal(lame_global_flags * gfp, int useTemporal)
1675 {
1676     if (is_lame_global_flags_valid(gfp)) {
1677         /* default = 1 (enabled) */
1678
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;
1684             return 0;
1685         }
1686     }
1687     return -1;
1688 }
1689
1690 int
1691 lame_get_useTemporal(const lame_global_flags * gfp)
1692 {
1693     if (is_lame_global_flags_valid(gfp)) {
1694         assert(0 <= gfp->useTemporal && 1 >= gfp->useTemporal);
1695         return gfp->useTemporal;
1696     }
1697     return 0;
1698 }
1699
1700
1701 /* Use inter-channel masking effect */
1702 int
1703 lame_set_interChRatio(lame_global_flags * gfp, float ratio)
1704 {
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;
1709             return 0;
1710         }
1711     }
1712     return -1;
1713 }
1714
1715 float
1716 lame_get_interChRatio(const lame_global_flags * gfp)
1717 {
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;
1721     }
1722     return 0;
1723 }
1724
1725
1726 /* Use pseudo substep shaping method */
1727 int
1728 lame_set_substep(lame_global_flags * gfp, int method)
1729 {
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;
1734             return 0;
1735         }
1736     }
1737     return -1;
1738 }
1739
1740 int
1741 lame_get_substep(const lame_global_flags * gfp)
1742 {
1743     if (is_lame_global_flags_valid(gfp)) {
1744         assert(0 <= gfp->substep_shaping && gfp->substep_shaping <= 7);
1745         return gfp->substep_shaping;
1746     }
1747     return 0;
1748 }
1749
1750 /* scalefactors scale */
1751 int
1752 lame_set_sfscale(lame_global_flags * gfp, int val)
1753 {
1754     if (is_lame_global_flags_valid(gfp)) {
1755         gfp->noise_shaping = (val != 0) ? 2 : 1;
1756         return 0;
1757     }
1758     return -1;
1759 }
1760
1761 int
1762 lame_get_sfscale(const lame_global_flags * gfp)
1763 {
1764     if (is_lame_global_flags_valid(gfp)) {
1765         return (gfp->noise_shaping == 2) ? 1 : 0;
1766     }
1767     return 0;
1768 }
1769
1770 /* subblock gain */
1771 int
1772 lame_set_subblock_gain(lame_global_flags * gfp, int sbgain)
1773 {
1774     if (is_lame_global_flags_valid(gfp)) {
1775         gfp->subblock_gain = sbgain;
1776         return 0;
1777     }
1778     return -1;
1779 }
1780
1781 int
1782 lame_get_subblock_gain(const lame_global_flags * gfp)
1783 {
1784     if (is_lame_global_flags_valid(gfp)) {
1785         return gfp->subblock_gain;
1786     }
1787     return 0;
1788 }
1789
1790
1791 /* Disable short blocks. */
1792 int
1793 lame_set_no_short_blocks(lame_global_flags * gfp, int no_short_blocks)
1794 {
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;
1801             return 0;
1802         }
1803     }
1804     return -1;
1805 }
1806
1807 int
1808 lame_get_no_short_blocks(const lame_global_flags * gfp)
1809 {
1810     if (is_lame_global_flags_valid(gfp)) {
1811         switch (gfp->short_blocks) {
1812         default:
1813         case short_block_not_set:
1814             return -1;
1815         case short_block_dispensed:
1816             return 1;
1817         case short_block_allowed:
1818         case short_block_coupled:
1819         case short_block_forced:
1820             return 0;
1821         }
1822     }
1823     return -1;
1824 }
1825
1826
1827 /* Force short blocks. */
1828 int
1829 lame_set_force_short_blocks(lame_global_flags * gfp, int short_blocks)
1830 {
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)
1836             return -1;
1837
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;
1842
1843         return 0;
1844     }
1845     return -1;
1846 }
1847
1848 int
1849 lame_get_force_short_blocks(const lame_global_flags * gfp)
1850 {
1851     if (is_lame_global_flags_valid(gfp)) {
1852         switch (gfp->short_blocks) {
1853         default:
1854         case short_block_not_set:
1855             return -1;
1856         case short_block_dispensed:
1857         case short_block_allowed:
1858         case short_block_coupled:
1859             return 0;
1860         case short_block_forced:
1861             return 1;
1862         }
1863     }
1864     return -1;
1865 }
1866
1867 int
1868 lame_set_short_threshold_lrm(lame_global_flags * gfp, float lrm)
1869 {
1870     if (is_lame_global_flags_valid(gfp)) {
1871         gfp->attackthre = lrm;
1872         return 0;
1873     }
1874     return -1;
1875 }
1876
1877 float
1878 lame_get_short_threshold_lrm(const lame_global_flags * gfp)
1879 {
1880     if (is_lame_global_flags_valid(gfp)) {
1881         return gfp->attackthre;
1882     }
1883     return 0;
1884 }
1885
1886 int
1887 lame_set_short_threshold_s(lame_global_flags * gfp, float s)
1888 {
1889     if (is_lame_global_flags_valid(gfp)) {
1890         gfp->attackthre_s = s;
1891         return 0;
1892     }
1893     return -1;
1894 }
1895
1896 float
1897 lame_get_short_threshold_s(const lame_global_flags * gfp)
1898 {
1899     if (is_lame_global_flags_valid(gfp)) {
1900         return gfp->attackthre_s;
1901     }
1902     return 0;
1903 }
1904
1905 int
1906 lame_set_short_threshold(lame_global_flags * gfp, float lrm, float s)
1907 {
1908     if (is_lame_global_flags_valid(gfp)) {
1909         lame_set_short_threshold_lrm(gfp, lrm);
1910         lame_set_short_threshold_s(gfp, s);
1911         return 0;
1912     }
1913     return -1;
1914 }
1915
1916
1917 /*
1918  * Input PCM is emphased PCM
1919  * (for instance from one of the rarely emphased CDs).
1920  *
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
1923  * ignore these bits
1924  */
1925 int
1926 lame_set_emphasis(lame_global_flags * gfp, int emphasis)
1927 {
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;
1932             return 0;
1933         }
1934     }
1935     return -1;
1936 }
1937
1938 int
1939 lame_get_emphasis(const lame_global_flags * gfp)
1940 {
1941     if (is_lame_global_flags_valid(gfp)) {
1942         assert(0 <= gfp->emphasis && gfp->emphasis < 4);
1943         return gfp->emphasis;
1944     }
1945     return 0;
1946 }
1947
1948
1949
1950
1951 /***************************************************************/
1952 /* internal variables, cannot be set...                        */
1953 /* provided because they may be of use to calling application  */
1954 /***************************************************************/
1955
1956 /* MPEG version.
1957  *  0 = MPEG-2
1958  *  1 = MPEG-1
1959  * (2 = MPEG-2.5)    
1960  */
1961 int
1962 lame_get_version(const lame_global_flags * gfp)
1963 {
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;
1968         }
1969     }
1970     return 0;
1971 }
1972
1973
1974 /* Encoder delay. */
1975 int
1976 lame_get_encoder_delay(const lame_global_flags * gfp)
1977 {
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;
1982         }
1983     }
1984     return 0;
1985 }
1986
1987 /* padding added to the end of the input */
1988 int
1989 lame_get_encoder_padding(const lame_global_flags * gfp)
1990 {
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;
1995         }
1996     }
1997     return 0;
1998 }
1999
2000
2001 /* Size of MPEG frame. */
2002 int
2003 lame_get_framesize(const lame_global_flags * gfp)
2004 {
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;
2010         }
2011     }
2012     return 0;
2013 }
2014
2015
2016 /* Number of frames encoded so far. */
2017 int
2018 lame_get_frameNum(const lame_global_flags * gfp)
2019 {
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;
2024         }
2025     }
2026     return 0;
2027 }
2028
2029 int
2030 lame_get_mf_samples_to_encode(const lame_global_flags * gfp)
2031 {
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;
2036         }
2037     }
2038     return 0;
2039 }
2040
2041 int     CDECL
2042 lame_get_size_mp3buffer(const lame_global_flags * gfp)
2043 {
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)) {
2047             int     size;
2048             compute_flushbits(gfc, &size);
2049             return size;
2050         }
2051     }
2052     return 0;
2053 }
2054
2055 int
2056 lame_get_RadioGain(const lame_global_flags * gfp)
2057 {
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;
2062         }
2063     }
2064     return 0;
2065 }
2066
2067 int
2068 lame_get_AudiophileGain(const lame_global_flags * gfp)
2069 {
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)) {
2073             return 0;
2074         }
2075     }
2076     return 0;
2077 }
2078
2079 float
2080 lame_get_PeakSample(const lame_global_flags * gfp)
2081 {
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;
2086         }
2087     }
2088     return 0;
2089 }
2090
2091 int
2092 lame_get_noclipGainChange(const lame_global_flags * gfp)
2093 {
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;
2098         }
2099     }
2100     return 0;
2101 }
2102
2103 float
2104 lame_get_noclipScale(const lame_global_flags * gfp)
2105 {
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;
2110         }
2111     }
2112     return 0;
2113 }
2114
2115
2116 /*
2117  * LAME's estimate of the total number of frames to be encoded.
2118  * Only valid if calling program set num_samples.
2119  */
2120 int
2121 lame_get_totalframes(const lame_global_flags * gfp)
2122 {
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;
2130
2131             /* estimate based on user set num_samples: */
2132             if (pcm_samples_to_encode == (0ul-1ul)) {
2133                 return 0;
2134             }
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;
2138             }
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;
2143             }
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;
2149         }
2150     }
2151     return 0;
2152 }
2153
2154
2155
2156
2157
2158 int
2159 lame_set_preset(lame_global_flags * gfp, int preset)
2160 {
2161     if (is_lame_global_flags_valid(gfp)) {
2162         gfp->preset = preset;
2163         return apply_preset(gfp, preset, 1);
2164     }
2165     return -1;
2166 }
2167
2168
2169
2170 int
2171 lame_set_asm_optimizations(lame_global_flags * gfp, int optim, int mode)
2172 {
2173     if (is_lame_global_flags_valid(gfp)) {
2174         mode = (mode == 1 ? 1 : 0);
2175         switch (optim) {
2176         case MMX:{
2177                 gfp->asm_optimizations.mmx = mode;
2178                 return optim;
2179             }
2180         case AMD_3DNOW:{
2181                 gfp->asm_optimizations.amd3dnow = mode;
2182                 return optim;
2183             }
2184         case SSE:{
2185                 gfp->asm_optimizations.sse = mode;
2186                 return optim;
2187             }
2188         default:
2189             return optim;
2190         }
2191     }
2192     return -1;
2193 }
2194
2195
2196 void
2197 lame_set_write_id3tag_automatic(lame_global_flags * gfp, int v)
2198 {
2199     if (is_lame_global_flags_valid(gfp)) {
2200         gfp->write_id3tag_automatic = v;
2201     }
2202 }
2203
2204
2205 int
2206 lame_get_write_id3tag_automatic(lame_global_flags const *gfp)
2207 {
2208     if (is_lame_global_flags_valid(gfp)) {
2209         return gfp->write_id3tag_automatic;
2210     }
2211     return 1;
2212 }
2213
2214
2215 /*
2216
2217 UNDOCUMENTED, experimental settings.  These routines are not prototyped
2218 in lame.h.  You should not use them, they are experimental and may
2219 change.  
2220
2221 */
2222
2223
2224 /*
2225  *  just another daily changing developer switch  
2226  */
2227 void CDECL lame_set_tune(lame_global_flags *, float);
2228
2229 void
2230 lame_set_tune(lame_global_flags * gfp, float val)
2231 {
2232     if (is_lame_global_flags_valid(gfp)) {
2233         gfp->tune_value_a = val;
2234         gfp->tune = 1;
2235     }
2236 }
2237
2238 /* Custom msfix hack */
2239 void
2240 lame_set_msfix(lame_global_flags * gfp, double msfix)
2241 {
2242     if (is_lame_global_flags_valid(gfp)) {
2243         /* default = 0 */
2244         gfp->msfix = msfix;
2245     }
2246 }
2247
2248 float
2249 lame_get_msfix(const lame_global_flags * gfp)
2250 {
2251     if (is_lame_global_flags_valid(gfp)) {
2252         return gfp->msfix;
2253     }
2254     return 0;
2255 }
2256
2257 #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
2258 int CDECL lame_set_preset_expopts(lame_global_flags *, int);
2259 #else
2260 #endif
2261
2262 int
2263 lame_set_preset_expopts(lame_global_flags * gfp, int preset_expopts)
2264 {
2265     (void) gfp;
2266     (void) preset_expopts;
2267     return 0;
2268 }
2269
2270
2271 int
2272 lame_set_preset_notune(lame_global_flags * gfp, int preset_notune)
2273 {
2274     (void) gfp;
2275     (void) preset_notune;
2276     return 0;
2277 }