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 2001/03/12 04:38:35 markt Exp $ */
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 #include <assert.h>
30 #include "lame.h"
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
lame_set_num_samples(lame_global_flags * gfp,unsigned long num_samples)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
lame_get_num_samples(const lame_global_flags * gfp)55 lame_get_num_samples( const lame_global_flags* gfp )
56 {
57 return gfp->num_samples;
58 }
59
60
61 /* input samplerate */
62 int
lame_set_in_samplerate(lame_global_flags * gfp,int in_samplerate)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
lame_get_in_samplerate(const lame_global_flags * gfp)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
lame_set_num_channels(lame_global_flags * gfp,int num_channels)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 didn't support more than 2 channels */
88
89 gfp->num_channels = num_channels;
90
91 return 0;
92 }
93
94 int
lame_get_num_channels(const lame_global_flags * gfp)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
lame_set_scale(lame_global_flags * gfp,float scale)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
lame_get_scale(const lame_global_flags * gfp)113 lame_get_scale( const lame_global_flags* gfp )
114 {
115 return gfp->scale;
116 }
117
118
119 /* output sample rate in Hz */
120 int
lame_set_out_samplerate(lame_global_flags * gfp,int out_samplerate)121 lame_set_out_samplerate( lame_global_flags* gfp,
122 int out_samplerate )
123 {
124 /*
125 * default = 0: LAME picks best value based on the amount
126 * of compression
127 * MPEG only allows:
128 * MPEG1 32, 44.1, 48khz
129 * MPEG2 16, 22.05, 24
130 * MPEG2.5 8, 11.025, 12
131 *
132 * (not used by decoding routines)
133 */
134 gfp->out_samplerate = out_samplerate;
135
136 return 0;
137 }
138
139 int
lame_get_out_samplerate(const lame_global_flags * gfp)140 lame_get_out_samplerate( const lame_global_flags* gfp )
141 {
142 return gfp->out_samplerate;
143 }
144
145
146
147
148 /*
149 * general control parameters
150 */
151
152 /*collect data for an MP3 frame analzyer */
153 int
lame_set_analysis(lame_global_flags * gfp,int analysis)154 lame_set_analysis( lame_global_flags* gfp,
155 int analysis )
156 {
157 /* default = 0 */
158
159 /* enforce disable/enable meaning, if we need more than two values
160 we need to switch to an enum to have an apropriate representation
161 of the possible meanings of the value */
162 if ( 0 > analysis || 1 < analysis )
163 return -1;
164
165 gfp->analysis = analysis;
166
167 return 0;
168 }
169
170 int
lame_get_analysis(const lame_global_flags * gfp)171 lame_get_analysis( const lame_global_flags* gfp )
172 {
173 assert( 0 <= gfp->analysis && 1 >= gfp->analysis );
174
175 return gfp->analysis;
176 }
177
178
179 /* write a Xing VBR header frame */
180 int
lame_set_bWriteVbrTag(lame_global_flags * gfp,int bWriteVbrTag)181 lame_set_bWriteVbrTag( lame_global_flags* gfp,
182 int bWriteVbrTag )
183 {
184 /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
185
186 /* enforce disable/enable meaning, if we need more than two values
187 we need to switch to an enum to have an apropriate representation
188 of the possible meanings of the value */
189 if ( 0 > bWriteVbrTag || 1 < bWriteVbrTag )
190 return -1;
191
192 gfp->bWriteVbrTag = bWriteVbrTag;
193
194 return 0;
195 }
196
197 int
lame_get_bWriteVbrTag(const lame_global_flags * gfp)198 lame_get_bWriteVbrTag( const lame_global_flags* gfp )
199 {
200 assert( 0 <= gfp->bWriteVbrTag && 1 >= gfp->bWriteVbrTag );
201
202 return gfp->bWriteVbrTag;
203 }
204
205
206 /* disable writing a wave header with *decoding* */
207 int
lame_set_disable_waveheader(lame_global_flags * gfp,int disable_waveheader)208 lame_set_disable_waveheader( lame_global_flags* gfp,
209 int disable_waveheader )
210 {
211 /* default = 0 (disabled) */
212
213 /* enforce disable/enable meaning, if we need more than two values
214 we need to switch to an enum to have an apropriate representation
215 of the possible meanings of the value */
216 if ( 0 > disable_waveheader || 1 < disable_waveheader )
217 return -1;
218
219 gfp->disable_waveheader = disable_waveheader;
220
221 return 0;
222 }
223
224 int
lame_get_disable_waveheader(const lame_global_flags * gfp)225 lame_get_disable_waveheader( const lame_global_flags* gfp )
226 {
227 assert( 0 <= gfp->disable_waveheader && 1 >= gfp->disable_waveheader );
228
229 return gfp->disable_waveheader;
230 }
231
232
233 /* decode only, use lame/mpglib to convert mp3/ogg to wav */
234 int
lame_set_decode_only(lame_global_flags * gfp,int decode_only)235 lame_set_decode_only( lame_global_flags* gfp,
236 int decode_only )
237 {
238 /* default = 0 (disabled) */
239
240 /* enforce disable/enable meaning, if we need more than two values
241 we need to switch to an enum to have an apropriate representation
242 of the possible meanings of the value */
243 if ( 0 > decode_only || 1 < decode_only )
244 return -1;
245
246 gfp->decode_only = decode_only;
247
248 return 0;
249 }
250
251 int
lame_get_decode_only(const lame_global_flags * gfp)252 lame_get_decode_only( const lame_global_flags* gfp )
253 {
254 assert( 0 <= gfp->decode_only && 1 >= gfp->decode_only );
255
256 return gfp->decode_only;
257 }
258
259
260 /* encode a Vorbis .ogg file */
261 int
lame_set_ogg(lame_global_flags * gfp,int ogg)262 lame_set_ogg( lame_global_flags* gfp,
263 int ogg )
264 {
265 /* default = 0 (disabled) */
266
267 /* enforce disable/enable meaning, if we need more than two values
268 we need to switch to an enum to have an apropriate representation
269 of the possible meanings of the value */
270 if ( 0 > ogg || 1 < ogg )
271 return -1;
272
273 gfp->ogg = ogg;
274
275 return 0;
276 }
277
278 int
lame_get_ogg(const lame_global_flags * gfp)279 lame_get_ogg( const lame_global_flags* gfp )
280 {
281 assert( 0 <= gfp->ogg && 1 >= gfp->ogg );
282
283 return gfp->ogg;
284 }
285
286
287 /*
288 * Internal algorithm selection.
289 * True quality is determined by the bitrate but this variable will effect
290 * quality by selecting expensive or cheap algorithms.
291 * quality=0..9. 0=best (very slow). 9=worst.
292 * recommended: 2 near-best quality, not too slow
293 * 5 good quality, fast
294 * 7 ok quality, really fast
295 */
296 int
lame_set_quality(lame_global_flags * gfp,int quality)297 lame_set_quality( lame_global_flags* gfp,
298 int quality )
299 {
300 gfp->quality = quality;
301
302 return 0;
303 }
304
305 int
lame_get_quality(const lame_global_flags * gfp)306 lame_get_quality( const lame_global_flags* gfp )
307 {
308 return gfp->quality;
309 }
310
311
312 /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
313 int
lame_set_mode(lame_global_flags * gfp,MPEG_mode mode)314 lame_set_mode( lame_global_flags* gfp,
315 MPEG_mode mode )
316 {
317 /* default: lame chooses based on compression ratio and input channels */
318
319 if( 0 > mode || MAX_INDICATOR <= mode )
320 return -1; /* Unknown MPEG mode! */
321
322 gfp->mode = mode;
323
324 return 0;
325 }
326
327 MPEG_mode
lame_get_mode(const lame_global_flags * gfp)328 lame_get_mode( const lame_global_flags* gfp )
329 {
330 assert( 0 <= gfp->mode && MAX_INDICATOR > gfp->mode );
331
332 return gfp->mode;
333 }
334
335
336 /* Us a M/S mode with a switching threshold based on compression ratio */
337 int
lame_set_mode_automs(lame_global_flags * gfp,int mode_automs)338 lame_set_mode_automs( lame_global_flags* gfp,
339 int mode_automs )
340 {
341 /* default = 0 (disabled) */
342
343 /* enforce disable/enable meaning, if we need more than two values
344 we need to switch to an enum to have an apropriate representation
345 of the possible meanings of the value */
346 if ( 0 > mode_automs || 1 < mode_automs )
347 return -1;
348
349 gfp->mode_automs = mode_automs;
350
351 return 0;
352 }
353
354 int
lame_get_mode_automs(const lame_global_flags * gfp)355 lame_get_mode_automs( const lame_global_flags* gfp )
356 {
357 assert( 0 <= gfp->mode_automs && 1 >= gfp->mode_automs );
358
359 return gfp->mode_automs;
360 }
361
362
363 // force_ms. Force M/S for all frames. For testing only.
364 // default = 0 (disabled)
365 int
366 lame_set_force_ms( lame_global_flags* gfp,
367 int force_ms );
368 int
369 lame_get_force_ms( const lame_global_flags* gfp );
370
371
372 // use free_format? default = 0 (disabled)
373 int
374 lame_set_free_format( lame_global_flags* gfp,
375 int free_format );
376 int
377 lame_get_free_format( const lame_global_flags* gfp );
378
379
380 /* message handlers */
381 int
lame_set_errorf(lame_global_flags * gfp,void (* func)(const char *,va_list))382 lame_set_errorf( lame_global_flags* gfp,
383 void (*func)( const char*, va_list ) )
384 {
385 gfp->report.errorf = func;
386
387 return 0;
388 }
389
390 int
lame_set_debugf(lame_global_flags * gfp,void (* func)(const char *,va_list))391 lame_set_debugf( lame_global_flags* gfp,
392 void (*func)( const char*, va_list ) )
393 {
394 gfp->report.debugf = func;
395
396 return 0;
397 }
398
399 int
lame_set_msgf(lame_global_flags * gfp,void (* func)(const char *,va_list))400 lame_set_msgf( lame_global_flags* gfp,
401 void (*func)( const char *, va_list ) )
402 {
403 gfp->report.msgf = func;
404
405 return 0;
406 }
407
408
409 /* set one of brate compression ratio. default is compression ratio of 11. */
410 int
411 lame_set_brate( lame_global_flags* gfp,
412 int brate );
413 int
414 lame_get_brate( const lame_global_flags* gfp );
415 int
416 lame_set_compression_ratio( lame_global_flags* gfp,
417 float compression_ratio );
418 float
419 lame_get_compression_ratio( const lame_global_flags* gfp );
420
421
422
423
424 /*
425 * frame parameters
426 */
427
428 // mark as copyright. default=0
429 int
430 lame_set_copyright( lame_global_flags* gfp,
431 int copyright );
432 int
433 lame_get_copyright( const lame_global_flags* gfp );
434
435
436 // mark as original. default=1
437 int
438 lame_set_original( lame_global_flags* gfp,
439 int original );
440 int
441 lame_get_original( const lame_global_flags* gfp );
442
443
444 // error_protection. Use 2 bytes from each fraome for CRC checksum. default=0
445 int
446 lame_set_error_protection( lame_global_flags* gfp,
447 int error_protection );
448 int
449 lame_get_error_protection( const lame_global_flags* gfp );
450
451
452 // padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default)
453 int
454 lame_set_padding_type( lame_global_flags* gfp,
455 int padding_type );
456 int
457 lame_get_padding_type( const lame_global_flags* gfp );
458
459
460 // MP3 'private extension' bit Meaningless
461 int
462 lame_set_extension( lame_global_flags* gfp,
463 int extension );
464 int
465 lame_get_extension( const lame_global_flags* gfp );
466
467
468 // enforce strict ISO compliance. default=0
469 int
470 lame_set_strict_ISO( lame_global_flags* gfp,
471 int strict_ISO );
472 int
473 lame_get_strict_ISO( const lame_global_flags* gfp );
474
475
476
477
478 /********************************************************************
479 * quantization/noise shaping
480 ***********************************************************************/
481
482 // disable the bit reservoir. For testing only. default=0
483 int
484 lame_set_disable_reservoir( lame_global_flags* gfp,
485 int disable_reservoir );
486 int
487 lame_get_disable_reservoir( const lame_global_flags* gfp );
488
489
490 // select a different "best quantization" function. default=0
491 int
492 lame_set_experimentalX( lame_global_flags* gfp,
493 int experimentalX );
494 int
495 lame_get_experimentalX( const lame_global_flags* gfp );
496
497
498 // another experimental option. for testing only
499 int
500 lame_set_experimentalY( lame_global_flags* gfp,
501 int experimentalY );
502 int
503 lame_get_experimentalY( const lame_global_flags* gfp );
504
505
506 // another experimental option. for testing only
507 int
508 lame_set_experimentalZ( lame_global_flags* gfp,
509 int experimentalZ );
510 int
511 lame_get_experimentalZ( const lame_global_flags* gfp );
512
513
514 // Naoki's psycho acoustic model. default=0
515 int
516 lame_set_exp_nspsytune( lame_global_flags* gfp,
517 int exp_nspsytune );
518 int
519 lame_get_exp_nspsytune( const lame_global_flags* gfp );
520
521
522
523
524 /********************************************************************
525 * VBR control
526 ***********************************************************************/
527
528 // Types of VBR. default = vbr_off = CBR
529 int
530 lame_set_VBR( lame_global_flags* gfp,
531 vbr_mode VBR );
532 vbr_mode
533 lame_get_exp_VBR( const lame_global_flags* gfp );
534
535
536 // VBR quality level. 0=highest 9=lowest
537 int
538 lame_set_VBR_q( lame_global_flags* gfp,
539 int VBR_q );
540 int
541 lame_get_VBR_q( const lame_global_flags* gfp );
542
543
544 // Ignored except for VBR=vbr_abr (ABR mode)
545 int
546 lame_set_VBR_mean_bitrate_kbps( lame_global_flags* gfp,
547 int VBR_mean_bitrate_kbps );
548 int
549 lame_get_VBR_mean_bitrate_kbps( const lame_global_flags* gfp );
550
551 int
552 lame_set_VBR_min_bitrate_kbps( lame_global_flags* gfp,
553 int VBR_min_bitrate_kbps );
554 int
555 lame_get_VBR_min_bitrate_kbps( const lame_global_flags* gfp );
556
557 int
558 lame_set_VBR_max_bitrate_kbps( lame_global_flags* gfp,
559 int VBR_max_bitrate_kbps );
560 int
561 lame_get_VBR_max_bitrate_kbps( const lame_global_flags* gfp );
562
563
564 // 1=stricetly enforce VBR_min_bitrate. Normally it will be violated for
565 // analog silence
566 int
567 lame_set_VBR_hard_min( lame_global_flags* gfp,
568 int VBR_hard_min );
569 int
570 lame_get_VBR_hard_min( const lame_global_flags* gfp );
571
572
573 /********************************************************************
574 * Filtering control
575 ***********************************************************************/
576
577 // freq in Hz to apply lowpass. Default = 0 = lame chooses. -1 = disabled
578 int
579 lame_set_lowpassfreq( lame_global_flags* gfp,
580 int lowpassfreq );
581 int
582 lame_get_lowpassfreq( const lame_global_flags* gfp );
583
584
585 // width of transition band, in Hz. Default = one polyphase filter band
586 int
587 lame_set_lowpasswidth( lame_global_flags* gfp,
588 int lowpasswidth );
589 int
590 lame_get_lowpasswidth( const lame_global_flags* gfp );
591
592
593 // freq in Hz to apply highpass. Default = 0 = lame chooses. -1 = disabled
594 int
595 lame_set_highpassfreq( lame_global_flags* gfp,
596 int highpassfreq );
597 int
598 lame_get_highpassfreq( const lame_global_flags* gfp );
599
600
601 // width of transition band, in Hz. Default = one polyphase filter band
602 int
603 lame_set_highpasswidth( lame_global_flags* gfp,
604 int highpasswidth );
605 int
606 lame_get_highpasswidth( const lame_global_flags* gfp );
607
608
609
610
611 /*
612 * psycho acoustics and other arguments which you should not change
613 * unless you know what you are doing
614 */
615
616 // only use ATH for masking
617 int
618 lame_set_ATHonly( lame_global_flags* gfp,
619 int ATHonly );
620 int
621 lame_get_ATHonly( const lame_global_flags* gfp );
622
623
624 // only use ATH for short blocks
625 int
626 lame_set_ATHshort( lame_global_flags* gfp,
627 int ATHshort );
628 int
629 lame_get_ATHshort( const lame_global_flags* gfp );
630
631
632 // disable ATH
633 int
634 lame_set_noATH( lame_global_flags* gfp,
635 int noATH );
636 int
637 lame_get_noATH( const lame_global_flags* gfp );
638
639
640 // select ATH formula
641 int
642 lame_set_ATHtype( lame_global_flags* gfp,
643 int ATHtype );
644 int
645 lame_get_ATHtype( const lame_global_flags* gfp );
646
647
648 // lower ATH by this many db
649 int
650 lame_set_ATHlower( lame_global_flags* gfp,
651 float ATHlower );
652 float
653 lame_get_ATHlower( const lame_global_flags* gfp );
654
655
656 // predictability limit (ISO tonality formula)
657 int
658 lame_set_cwlimit( lame_global_flags* gfp,
659 int cwlimit );
660 int
661 lame_get_cwlimit( const lame_global_flags* gfp );
662
663
664 // allow blocktypes to differ between channels?
665 // default: 0 for jstereo, 1 for stereo
666 int
667 lame_set_allow_diff_short( lame_global_flags* gfp,
668 int allow_diff_short );
669 int
670 lame_get_allow_diff_short( const lame_global_flags* gfp );
671
672
673 // use temporal masking effect (default = 1)
674 int
675 lame_set_useTemporal( lame_global_flags* gfp,
676 int useTemporal );
677 int
678 lame_get_useTemporal( const lame_global_flags* gfp );
679
680
681 // disable short blocks
682 int
683 lame_set_no_short_blocks( lame_global_flags* gfp,
684 int no_short_blocks );
685 int
686 lame_get_no_short_blocks( const lame_global_flags* gfp );
687
688
689 /* Input PCM is emphased PCM (for instance from one of the rarely
690 emphased CDs), it is STRONGLY not recommended to use this, because
691 psycho does not take it into account, and last but not least many decoders
692 ignore these bits */
693 int
694 lame_set_emphasis( lame_global_flags* gfp,
695 int emphasis );
696 int
697 lame_get_emphasis( const lame_global_flags* gfp );
698
699
700
701
702 /***************************************************************/
703 /* internal variables, cannot be set... */
704 /* provided because they may be of use to calling application */
705 /***************************************************************/
706
707 // version 0=MPEG-2 1=MPEG-1 (2=MPEG-2.5)
708 int
709 lame_get_version( const lame_global_flags* gfp );
710
711
712 // encoder delay
713 int
714 lame_get_encoder_delay( const lame_global_flags* gfp );
715
716
717 // size of MPEG frame
718 int
719 lame_get_framesize( const lame_global_flags* gfp );
720
721
722 // number of frames encoded so far
723 int
724 lame_get_frameNum( const lame_global_flags* gfp );
725
726
727 // lame's estimate of the total number of frames to be encoded
728 // only valid if calling program set num_samples
729 int
730 lame_get_totalframes( const lame_global_flags* gfp );
731