123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346 |
- /* -*- mode: C; mode: fold -*- */
- /*
- * set/get functions for lame_global_flags
- *
- * Copyright (c) 2001-2005 Alexander Leidinger
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
- /* $Id: set_get.c,v 1.104 2017/09/06 15:07:30 robert Exp $ */
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include "lame.h"
- #include "machine.h"
- #include "encoder.h"
- #include "util.h"
- #include "bitstream.h" /* because of compute_flushbits */
- #include "set_get.h"
- #include "lame_global_flags.h"
- /*
- * input stream description
- */
- /* number of samples */
- /* it's unlikely for this function to return an error */
- int
- lame_set_num_samples(lame_global_flags * gfp, unsigned long num_samples)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 2^32-1 */
- gfp->num_samples = num_samples;
- return 0;
- }
- return -1;
- }
- unsigned long
- lame_get_num_samples(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->num_samples;
- }
- return 0;
- }
- /* input samplerate */
- int
- lame_set_in_samplerate(lame_global_flags * gfp, int in_samplerate)
- {
- if (is_lame_global_flags_valid(gfp)) {
- if (in_samplerate < 1)
- return -1;
- /* input sample rate in Hz, default = 44100 Hz */
- gfp->samplerate_in = in_samplerate;
- return 0;
- }
- return -1;
- }
- int
- lame_get_in_samplerate(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->samplerate_in;
- }
- return 0;
- }
- /* number of channels in input stream */
- int
- lame_set_num_channels(lame_global_flags * gfp, int num_channels)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 2 */
- if (2 < num_channels || 0 >= num_channels) {
- return -1; /* we don't support more than 2 channels */
- }
- gfp->num_channels = num_channels;
- return 0;
- }
- return -1;
- }
- int
- lame_get_num_channels(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->num_channels;
- }
- return 0;
- }
- /* scale the input by this amount before encoding (not used for decoding) */
- int
- lame_set_scale(lame_global_flags * gfp, float scale)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 */
- gfp->scale = scale;
- return 0;
- }
- return -1;
- }
- float
- lame_get_scale(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->scale;
- }
- return 0;
- }
- /* scale the channel 0 (left) input by this amount before
- encoding (not used for decoding) */
- int
- lame_set_scale_left(lame_global_flags * gfp, float scale)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 */
- gfp->scale_left = scale;
- return 0;
- }
- return -1;
- }
- float
- lame_get_scale_left(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->scale_left;
- }
- return 0;
- }
- /* scale the channel 1 (right) input by this amount before
- encoding (not used for decoding) */
- int
- lame_set_scale_right(lame_global_flags * gfp, float scale)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 */
- gfp->scale_right = scale;
- return 0;
- }
- return -1;
- }
- float
- lame_get_scale_right(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->scale_right;
- }
- return 0;
- }
- /* output sample rate in Hz */
- int
- lame_set_out_samplerate(lame_global_flags * gfp, int out_samplerate)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /*
- * default = 0: LAME picks best value based on the amount
- * of compression
- * MPEG only allows:
- * MPEG1 32, 44.1, 48khz
- * MPEG2 16, 22.05, 24
- * MPEG2.5 8, 11.025, 12
- *
- * (not used by decoding routines)
- */
- if (out_samplerate != 0) {
- int v=0;
- if (SmpFrqIndex(out_samplerate, &v) < 0)
- return -1;
- }
- gfp->samplerate_out = out_samplerate;
- return 0;
- }
- return -1;
- }
- int
- lame_get_out_samplerate(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->samplerate_out;
- }
- return 0;
- }
- /*
- * general control parameters
- */
- /* collect data for an MP3 frame analzyer */
- int
- lame_set_analysis(lame_global_flags * gfp, int analysis)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > analysis || 1 < analysis)
- return -1;
- gfp->analysis = analysis;
- return 0;
- }
- return -1;
- }
- int
- lame_get_analysis(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->analysis && 1 >= gfp->analysis);
- return gfp->analysis;
- }
- return 0;
- }
- /* write a Xing VBR header frame */
- int
- lame_set_bWriteVbrTag(lame_global_flags * gfp, int bWriteVbrTag)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 (on) for VBR/ABR modes, 0 (off) for CBR mode */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > bWriteVbrTag || 1 < bWriteVbrTag)
- return -1;
- gfp->write_lame_tag = bWriteVbrTag;
- return 0;
- }
- return -1;
- }
- int
- lame_get_bWriteVbrTag(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->write_lame_tag && 1 >= gfp->write_lame_tag);
- return gfp->write_lame_tag;
- }
- return 0;
- }
- /* decode only, use lame/mpglib to convert mp3 to wav */
- int
- lame_set_decode_only(lame_global_flags * gfp, int decode_only)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > decode_only || 1 < decode_only)
- return -1;
- gfp->decode_only = decode_only;
- return 0;
- }
- return -1;
- }
- int
- lame_get_decode_only(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->decode_only && 1 >= gfp->decode_only);
- return gfp->decode_only;
- }
- return 0;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- /* 1=encode a Vorbis .ogg file. default=0 */
- /* DEPRECATED */
- int CDECL lame_set_ogg(lame_global_flags *, int);
- int CDECL lame_get_ogg(const lame_global_flags *);
- #else
- #endif
- /* encode a Vorbis .ogg file */
- /* DEPRECATED */
- int
- lame_set_ogg(lame_global_flags * gfp, int ogg)
- {
- (void) gfp;
- (void) ogg;
- return -1;
- }
- int
- lame_get_ogg(const lame_global_flags * gfp)
- {
- (void) gfp;
- return 0;
- }
- /*
- * Internal algorithm selection.
- * True quality is determined by the bitrate but this variable will effect
- * quality by selecting expensive or cheap algorithms.
- * quality=0..9. 0=best (very slow). 9=worst.
- * recommended: 3 near-best quality, not too slow
- * 5 good quality, fast
- * 7 ok quality, really fast
- */
- int
- lame_set_quality(lame_global_flags * gfp, int quality)
- {
- if (is_lame_global_flags_valid(gfp)) {
- if (quality < 0) {
- gfp->quality = 0;
- }
- else if (quality > 9) {
- gfp->quality = 9;
- }
- else {
- gfp->quality = quality;
- }
- return 0;
- }
- return -1;
- }
- int
- lame_get_quality(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->quality;
- }
- return 0;
- }
- /* mode = STEREO, JOINT_STEREO, DUAL_CHANNEL (not supported), MONO */
- int
- lame_set_mode(lame_global_flags * gfp, MPEG_mode mode)
- {
- if (is_lame_global_flags_valid(gfp)) {
- int mpg_mode = mode;
- /* default: lame chooses based on compression ratio and input channels */
- if (mpg_mode < 0 || MAX_INDICATOR <= mpg_mode)
- return -1; /* Unknown MPEG mode! */
- gfp->mode = mode;
- return 0;
- }
- return -1;
- }
- MPEG_mode
- lame_get_mode(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(gfp->mode < MAX_INDICATOR);
- return gfp->mode;
- }
- return NOT_SET;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- /*
- mode_automs. Use a M/S mode with a switching threshold based on
- compression ratio
- DEPRECATED
- */
- int CDECL lame_set_mode_automs(lame_global_flags *, int);
- int CDECL lame_get_mode_automs(const lame_global_flags *);
- #else
- #endif
- /* Us a M/S mode with a switching threshold based on compression ratio */
- /* DEPRECATED */
- int
- lame_set_mode_automs(lame_global_flags * gfp, int mode_automs)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > mode_automs || 1 < mode_automs)
- return -1;
- lame_set_mode(gfp, JOINT_STEREO);
- return 0;
- }
- return -1;
- }
- int
- lame_get_mode_automs(const lame_global_flags * gfp)
- {
- (void) gfp;
- return 1;
- }
- /*
- * Force M/S for all frames. For testing only.
- * Requires mode = 1.
- */
- int
- lame_set_force_ms(lame_global_flags * gfp, int force_ms)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > force_ms || 1 < force_ms)
- return -1;
- gfp->force_ms = force_ms;
- return 0;
- }
- return -1;
- }
- int
- lame_get_force_ms(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->force_ms && 1 >= gfp->force_ms);
- return gfp->force_ms;
- }
- return 0;
- }
- /* Use free_format. */
- int
- lame_set_free_format(lame_global_flags * gfp, int free_format)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > free_format || 1 < free_format)
- return -1;
- gfp->free_format = free_format;
- return 0;
- }
- return -1;
- }
- int
- lame_get_free_format(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->free_format && 1 >= gfp->free_format);
- return gfp->free_format;
- }
- return 0;
- }
- /* Perform ReplayGain analysis */
- int
- lame_set_findReplayGain(lame_global_flags * gfp, int findReplayGain)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > findReplayGain || 1 < findReplayGain)
- return -1;
- gfp->findReplayGain = findReplayGain;
- return 0;
- }
- return -1;
- }
- int
- lame_get_findReplayGain(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->findReplayGain && 1 >= gfp->findReplayGain);
- return gfp->findReplayGain;
- }
- return 0;
- }
- /* Decode on the fly. Find the peak sample. If ReplayGain analysis is
- enabled then perform it on the decoded data. */
- int
- lame_set_decode_on_the_fly(lame_global_flags * gfp, int decode_on_the_fly)
- {
- if (is_lame_global_flags_valid(gfp)) {
- #ifndef DECODE_ON_THE_FLY
- return -1;
- #else
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > decode_on_the_fly || 1 < decode_on_the_fly)
- return -1;
- gfp->decode_on_the_fly = decode_on_the_fly;
- return 0;
- #endif
- }
- return -1;
- }
- int
- lame_get_decode_on_the_fly(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->decode_on_the_fly && 1 >= gfp->decode_on_the_fly);
- return gfp->decode_on_the_fly;
- }
- return 0;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- /* DEPRECATED: now does the same as lame_set_findReplayGain()
- default = 0 (disabled) */
- int CDECL lame_set_ReplayGain_input(lame_global_flags *, int);
- int CDECL lame_get_ReplayGain_input(const lame_global_flags *);
- /* DEPRECATED: now does the same as
- lame_set_decode_on_the_fly() && lame_set_findReplayGain()
- default = 0 (disabled) */
- int CDECL lame_set_ReplayGain_decode(lame_global_flags *, int);
- int CDECL lame_get_ReplayGain_decode(const lame_global_flags *);
- /* DEPRECATED: now does the same as lame_set_decode_on_the_fly()
- default = 0 (disabled) */
- int CDECL lame_set_findPeakSample(lame_global_flags *, int);
- int CDECL lame_get_findPeakSample(const lame_global_flags *);
- #else
- #endif
- /* DEPRECATED. same as lame_set_decode_on_the_fly() */
- int
- lame_set_findPeakSample(lame_global_flags * gfp, int arg)
- {
- return lame_set_decode_on_the_fly(gfp, arg);
- }
- int
- lame_get_findPeakSample(const lame_global_flags * gfp)
- {
- return lame_get_decode_on_the_fly(gfp);
- }
- /* DEPRECATED. same as lame_set_findReplayGain() */
- int
- lame_set_ReplayGain_input(lame_global_flags * gfp, int arg)
- {
- return lame_set_findReplayGain(gfp, arg);
- }
- int
- lame_get_ReplayGain_input(const lame_global_flags * gfp)
- {
- return lame_get_findReplayGain(gfp);
- }
- /* DEPRECATED. same as lame_set_decode_on_the_fly() &&
- lame_set_findReplayGain() */
- int
- lame_set_ReplayGain_decode(lame_global_flags * gfp, int arg)
- {
- if (lame_set_decode_on_the_fly(gfp, arg) < 0 || lame_set_findReplayGain(gfp, arg) < 0)
- return -1;
- else
- return 0;
- }
- int
- lame_get_ReplayGain_decode(const lame_global_flags * gfp)
- {
- if (lame_get_decode_on_the_fly(gfp) > 0 && lame_get_findReplayGain(gfp) > 0)
- return 1;
- else
- return 0;
- }
- /* set and get some gapless encoding flags */
- int
- lame_set_nogap_total(lame_global_flags * gfp, int the_nogap_total)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->nogap_total = the_nogap_total;
- return 0;
- }
- return -1;
- }
- int
- lame_get_nogap_total(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->nogap_total;
- }
- return 0;
- }
- int
- lame_set_nogap_currentindex(lame_global_flags * gfp, int the_nogap_index)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->nogap_current = the_nogap_index;
- return 0;
- }
- return -1;
- }
- int
- lame_get_nogap_currentindex(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->nogap_current;
- }
- return 0;
- }
- /* message handlers */
- int
- lame_set_errorf(lame_global_flags * gfp, void (*func) (const char *, va_list))
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->report.errorf = func;
- return 0;
- }
- return -1;
- }
- int
- lame_set_debugf(lame_global_flags * gfp, void (*func) (const char *, va_list))
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->report.debugf = func;
- return 0;
- }
- return -1;
- }
- int
- lame_set_msgf(lame_global_flags * gfp, void (*func) (const char *, va_list))
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->report.msgf = func;
- return 0;
- }
- return -1;
- }
- /*
- * Set one of
- * - brate
- * - compression ratio.
- *
- * Default is compression ratio of 11.
- */
- int
- lame_set_brate(lame_global_flags * gfp, int brate)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->brate = brate;
- if (brate > 320) {
- gfp->disable_reservoir = 1;
- }
- return 0;
- }
- return -1;
- }
- int
- lame_get_brate(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->brate;
- }
- return 0;
- }
- int
- lame_set_compression_ratio(lame_global_flags * gfp, float compression_ratio)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->compression_ratio = compression_ratio;
- return 0;
- }
- return -1;
- }
- float
- lame_get_compression_ratio(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->compression_ratio;
- }
- return 0;
- }
- /*
- * frame parameters
- */
- /* Mark as copyright protected. */
- int
- lame_set_copyright(lame_global_flags * gfp, int copyright)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > copyright || 1 < copyright)
- return -1;
- gfp->copyright = copyright;
- return 0;
- }
- return -1;
- }
- int
- lame_get_copyright(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->copyright && 1 >= gfp->copyright);
- return gfp->copyright;
- }
- return 0;
- }
- /* Mark as original. */
- int
- lame_set_original(lame_global_flags * gfp, int original)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 (enabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > original || 1 < original)
- return -1;
- gfp->original = original;
- return 0;
- }
- return -1;
- }
- int
- lame_get_original(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->original && 1 >= gfp->original);
- return gfp->original;
- }
- return 0;
- }
- /*
- * error_protection.
- * Use 2 bytes from each frame for CRC checksum.
- */
- int
- lame_set_error_protection(lame_global_flags * gfp, int error_protection)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > error_protection || 1 < error_protection)
- return -1;
- gfp->error_protection = error_protection;
- return 0;
- }
- return -1;
- }
- int
- lame_get_error_protection(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->error_protection && 1 >= gfp->error_protection);
- return gfp->error_protection;
- }
- return 0;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- /* padding_type. 0=pad no frames 1=pad all frames 2=adjust padding(default) */
- int CDECL lame_set_padding_type(lame_global_flags *, Padding_type);
- Padding_type CDECL lame_get_padding_type(const lame_global_flags *);
- #else
- #endif
- /*
- * padding_type.
- * PAD_NO = pad no frames
- * PAD_ALL = pad all frames
- * PAD_ADJUST = adjust padding
- */
- int
- lame_set_padding_type(lame_global_flags * gfp, Padding_type padding_type)
- {
- (void) gfp;
- (void) padding_type;
- return 0;
- }
- Padding_type
- lame_get_padding_type(const lame_global_flags * gfp)
- {
- (void) gfp;
- return PAD_ADJUST;
- }
- /* MP3 'private extension' bit. Meaningless. */
- int
- lame_set_extension(lame_global_flags * gfp, int extension)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > extension || 1 < extension)
- return -1;
- gfp->extension = extension;
- return 0;
- }
- return -1;
- }
- int
- lame_get_extension(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->extension && 1 >= gfp->extension);
- return gfp->extension;
- }
- return 0;
- }
- /* Enforce strict ISO compliance. */
- int
- lame_set_strict_ISO(lame_global_flags * gfp, int val)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (val < MDB_DEFAULT || MDB_MAXIMUM < val)
- return -1;
- gfp->strict_ISO = val;
- return 0;
- }
- return -1;
- }
- int
- lame_get_strict_ISO(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->strict_ISO;
- }
- return 0;
- }
- /********************************************************************
- * quantization/noise shaping
- ***********************************************************************/
- /* Disable the bit reservoir. For testing only. */
- int
- lame_set_disable_reservoir(lame_global_flags * gfp, int disable_reservoir)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > disable_reservoir || 1 < disable_reservoir)
- return -1;
- gfp->disable_reservoir = disable_reservoir;
- return 0;
- }
- return -1;
- }
- int
- lame_get_disable_reservoir(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->disable_reservoir && 1 >= gfp->disable_reservoir);
- return gfp->disable_reservoir;
- }
- return 0;
- }
- int
- lame_set_experimentalX(lame_global_flags * gfp, int experimentalX)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_set_quant_comp(gfp, experimentalX);
- lame_set_quant_comp_short(gfp, experimentalX);
- return 0;
- }
- return -1;
- }
- int
- lame_get_experimentalX(const lame_global_flags * gfp)
- {
- return lame_get_quant_comp(gfp);
- }
- /* Select a different "best quantization" function. default = 0 */
- int
- lame_set_quant_comp(lame_global_flags * gfp, int quant_type)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->quant_comp = quant_type;
- return 0;
- }
- return -1;
- }
- int
- lame_get_quant_comp(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->quant_comp;
- }
- return 0;
- }
- /* Select a different "best quantization" function. default = 0 */
- int
- lame_set_quant_comp_short(lame_global_flags * gfp, int quant_type)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->quant_comp_short = quant_type;
- return 0;
- }
- return -1;
- }
- int
- lame_get_quant_comp_short(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->quant_comp_short;
- }
- return 0;
- }
- /* Another experimental option. For testing only. */
- int
- lame_set_experimentalY(lame_global_flags * gfp, int experimentalY)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->experimentalY = experimentalY;
- return 0;
- }
- return -1;
- }
- int
- lame_get_experimentalY(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->experimentalY;
- }
- return 0;
- }
- int
- lame_set_experimentalZ(lame_global_flags * gfp, int experimentalZ)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->experimentalZ = experimentalZ;
- return 0;
- }
- return -1;
- }
- int
- lame_get_experimentalZ(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->experimentalZ;
- }
- return 0;
- }
- /* Naoki's psycho acoustic model. */
- int
- lame_set_exp_nspsytune(lame_global_flags * gfp, int exp_nspsytune)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- gfp->exp_nspsytune = exp_nspsytune;
- return 0;
- }
- return -1;
- }
- int
- lame_get_exp_nspsytune(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->exp_nspsytune;
- }
- return 0;
- }
- /********************************************************************
- * VBR control
- ***********************************************************************/
- /* Types of VBR. default = vbr_off = CBR */
- int
- lame_set_VBR(lame_global_flags * gfp, vbr_mode VBR)
- {
- if (is_lame_global_flags_valid(gfp)) {
- int vbr_q = VBR;
- if (0 > vbr_q || vbr_max_indicator <= vbr_q)
- return -1; /* Unknown VBR mode! */
- gfp->VBR = VBR;
- return 0;
- }
- return -1;
- }
- vbr_mode
- lame_get_VBR(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(gfp->VBR < vbr_max_indicator);
- return gfp->VBR;
- }
- return vbr_off;
- }
- /*
- * VBR quality level.
- * 0 = highest
- * 9 = lowest
- */
- int
- lame_set_VBR_q(lame_global_flags * gfp, int VBR_q)
- {
- if (is_lame_global_flags_valid(gfp)) {
- int ret = 0;
- if (0 > VBR_q) {
- ret = -1; /* Unknown VBR quality level! */
- VBR_q = 0;
- }
- if (9 < VBR_q) {
- ret = -1;
- VBR_q = 9;
- }
- gfp->VBR_q = VBR_q;
- gfp->VBR_q_frac = 0;
- return ret;
- }
- return -1;
- }
- int
- lame_get_VBR_q(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->VBR_q && 10 > gfp->VBR_q);
- return gfp->VBR_q;
- }
- return 0;
- }
- int
- lame_set_VBR_quality(lame_global_flags * gfp, float VBR_q)
- {
- if (is_lame_global_flags_valid(gfp)) {
- int ret = 0;
- if (0 > VBR_q) {
- ret = -1; /* Unknown VBR quality level! */
- VBR_q = 0;
- }
- if (9.999 < VBR_q) {
- ret = -1;
- VBR_q = 9.999;
- }
- gfp->VBR_q = (int) VBR_q;
- gfp->VBR_q_frac = VBR_q - gfp->VBR_q;
- return ret;
- }
- return -1;
- }
- float
- lame_get_VBR_quality(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->VBR_q + gfp->VBR_q_frac;
- }
- return 0;
- }
- /* Ignored except for VBR = vbr_abr (ABR mode) */
- int
- lame_set_VBR_mean_bitrate_kbps(lame_global_flags * gfp, int VBR_mean_bitrate_kbps)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->VBR_mean_bitrate_kbps = VBR_mean_bitrate_kbps;
- return 0;
- }
- return -1;
- }
- int
- lame_get_VBR_mean_bitrate_kbps(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->VBR_mean_bitrate_kbps;
- }
- return 0;
- }
- int
- lame_set_VBR_min_bitrate_kbps(lame_global_flags * gfp, int VBR_min_bitrate_kbps)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->VBR_min_bitrate_kbps = VBR_min_bitrate_kbps;
- return 0;
- }
- return -1;
- }
- int
- lame_get_VBR_min_bitrate_kbps(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->VBR_min_bitrate_kbps;
- }
- return 0;
- }
- int
- lame_set_VBR_max_bitrate_kbps(lame_global_flags * gfp, int VBR_max_bitrate_kbps)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->VBR_max_bitrate_kbps = VBR_max_bitrate_kbps;
- return 0;
- }
- return -1;
- }
- int
- lame_get_VBR_max_bitrate_kbps(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->VBR_max_bitrate_kbps;
- }
- return 0;
- }
- /*
- * Strictly enforce VBR_min_bitrate.
- * Normally it will be violated for analog silence.
- */
- int
- lame_set_VBR_hard_min(lame_global_flags * gfp, int VBR_hard_min)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 (disabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > VBR_hard_min || 1 < VBR_hard_min)
- return -1;
- gfp->VBR_hard_min = VBR_hard_min;
- return 0;
- }
- return -1;
- }
- int
- lame_get_VBR_hard_min(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->VBR_hard_min && 1 >= gfp->VBR_hard_min);
- return gfp->VBR_hard_min;
- }
- return 0;
- }
- /********************************************************************
- * Filtering control
- ***********************************************************************/
- /*
- * Freqency in Hz to apply lowpass.
- * 0 = default = lame chooses
- * -1 = disabled
- */
- int
- lame_set_lowpassfreq(lame_global_flags * gfp, int lowpassfreq)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->lowpassfreq = lowpassfreq;
- return 0;
- }
- return -1;
- }
- int
- lame_get_lowpassfreq(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->lowpassfreq;
- }
- return 0;
- }
- /*
- * Width of transition band (in Hz).
- * default = one polyphase filter band
- */
- int
- lame_set_lowpasswidth(lame_global_flags * gfp, int lowpasswidth)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->lowpasswidth = lowpasswidth;
- return 0;
- }
- return -1;
- }
- int
- lame_get_lowpasswidth(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->lowpasswidth;
- }
- return 0;
- }
- /*
- * Frequency in Hz to apply highpass.
- * 0 = default = lame chooses
- * -1 = disabled
- */
- int
- lame_set_highpassfreq(lame_global_flags * gfp, int highpassfreq)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->highpassfreq = highpassfreq;
- return 0;
- }
- return -1;
- }
- int
- lame_get_highpassfreq(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->highpassfreq;
- }
- return 0;
- }
- /*
- * Width of transition band (in Hz).
- * default = one polyphase filter band
- */
- int
- lame_set_highpasswidth(lame_global_flags * gfp, int highpasswidth)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->highpasswidth = highpasswidth;
- return 0;
- }
- return -1;
- }
- int
- lame_get_highpasswidth(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->highpasswidth;
- }
- return 0;
- }
- /*
- * psycho acoustics and other arguments which you should not change
- * unless you know what you are doing
- */
- /* Adjust masking values. */
- int
- lame_set_maskingadjust(lame_global_flags * gfp, float adjust)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->maskingadjust = adjust;
- return 0;
- }
- return -1;
- }
- float
- lame_get_maskingadjust(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->maskingadjust;
- }
- return 0;
- }
- int
- lame_set_maskingadjust_short(lame_global_flags * gfp, float adjust)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->maskingadjust_short = adjust;
- return 0;
- }
- return -1;
- }
- float
- lame_get_maskingadjust_short(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->maskingadjust_short;
- }
- return 0;
- }
- /* Only use ATH for masking. */
- int
- lame_set_ATHonly(lame_global_flags * gfp, int ATHonly)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->ATHonly = ATHonly;
- return 0;
- }
- return -1;
- }
- int
- lame_get_ATHonly(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->ATHonly;
- }
- return 0;
- }
- /* Only use ATH for short blocks. */
- int
- lame_set_ATHshort(lame_global_flags * gfp, int ATHshort)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->ATHshort = ATHshort;
- return 0;
- }
- return -1;
- }
- int
- lame_get_ATHshort(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->ATHshort;
- }
- return 0;
- }
- /* Disable ATH. */
- int
- lame_set_noATH(lame_global_flags * gfp, int noATH)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->noATH = noATH;
- return 0;
- }
- return -1;
- }
- int
- lame_get_noATH(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->noATH;
- }
- return 0;
- }
- /* Select ATH formula. */
- int
- lame_set_ATHtype(lame_global_flags * gfp, int ATHtype)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* XXX: ATHtype should be converted to an enum. */
- gfp->ATHtype = ATHtype;
- return 0;
- }
- return -1;
- }
- int
- lame_get_ATHtype(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->ATHtype;
- }
- return 0;
- }
- /* Select ATH formula 4 shape. */
- int
- lame_set_ATHcurve(lame_global_flags * gfp, float ATHcurve)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->ATHcurve = ATHcurve;
- return 0;
- }
- return -1;
- }
- float
- lame_get_ATHcurve(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->ATHcurve;
- }
- return 0;
- }
- /* Lower ATH by this many db. */
- int
- lame_set_ATHlower(lame_global_flags * gfp, float ATHlower)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->ATH_lower_db = ATHlower;
- return 0;
- }
- return -1;
- }
- float
- lame_get_ATHlower(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->ATH_lower_db;
- }
- return 0;
- }
- /* Select ATH adaptive adjustment scheme. */
- int
- lame_set_athaa_type(lame_global_flags * gfp, int athaa_type)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->athaa_type = athaa_type;
- return 0;
- }
- return -1;
- }
- int
- lame_get_athaa_type(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->athaa_type;
- }
- return 0;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- int CDECL lame_set_athaa_loudapprox(lame_global_flags * gfp, int athaa_loudapprox);
- int CDECL lame_get_athaa_loudapprox(const lame_global_flags * gfp);
- #else
- #endif
- /* Select the loudness approximation used by the ATH adaptive auto-leveling. */
- int
- lame_set_athaa_loudapprox(lame_global_flags * gfp, int athaa_loudapprox)
- {
- (void) gfp;
- (void) athaa_loudapprox;
- return 0;
- }
- int
- lame_get_athaa_loudapprox(const lame_global_flags * gfp)
- {
- (void) gfp;
- /* obsolete, the type known under number 2 is the only survival */
- return 2;
- }
- /* Adjust (in dB) the point below which adaptive ATH level adjustment occurs. */
- int
- lame_set_athaa_sensitivity(lame_global_flags * gfp, float athaa_sensitivity)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->athaa_sensitivity = athaa_sensitivity;
- return 0;
- }
- return -1;
- }
- float
- lame_get_athaa_sensitivity(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->athaa_sensitivity;
- }
- return 0;
- }
- /* Predictability limit (ISO tonality formula) */
- int lame_set_cwlimit(lame_global_flags * gfp, int cwlimit);
- int lame_get_cwlimit(const lame_global_flags * gfp);
- int
- lame_set_cwlimit(lame_global_flags * gfp, int cwlimit)
- {
- (void) gfp;
- (void) cwlimit;
- return 0;
- }
- int
- lame_get_cwlimit(const lame_global_flags * gfp)
- {
- (void) gfp;
- return 0;
- }
- /*
- * Allow blocktypes to differ between channels.
- * default:
- * 0 for jstereo => block types coupled
- * 1 for stereo => block types may differ
- */
- int
- lame_set_allow_diff_short(lame_global_flags * gfp, int allow_diff_short)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->short_blocks = allow_diff_short ? short_block_allowed : short_block_coupled;
- return 0;
- }
- return -1;
- }
- int
- lame_get_allow_diff_short(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- if (gfp->short_blocks == short_block_allowed)
- return 1; /* short blocks allowed to differ */
- else
- return 0; /* not set, dispensed, forced or coupled */
- }
- return 0;
- }
- /* Use temporal masking effect */
- int
- lame_set_useTemporal(lame_global_flags * gfp, int useTemporal)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 1 (enabled) */
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 <= useTemporal && useTemporal <= 1) {
- gfp->useTemporal = useTemporal;
- return 0;
- }
- }
- return -1;
- }
- int
- lame_get_useTemporal(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->useTemporal && 1 >= gfp->useTemporal);
- return gfp->useTemporal;
- }
- return 0;
- }
- /* Use inter-channel masking effect */
- int
- lame_set_interChRatio(lame_global_flags * gfp, float ratio)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0.0 (no inter-channel maskin) */
- if (0 <= ratio && ratio <= 1.0) {
- gfp->interChRatio = ratio;
- return 0;
- }
- }
- return -1;
- }
- float
- lame_get_interChRatio(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert((0 <= gfp->interChRatio && gfp->interChRatio <= 1.0) || EQ(gfp->interChRatio, -1));
- return gfp->interChRatio;
- }
- return 0;
- }
- /* Use pseudo substep shaping method */
- int
- lame_set_substep(lame_global_flags * gfp, int method)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0.0 (no substep noise shaping) */
- if (0 <= method && method <= 7) {
- gfp->substep_shaping = method;
- return 0;
- }
- }
- return -1;
- }
- int
- lame_get_substep(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->substep_shaping && gfp->substep_shaping <= 7);
- return gfp->substep_shaping;
- }
- return 0;
- }
- /* scalefactors scale */
- int
- lame_set_sfscale(lame_global_flags * gfp, int val)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->noise_shaping = (val != 0) ? 2 : 1;
- return 0;
- }
- return -1;
- }
- int
- lame_get_sfscale(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return (gfp->noise_shaping == 2) ? 1 : 0;
- }
- return 0;
- }
- /* subblock gain */
- int
- lame_set_subblock_gain(lame_global_flags * gfp, int sbgain)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->subblock_gain = sbgain;
- return 0;
- }
- return -1;
- }
- int
- lame_get_subblock_gain(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->subblock_gain;
- }
- return 0;
- }
- /* Disable short blocks. */
- int
- lame_set_no_short_blocks(lame_global_flags * gfp, int no_short_blocks)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 <= no_short_blocks && no_short_blocks <= 1) {
- gfp->short_blocks = no_short_blocks ? short_block_dispensed : short_block_allowed;
- return 0;
- }
- }
- return -1;
- }
- int
- lame_get_no_short_blocks(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- switch (gfp->short_blocks) {
- default:
- case short_block_not_set:
- return -1;
- case short_block_dispensed:
- return 1;
- case short_block_allowed:
- case short_block_coupled:
- case short_block_forced:
- return 0;
- }
- }
- return -1;
- }
- /* Force short blocks. */
- int
- lame_set_force_short_blocks(lame_global_flags * gfp, int short_blocks)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* enforce disable/enable meaning, if we need more than two values
- we need to switch to an enum to have an apropriate representation
- of the possible meanings of the value */
- if (0 > short_blocks || 1 < short_blocks)
- return -1;
- if (short_blocks == 1)
- gfp->short_blocks = short_block_forced;
- else if (gfp->short_blocks == short_block_forced)
- gfp->short_blocks = short_block_allowed;
- return 0;
- }
- return -1;
- }
- int
- lame_get_force_short_blocks(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- switch (gfp->short_blocks) {
- default:
- case short_block_not_set:
- return -1;
- case short_block_dispensed:
- case short_block_allowed:
- case short_block_coupled:
- return 0;
- case short_block_forced:
- return 1;
- }
- }
- return -1;
- }
- int
- lame_set_short_threshold_lrm(lame_global_flags * gfp, float lrm)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->attackthre = lrm;
- return 0;
- }
- return -1;
- }
- float
- lame_get_short_threshold_lrm(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->attackthre;
- }
- return 0;
- }
- int
- lame_set_short_threshold_s(lame_global_flags * gfp, float s)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->attackthre_s = s;
- return 0;
- }
- return -1;
- }
- float
- lame_get_short_threshold_s(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->attackthre_s;
- }
- return 0;
- }
- int
- lame_set_short_threshold(lame_global_flags * gfp, float lrm, float s)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_set_short_threshold_lrm(gfp, lrm);
- lame_set_short_threshold_s(gfp, s);
- return 0;
- }
- return -1;
- }
- /*
- * Input PCM is emphased PCM
- * (for instance from one of the rarely emphased CDs).
- *
- * It is STRONGLY not recommended to use this, because psycho does not
- * take it into account, and last but not least many decoders
- * ignore these bits
- */
- int
- lame_set_emphasis(lame_global_flags * gfp, int emphasis)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* XXX: emphasis should be converted to an enum */
- if (0 <= emphasis && emphasis < 4) {
- gfp->emphasis = emphasis;
- return 0;
- }
- }
- return -1;
- }
- int
- lame_get_emphasis(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- assert(0 <= gfp->emphasis && gfp->emphasis < 4);
- return gfp->emphasis;
- }
- return 0;
- }
- /***************************************************************/
- /* internal variables, cannot be set... */
- /* provided because they may be of use to calling application */
- /***************************************************************/
- /* MPEG version.
- * 0 = MPEG-2
- * 1 = MPEG-1
- * (2 = MPEG-2.5)
- */
- int
- lame_get_version(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->cfg.version;
- }
- }
- return 0;
- }
- /* Encoder delay. */
- int
- lame_get_encoder_delay(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_enc.encoder_delay;
- }
- }
- return 0;
- }
- /* padding added to the end of the input */
- int
- lame_get_encoder_padding(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_enc.encoder_padding;
- }
- }
- return 0;
- }
- /* Size of MPEG frame. */
- int
- lame_get_framesize(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- SessionConfig_t const *const cfg = &gfc->cfg;
- return 576 * cfg->mode_gr;
- }
- }
- return 0;
- }
- /* Number of frames encoded so far. */
- int
- lame_get_frameNum(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_enc.frame_number;
- }
- }
- return 0;
- }
- int
- lame_get_mf_samples_to_encode(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->sv_enc.mf_samples_to_encode;
- }
- }
- return 0;
- }
- int CDECL
- lame_get_size_mp3buffer(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- int size;
- compute_flushbits(gfc, &size);
- return size;
- }
- }
- return 0;
- }
- int
- lame_get_RadioGain(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_rpg.RadioGain;
- }
- }
- return 0;
- }
- int
- lame_get_AudiophileGain(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return 0;
- }
- }
- return 0;
- }
- float
- lame_get_PeakSample(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return (float) gfc->ov_rpg.PeakSample;
- }
- }
- return 0;
- }
- int
- lame_get_noclipGainChange(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_rpg.noclipGainChange;
- }
- }
- return 0;
- }
- float
- lame_get_noclipScale(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return gfc->ov_rpg.noclipScale;
- }
- }
- return 0;
- }
- /*
- * LAME's estimate of the total number of frames to be encoded.
- * Only valid if calling program set num_samples.
- */
- int
- lame_get_totalframes(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- SessionConfig_t const *const cfg = &gfc->cfg;
- unsigned long const pcm_samples_per_frame = 576 * cfg->mode_gr;
- unsigned long pcm_samples_to_encode = gfp->num_samples;
- unsigned long end_padding = 0;
- int frames = 0;
- if (pcm_samples_to_encode == (0ul-1ul))
- return 0; /* unknown */
- /* estimate based on user set num_samples: */
- if (cfg->samplerate_in != cfg->samplerate_out) {
- /* resampling, estimate new samples_to_encode */
- double resampled_samples_to_encode = 0.0, frames_f = 0.0;
- if (cfg->samplerate_in > 0) {
- resampled_samples_to_encode = pcm_samples_to_encode;
- resampled_samples_to_encode *= cfg->samplerate_out;
- resampled_samples_to_encode /= cfg->samplerate_in;
- }
- if (resampled_samples_to_encode <= 0.0)
- return 0; /* unlikely to happen, so what, no estimate! */
- frames_f = floor(resampled_samples_to_encode / pcm_samples_per_frame);
- if (frames_f >= (INT_MAX-2))
- return 0; /* overflow, happens eventually, no estimate! */
- frames = frames_f;
- resampled_samples_to_encode -= frames * pcm_samples_per_frame;
- pcm_samples_to_encode = ceil(resampled_samples_to_encode);
- }
- else {
- frames = pcm_samples_to_encode / pcm_samples_per_frame;
- pcm_samples_to_encode -= frames * pcm_samples_per_frame;
- }
- pcm_samples_to_encode += 576ul;
- end_padding = pcm_samples_per_frame - (pcm_samples_to_encode % pcm_samples_per_frame);
- if (end_padding < 576ul) {
- end_padding += pcm_samples_per_frame;
- }
- pcm_samples_to_encode += end_padding;
- frames += (pcm_samples_to_encode / pcm_samples_per_frame);
- /* check to see if we underestimated totalframes */
- /* if (totalframes < gfp->frameNum) */
- /* totalframes = gfp->frameNum; */
- return frames;
- }
- }
- return 0;
- }
- int
- lame_set_preset(lame_global_flags * gfp, int preset)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->preset = preset;
- return apply_preset(gfp, preset, 1);
- }
- return -1;
- }
- int
- lame_set_asm_optimizations(lame_global_flags * gfp, int optim, int mode)
- {
- if (is_lame_global_flags_valid(gfp)) {
- mode = (mode == 1 ? 1 : 0);
- switch (optim) {
- case MMX:{
- gfp->asm_optimizations.mmx = mode;
- return optim;
- }
- case AMD_3DNOW:{
- gfp->asm_optimizations.amd3dnow = mode;
- return optim;
- }
- case SSE:{
- gfp->asm_optimizations.sse = mode;
- return optim;
- }
- default:
- return optim;
- }
- }
- return -1;
- }
- void
- lame_set_write_id3tag_automatic(lame_global_flags * gfp, int v)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->write_id3tag_automatic = v;
- }
- }
- int
- lame_get_write_id3tag_automatic(lame_global_flags const *gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->write_id3tag_automatic;
- }
- return 1;
- }
- /*
- UNDOCUMENTED, experimental settings. These routines are not prototyped
- in lame.h. You should not use them, they are experimental and may
- change.
- */
- /*
- * just another daily changing developer switch
- */
- void CDECL lame_set_tune(lame_global_flags *, float);
- void
- lame_set_tune(lame_global_flags * gfp, float val)
- {
- if (is_lame_global_flags_valid(gfp)) {
- gfp->tune_value_a = val;
- gfp->tune = 1;
- }
- }
- /* Custom msfix hack */
- void
- lame_set_msfix(lame_global_flags * gfp, double msfix)
- {
- if (is_lame_global_flags_valid(gfp)) {
- /* default = 0 */
- gfp->msfix = msfix;
- }
- }
- float
- lame_get_msfix(const lame_global_flags * gfp)
- {
- if (is_lame_global_flags_valid(gfp)) {
- return gfp->msfix;
- }
- return 0;
- }
- #if DEPRECATED_OR_OBSOLETE_CODE_REMOVED
- int CDECL lame_set_preset_expopts(lame_global_flags *, int);
- #else
- #endif
- int
- lame_set_preset_expopts(lame_global_flags * gfp, int preset_expopts)
- {
- (void) gfp;
- (void) preset_expopts;
- return 0;
- }
- int
- lame_set_preset_notune(lame_global_flags * gfp, int preset_notune)
- {
- (void) gfp;
- (void) preset_notune;
- return 0;
- }
- static int
- calc_maximum_input_samples_for_buffer_size(lame_internal_flags const* gfc, size_t buffer_size)
- {
- SessionConfig_t const *const cfg = &gfc->cfg;
- int const pcm_samples_per_frame = 576 * cfg->mode_gr;
- int frames_per_buffer = 0, input_samples_per_buffer = 0;
- int kbps = 320;
- if (cfg->samplerate_out < 16000)
- kbps = 64;
- else if (cfg->samplerate_out < 32000)
- kbps = 160;
- else
- kbps = 320;
- if (cfg->free_format)
- kbps = cfg->avg_bitrate;
- else if (cfg->vbr == vbr_off) {
- kbps = cfg->avg_bitrate;
- }
- {
- int const pad = 1;
- int const bpf = ((cfg->version + 1) * 72000 * kbps / cfg->samplerate_out + pad);
- frames_per_buffer = buffer_size / bpf;
- }
- {
- double ratio = (double) cfg->samplerate_in / cfg->samplerate_out;
- input_samples_per_buffer = pcm_samples_per_frame * frames_per_buffer * ratio;
- }
- return input_samples_per_buffer;
- }
- int
- lame_get_maximum_number_of_samples(lame_t gfp, size_t buffer_size)
- {
- if (is_lame_global_flags_valid(gfp)) {
- lame_internal_flags const *const gfc = gfp->internal_flags;
- if (is_lame_internal_flags_valid(gfc)) {
- return calc_maximum_input_samples_for_buffer_size(gfc, buffer_size);
- }
- }
- return LAME_GENERICERROR;
- }
|