set_get.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347
  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. }