set_get.c 53 KB

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