vorbisenc.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: simple programmatic interface for encoder mode setup
  13. last mod: $Id$
  14. ********************************************************************/
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <math.h>
  18. #include "vorbis/codec.h"
  19. #include "vorbis/vorbisenc.h"
  20. #include "codec_internal.h"
  21. #include "os.h"
  22. #include "misc.h"
  23. /* careful with this; it's using static array sizing to make managing
  24. all the modes a little less annoying. If we use a residue backend
  25. with > 12 partition types, or a different division of iteration,
  26. this needs to be updated. */
  27. typedef struct {
  28. static_codebook *books[12][3];
  29. } static_bookblock;
  30. typedef struct {
  31. int res_type;
  32. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  33. vorbis_info_residue0 *res;
  34. static_codebook *book_aux;
  35. static_codebook *book_aux_managed;
  36. static_bookblock *books_base;
  37. static_bookblock *books_base_managed;
  38. } vorbis_residue_template;
  39. typedef struct {
  40. vorbis_info_mapping0 *map;
  41. vorbis_residue_template *res;
  42. } vorbis_mapping_template;
  43. typedef struct vp_adjblock{
  44. int block[P_BANDS];
  45. } vp_adjblock;
  46. typedef struct {
  47. int data[NOISE_COMPAND_LEVELS];
  48. } compandblock;
  49. /* high level configuration information for setting things up
  50. step-by-step with the detailed vorbis_encode_ctl interface.
  51. There's a fair amount of redundancy such that interactive setup
  52. does not directly deal with any vorbis_info or codec_setup_info
  53. initialization; it's all stored (until full init) in this highlevel
  54. setup, then flushed out to the real codec setup structs later. */
  55. typedef struct {
  56. int att[P_NOISECURVES];
  57. float boost;
  58. float decay;
  59. } att3;
  60. typedef struct { int data[P_NOISECURVES]; } adj3;
  61. typedef struct {
  62. int pre[PACKETBLOBS];
  63. int post[PACKETBLOBS];
  64. float kHz[PACKETBLOBS];
  65. float lowpasskHz[PACKETBLOBS];
  66. } adj_stereo;
  67. typedef struct {
  68. int lo;
  69. int hi;
  70. int fixed;
  71. } noiseguard;
  72. typedef struct {
  73. int data[P_NOISECURVES][17];
  74. } noise3;
  75. typedef struct {
  76. int mappings;
  77. double *rate_mapping;
  78. double *quality_mapping;
  79. int coupling_restriction;
  80. long samplerate_min_restriction;
  81. long samplerate_max_restriction;
  82. int *blocksize_short;
  83. int *blocksize_long;
  84. att3 *psy_tone_masteratt;
  85. int *psy_tone_0dB;
  86. int *psy_tone_dBsuppress;
  87. vp_adjblock *psy_tone_adj_impulse;
  88. vp_adjblock *psy_tone_adj_long;
  89. vp_adjblock *psy_tone_adj_other;
  90. noiseguard *psy_noiseguards;
  91. noise3 *psy_noise_bias_impulse;
  92. noise3 *psy_noise_bias_padding;
  93. noise3 *psy_noise_bias_trans;
  94. noise3 *psy_noise_bias_long;
  95. int *psy_noise_dBsuppress;
  96. compandblock *psy_noise_compand;
  97. double *psy_noise_compand_short_mapping;
  98. double *psy_noise_compand_long_mapping;
  99. int *psy_noise_normal_start[2];
  100. int *psy_noise_normal_partition[2];
  101. double *psy_noise_normal_thresh;
  102. int *psy_ath_float;
  103. int *psy_ath_abs;
  104. double *psy_lowpass;
  105. vorbis_info_psy_global *global_params;
  106. double *global_mapping;
  107. adj_stereo *stereo_modes;
  108. static_codebook ***floor_books;
  109. vorbis_info_floor1 *floor_params;
  110. int *floor_short_mapping;
  111. int *floor_long_mapping;
  112. vorbis_mapping_template *maps;
  113. } ve_setup_data_template;
  114. /* a few static coder conventions */
  115. static vorbis_info_mode _mode_template[2]={
  116. {0,0,0,0},
  117. {1,0,0,1}
  118. };
  119. static vorbis_info_mapping0 _map_nominal[2]={
  120. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  121. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  122. };
  123. #include "modes/setup_44.h"
  124. #include "modes/setup_44u.h"
  125. #include "modes/setup_32.h"
  126. #include "modes/setup_8.h"
  127. #include "modes/setup_11.h"
  128. #include "modes/setup_16.h"
  129. #include "modes/setup_22.h"
  130. #include "modes/setup_X.h"
  131. static ve_setup_data_template *setup_list[]={
  132. &ve_setup_44_stereo,
  133. &ve_setup_44_uncoupled,
  134. &ve_setup_32_stereo,
  135. &ve_setup_32_uncoupled,
  136. &ve_setup_22_stereo,
  137. &ve_setup_22_uncoupled,
  138. &ve_setup_16_stereo,
  139. &ve_setup_16_uncoupled,
  140. &ve_setup_11_stereo,
  141. &ve_setup_11_uncoupled,
  142. &ve_setup_8_stereo,
  143. &ve_setup_8_uncoupled,
  144. &ve_setup_X_stereo,
  145. &ve_setup_X_uncoupled,
  146. &ve_setup_XX_stereo,
  147. &ve_setup_XX_uncoupled,
  148. 0
  149. };
  150. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  151. if(vi && vi->codec_setup){
  152. vi->version=0;
  153. vi->channels=ch;
  154. vi->rate=rate;
  155. return(0);
  156. }
  157. return(OV_EINVAL);
  158. }
  159. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  160. static_codebook ***books,
  161. vorbis_info_floor1 *in,
  162. int *x){
  163. int i,k,is=s;
  164. vorbis_info_floor1 *f=_ogg_calloc(1,sizeof(*f));
  165. codec_setup_info *ci=vi->codec_setup;
  166. memcpy(f,in+x[is],sizeof(*f));
  167. /* fill in the lowpass field, even if it's temporary */
  168. f->n=ci->blocksizes[block]>>1;
  169. /* books */
  170. {
  171. int partitions=f->partitions;
  172. int maxclass=-1;
  173. int maxbook=-1;
  174. for(i=0;i<partitions;i++)
  175. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  176. for(i=0;i<=maxclass;i++){
  177. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  178. f->class_book[i]+=ci->books;
  179. for(k=0;k<(1<<f->class_subs[i]);k++){
  180. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  181. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  182. }
  183. }
  184. for(i=0;i<=maxbook;i++)
  185. ci->book_param[ci->books++]=books[x[is]][i];
  186. }
  187. /* for now, we're only using floor 1 */
  188. ci->floor_type[ci->floors]=1;
  189. ci->floor_param[ci->floors]=f;
  190. ci->floors++;
  191. return;
  192. }
  193. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  194. vorbis_info_psy_global *in,
  195. double *x){
  196. int i,is=s;
  197. double ds=s-is;
  198. codec_setup_info *ci=vi->codec_setup;
  199. vorbis_info_psy_global *g=&ci->psy_g_param;
  200. memcpy(g,in+(int)x[is],sizeof(*g));
  201. ds=x[is]*(1.-ds)+x[is+1]*ds;
  202. is=(int)ds;
  203. ds-=is;
  204. if(ds==0 && is>0){
  205. is--;
  206. ds=1.;
  207. }
  208. /* interpolate the trigger threshholds */
  209. for(i=0;i<4;i++){
  210. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  211. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  212. }
  213. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  214. return;
  215. }
  216. static void vorbis_encode_global_stereo(vorbis_info *vi,
  217. highlevel_encode_setup *hi,
  218. adj_stereo *p){
  219. float s=hi->stereo_point_setting;
  220. int i,is=s;
  221. double ds=s-is;
  222. codec_setup_info *ci=vi->codec_setup;
  223. vorbis_info_psy_global *g=&ci->psy_g_param;
  224. if(p){
  225. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  226. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  227. if(hi->managed){
  228. /* interpolate the kHz threshholds */
  229. for(i=0;i<PACKETBLOBS;i++){
  230. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  231. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  232. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  233. g->coupling_pkHz[i]=kHz;
  234. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  235. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  236. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  237. }
  238. }else{
  239. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  240. for(i=0;i<PACKETBLOBS;i++){
  241. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  242. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  243. g->coupling_pkHz[i]=kHz;
  244. }
  245. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  246. for(i=0;i<PACKETBLOBS;i++){
  247. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  248. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  249. }
  250. }
  251. }else{
  252. for(i=0;i<PACKETBLOBS;i++){
  253. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  254. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  255. }
  256. }
  257. return;
  258. }
  259. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  260. int *nn_start,
  261. int *nn_partition,
  262. double *nn_thresh,
  263. int block){
  264. codec_setup_info *ci=vi->codec_setup;
  265. vorbis_info_psy *p=ci->psy_param[block];
  266. highlevel_encode_setup *hi=&ci->hi;
  267. int is=s;
  268. if(block>=ci->psys)
  269. ci->psys=block+1;
  270. if(!p){
  271. p=_ogg_calloc(1,sizeof(*p));
  272. ci->psy_param[block]=p;
  273. }
  274. memcpy(p,&_psy_info_template,sizeof(*p));
  275. p->blockflag=block>>1;
  276. if(hi->noise_normalize_p){
  277. p->normal_channel_p=1;
  278. p->normal_point_p=1;
  279. p->normal_start=nn_start[is];
  280. p->normal_partition=nn_partition[is];
  281. p->normal_thresh=nn_thresh[is];
  282. }
  283. return;
  284. }
  285. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  286. att3 *att,
  287. int *max,
  288. vp_adjblock *in){
  289. int i,is=s;
  290. double ds=s-is;
  291. codec_setup_info *ci=vi->codec_setup;
  292. vorbis_info_psy *p=ci->psy_param[block];
  293. /* 0 and 2 are only used by bitmanagement, but there's no harm to always
  294. filling the values in here */
  295. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  296. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  297. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  298. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  299. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  300. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  301. for(i=0;i<P_BANDS;i++)
  302. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  303. return;
  304. }
  305. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  306. compandblock *in, double *x){
  307. int i,is=s, ishcm, hcm_stop=5; // high compander limit
  308. double ds=s-is, dshcm;
  309. codec_setup_info *ci=vi->codec_setup;
  310. vorbis_info_psy *p=ci->psy_param[block];
  311. /* the place was borrowed... */
  312. p->flacint=ds;
  313. /* interpolate the compander mapping */
  314. ds=x[is]*(1.-ds)+x[is+1]*ds;
  315. is=(int)ds;
  316. ds-=is;
  317. if(ds==0 && is>0){
  318. is--;
  319. ds=1.;
  320. }
  321. /* high compander setup */
  322. ishcm = is;
  323. dshcm = ds+.3;
  324. if(dshcm > 1.0){
  325. ishcm++;
  326. dshcm=dshcm-1;
  327. }
  328. if(x[hcm_stop] < ((float)ishcm+dshcm)){
  329. ishcm = x[hcm_stop];
  330. dshcm = x[hcm_stop]-ishcm;
  331. }
  332. if(dshcm==0 && ishcm>0){ // the same
  333. ishcm--;
  334. dshcm=1.;
  335. }
  336. /* interpolate the compander settings */
  337. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  338. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  339. /* interpolate the high compander settings */
  340. if(s < (float)hcm_stop){
  341. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  342. p->noisecompand_high[i]=in[ishcm].data[i]*(1.-dshcm)+in[ishcm+1].data[i]*dshcm;
  343. }else{ // disable high compander
  344. for(i=0;i<NOISE_COMPAND_LEVELS;i++)p->noisecompand_high[i]=0;
  345. }
  346. return;
  347. }
  348. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  349. int *suppress){
  350. int is=s;
  351. double ds=s-is;
  352. codec_setup_info *ci=vi->codec_setup;
  353. vorbis_info_psy *p=ci->psy_param[block];
  354. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  355. return;
  356. }
  357. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  358. int *suppress,
  359. noise3 *in,
  360. noiseguard *guard,
  361. double userbias){
  362. int i,is=s,j;
  363. double ds=s-is;
  364. codec_setup_info *ci=vi->codec_setup;
  365. vorbis_info_psy *p=ci->psy_param[block];
  366. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  367. p->noisewindowlomin=guard[block].lo;
  368. p->noisewindowhimin=guard[block].hi;
  369. p->noisewindowfixed=guard[block].fixed;
  370. for(j=0;j<P_NOISECURVES;j++)
  371. for(i=0;i<P_BANDS;i++)
  372. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  373. /* impulse blocks may take a user specified bias to boost the
  374. nominal/high noise encoding depth */
  375. for(j=0;j<P_NOISECURVES;j++){
  376. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  377. for(i=0;i<P_BANDS;i++){
  378. p->noiseoff[j][i]+=userbias;
  379. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  380. }
  381. }
  382. return;
  383. }
  384. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  385. codec_setup_info *ci=vi->codec_setup;
  386. vorbis_info_psy *p=ci->psy_param[block];
  387. p->ath_adjatt=ci->hi.ath_floating_dB;
  388. p->ath_maxatt=ci->hi.ath_absolute_dB;
  389. return;
  390. }
  391. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  392. int i;
  393. for(i=0;i<ci->books;i++)
  394. if(ci->book_param[i]==book)return(i);
  395. return(ci->books++);
  396. }
  397. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  398. int *shortb,int *longb){
  399. codec_setup_info *ci=vi->codec_setup;
  400. int is=s;
  401. int blockshort=shortb[is];
  402. int blocklong=longb[is];
  403. ci->blocksizes[0]=blockshort;
  404. ci->blocksizes[1]=blocklong;
  405. }
  406. static void vorbis_encode_residue_setup(vorbis_info *vi,
  407. int number, int block,
  408. vorbis_residue_template *res){
  409. codec_setup_info *ci=vi->codec_setup;
  410. int i,n;
  411. vorbis_info_residue0 *r=ci->residue_param[number]=
  412. _ogg_malloc(sizeof(*r));
  413. memcpy(r,res->res,sizeof(*r));
  414. if(ci->residues<=number)ci->residues=number+1;
  415. switch(ci->blocksizes[block]){
  416. case 64:case 128:case 256:
  417. r->grouping=16;
  418. break;
  419. default:
  420. r->grouping=32;
  421. break;
  422. }
  423. ci->residue_type[number]=res->res_type;
  424. /* to be adjusted by lowpass/pointlimit later */
  425. n=r->end=ci->blocksizes[block]>>1;
  426. if(res->res_type==2)
  427. n=r->end*=vi->channels;
  428. /* fill in all the books */
  429. {
  430. int booklist=0,k;
  431. if(ci->hi.managed){
  432. for(i=0;i<r->partitions;i++)
  433. for(k=0;k<3;k++)
  434. if(res->books_base_managed->books[i][k])
  435. r->secondstages[i]|=(1<<k);
  436. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  437. ci->book_param[r->groupbook]=res->book_aux_managed;
  438. for(i=0;i<r->partitions;i++){
  439. for(k=0;k<3;k++){
  440. if(res->books_base_managed->books[i][k]){
  441. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  442. r->booklist[booklist++]=bookid;
  443. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  444. }
  445. }
  446. }
  447. }else{
  448. for(i=0;i<r->partitions;i++)
  449. for(k=0;k<3;k++)
  450. if(res->books_base->books[i][k])
  451. r->secondstages[i]|=(1<<k);
  452. r->groupbook=book_dup_or_new(ci,res->book_aux);
  453. ci->book_param[r->groupbook]=res->book_aux;
  454. for(i=0;i<r->partitions;i++){
  455. for(k=0;k<3;k++){
  456. if(res->books_base->books[i][k]){
  457. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  458. r->booklist[booklist++]=bookid;
  459. ci->book_param[bookid]=res->books_base->books[i][k];
  460. }
  461. }
  462. }
  463. }
  464. }
  465. /* lowpass setup/pointlimit */
  466. {
  467. double freq=ci->hi.lowpass_kHz*1000.;
  468. vorbis_info_floor1 *f=ci->floor_param[block]; /* by convention */
  469. double nyq=vi->rate/2.;
  470. long blocksize=ci->blocksizes[block]>>1;
  471. /* lowpass needs to be set in the floor and the residue. */
  472. if(freq>nyq)freq=nyq;
  473. /* in the floor, the granularity can be very fine; it doesn't alter
  474. the encoding structure, only the samples used to fit the floor
  475. approximation */
  476. f->n=freq/nyq*blocksize;
  477. /* this res may by limited by the maximum pointlimit of the mode,
  478. not the lowpass. the floor is always lowpass limited. */
  479. if(res->limit_type){
  480. if(ci->hi.managed)
  481. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  482. else
  483. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  484. if(freq>nyq)freq=nyq;
  485. }
  486. /* in the residue, we're constrained, physically, by partition
  487. boundaries. We still lowpass 'wherever', but we have to round up
  488. here to next boundary, or the vorbis spec will round it *down* to
  489. previous boundary in encode/decode */
  490. if(ci->residue_type[block]==2)
  491. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  492. r->grouping;
  493. else
  494. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  495. r->grouping;
  496. }
  497. }
  498. /* we assume two maps in this encoder */
  499. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  500. vorbis_mapping_template *maps){
  501. codec_setup_info *ci=vi->codec_setup;
  502. int i,j,is=s,modes=2;
  503. vorbis_info_mapping0 *map=maps[is].map;
  504. vorbis_info_mode *mode=_mode_template;
  505. vorbis_residue_template *res=maps[is].res;
  506. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  507. for(i=0;i<modes;i++){
  508. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  509. ci->mode_param[i]=_ogg_calloc(1,sizeof(*mode));
  510. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  511. if(i>=ci->modes)ci->modes=i+1;
  512. ci->map_type[i]=0;
  513. memcpy(ci->map_param[i],map+i,sizeof(*map));
  514. if(i>=ci->maps)ci->maps=i+1;
  515. for(j=0;j<map[i].submaps;j++)
  516. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  517. ,res+map[i].residuesubmap[j]);
  518. }
  519. }
  520. static double setting_to_approx_bitrate(vorbis_info *vi){
  521. codec_setup_info *ci=vi->codec_setup;
  522. highlevel_encode_setup *hi=&ci->hi;
  523. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  524. int is=hi->base_setting;
  525. double ds=hi->base_setting-is;
  526. int ch=vi->channels;
  527. double *r=setup->rate_mapping;
  528. if(r==NULL)
  529. return(-1);
  530. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  531. }
  532. static void get_setup_template(vorbis_info *vi,
  533. long ch,long srate,
  534. double req,int q_or_bitrate){
  535. int i=0,j;
  536. codec_setup_info *ci=vi->codec_setup;
  537. highlevel_encode_setup *hi=&ci->hi;
  538. if(q_or_bitrate)req/=ch;
  539. while(setup_list[i]){
  540. if(setup_list[i]->coupling_restriction==-1 ||
  541. setup_list[i]->coupling_restriction==ch){
  542. if(srate>=setup_list[i]->samplerate_min_restriction &&
  543. srate<=setup_list[i]->samplerate_max_restriction){
  544. int mappings=setup_list[i]->mappings;
  545. double *map=(q_or_bitrate?
  546. setup_list[i]->rate_mapping:
  547. setup_list[i]->quality_mapping);
  548. /* the template matches. Does the requested quality mode
  549. fall within this template's modes? */
  550. if(req<map[0]){++i;continue;}
  551. if(req>map[setup_list[i]->mappings]){++i;continue;}
  552. for(j=0;j<mappings;j++)
  553. if(req>=map[j] && req<map[j+1])break;
  554. /* an all-points match */
  555. hi->setup=setup_list[i];
  556. if(j==mappings)
  557. hi->base_setting=j-.001;
  558. else{
  559. float low=map[j];
  560. float high=map[j+1];
  561. float del=(req-low)/(high-low);
  562. hi->base_setting=j+del;
  563. }
  564. return;
  565. }
  566. }
  567. i++;
  568. }
  569. hi->setup=NULL;
  570. }
  571. /* encoders will need to use vorbis_info_init beforehand and call
  572. vorbis_info clear when all done */
  573. /* two interfaces; this, more detailed one, and later a convenience
  574. layer on top */
  575. /* the final setup call */
  576. int vorbis_encode_setup_init(vorbis_info *vi){
  577. int i0=0,singleblock=0;
  578. codec_setup_info *ci=vi->codec_setup;
  579. ve_setup_data_template *setup=NULL;
  580. highlevel_encode_setup *hi=&ci->hi;
  581. if(ci==NULL)return(OV_EINVAL);
  582. if(!hi->impulse_block_p)i0=1;
  583. /* too low/high an ATH floater is nonsensical, but doesn't break anything */
  584. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  585. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  586. /* again, bound this to avoid the app shooting itself int he foot
  587. too badly */
  588. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  589. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  590. /* get the appropriate setup template; matches the fetch in previous
  591. stages */
  592. setup=(ve_setup_data_template *)hi->setup;
  593. if(setup==NULL)return(OV_EINVAL);
  594. hi->set_in_stone=1;
  595. /* choose block sizes from configured sizes as well as paying
  596. attention to long_block_p and short_block_p. If the configured
  597. short and long blocks are the same length, we set long_block_p
  598. and unset short_block_p */
  599. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  600. setup->blocksize_short,
  601. setup->blocksize_long);
  602. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  603. /* floor setup; choose proper floor params. Allocated on the floor
  604. stack in order; if we alloc only long floor, it's 0 */
  605. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  606. setup->floor_books,
  607. setup->floor_params,
  608. setup->floor_short_mapping);
  609. if(!singleblock)
  610. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  611. setup->floor_books,
  612. setup->floor_params,
  613. setup->floor_long_mapping);
  614. /* setup of [mostly] short block detection and stereo*/
  615. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  616. setup->global_params,
  617. setup->global_mapping);
  618. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  619. /* basic psych setup and noise normalization */
  620. vorbis_encode_psyset_setup(vi,hi->short_setting,
  621. setup->psy_noise_normal_start[0],
  622. setup->psy_noise_normal_partition[0],
  623. setup->psy_noise_normal_thresh,
  624. 0);
  625. vorbis_encode_psyset_setup(vi,hi->short_setting,
  626. setup->psy_noise_normal_start[0],
  627. setup->psy_noise_normal_partition[0],
  628. setup->psy_noise_normal_thresh,
  629. 1);
  630. if(!singleblock){
  631. vorbis_encode_psyset_setup(vi,hi->long_setting,
  632. setup->psy_noise_normal_start[1],
  633. setup->psy_noise_normal_partition[1],
  634. setup->psy_noise_normal_thresh,
  635. 2);
  636. vorbis_encode_psyset_setup(vi,hi->long_setting,
  637. setup->psy_noise_normal_start[1],
  638. setup->psy_noise_normal_partition[1],
  639. setup->psy_noise_normal_thresh,
  640. 3);
  641. }
  642. /* tone masking setup */
  643. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  644. setup->psy_tone_masteratt,
  645. setup->psy_tone_0dB,
  646. setup->psy_tone_adj_impulse);
  647. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  648. setup->psy_tone_masteratt,
  649. setup->psy_tone_0dB,
  650. setup->psy_tone_adj_other);
  651. if(!singleblock){
  652. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  653. setup->psy_tone_masteratt,
  654. setup->psy_tone_0dB,
  655. setup->psy_tone_adj_other);
  656. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  657. setup->psy_tone_masteratt,
  658. setup->psy_tone_0dB,
  659. setup->psy_tone_adj_long);
  660. }
  661. /* noise companding setup */
  662. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  663. setup->psy_noise_compand,
  664. setup->psy_noise_compand_short_mapping);
  665. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  666. setup->psy_noise_compand,
  667. setup->psy_noise_compand_short_mapping);
  668. if(!singleblock){
  669. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  670. setup->psy_noise_compand,
  671. setup->psy_noise_compand_long_mapping);
  672. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  673. setup->psy_noise_compand,
  674. setup->psy_noise_compand_long_mapping);
  675. }
  676. /* peak guarding setup */
  677. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  678. setup->psy_tone_dBsuppress);
  679. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  680. setup->psy_tone_dBsuppress);
  681. if(!singleblock){
  682. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  683. setup->psy_tone_dBsuppress);
  684. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  685. setup->psy_tone_dBsuppress);
  686. }
  687. /* noise bias setup */
  688. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  689. setup->psy_noise_dBsuppress,
  690. setup->psy_noise_bias_impulse,
  691. setup->psy_noiseguards,
  692. (i0==0?hi->impulse_noisetune:0.));
  693. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  694. setup->psy_noise_dBsuppress,
  695. setup->psy_noise_bias_padding,
  696. setup->psy_noiseguards,0.);
  697. if(!singleblock){
  698. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  699. setup->psy_noise_dBsuppress,
  700. setup->psy_noise_bias_trans,
  701. setup->psy_noiseguards,0.);
  702. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  703. setup->psy_noise_dBsuppress,
  704. setup->psy_noise_bias_long,
  705. setup->psy_noiseguards,0.);
  706. }
  707. vorbis_encode_ath_setup(vi,0);
  708. vorbis_encode_ath_setup(vi,1);
  709. if(!singleblock){
  710. vorbis_encode_ath_setup(vi,2);
  711. vorbis_encode_ath_setup(vi,3);
  712. }
  713. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  714. /* set bitrate readonlies and management */
  715. if(hi->bitrate_av>0)
  716. vi->bitrate_nominal=hi->bitrate_av;
  717. else{
  718. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  719. }
  720. vi->bitrate_lower=hi->bitrate_min;
  721. vi->bitrate_upper=hi->bitrate_max;
  722. if(hi->bitrate_av)
  723. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  724. else
  725. vi->bitrate_window=0.;
  726. if(hi->managed){
  727. ci->bi.avg_rate=hi->bitrate_av;
  728. ci->bi.min_rate=hi->bitrate_min;
  729. ci->bi.max_rate=hi->bitrate_max;
  730. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  731. ci->bi.reservoir_bias=
  732. hi->bitrate_reservoir_bias;
  733. ci->bi.slew_damp=hi->bitrate_av_damp;
  734. }
  735. return(0);
  736. }
  737. static int vorbis_encode_setup_setting(vorbis_info *vi,
  738. long channels,
  739. long rate){
  740. int ret=0,i,is;
  741. codec_setup_info *ci=vi->codec_setup;
  742. highlevel_encode_setup *hi=&ci->hi;
  743. ve_setup_data_template *setup=hi->setup;
  744. double ds;
  745. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  746. if(ret)return(ret);
  747. is=hi->base_setting;
  748. ds=hi->base_setting-is;
  749. hi->short_setting=hi->base_setting;
  750. hi->long_setting=hi->base_setting;
  751. hi->managed=0;
  752. hi->impulse_block_p=1;
  753. hi->noise_normalize_p=1;
  754. hi->stereo_point_setting=hi->base_setting;
  755. hi->lowpass_kHz=
  756. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  757. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  758. setup->psy_ath_float[is+1]*ds;
  759. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  760. setup->psy_ath_abs[is+1]*ds;
  761. hi->amplitude_track_dBpersec=-6.;
  762. hi->trigger_setting=hi->base_setting;
  763. for(i=0;i<4;i++){
  764. hi->block[i].tone_mask_setting=hi->base_setting;
  765. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  766. hi->block[i].noise_bias_setting=hi->base_setting;
  767. hi->block[i].noise_compand_setting=hi->base_setting;
  768. }
  769. return(ret);
  770. }
  771. int vorbis_encode_setup_vbr(vorbis_info *vi,
  772. long channels,
  773. long rate,
  774. float quality){
  775. codec_setup_info *ci=vi->codec_setup;
  776. highlevel_encode_setup *hi=&ci->hi;
  777. quality+=.0000001;
  778. if(quality>=1.)quality=.9999;
  779. get_setup_template(vi,channels,rate,quality,0);
  780. if(!hi->setup)return OV_EIMPL;
  781. return vorbis_encode_setup_setting(vi,channels,rate);
  782. }
  783. int vorbis_encode_init_vbr(vorbis_info *vi,
  784. long channels,
  785. long rate,
  786. float base_quality /* 0. to 1. */
  787. ){
  788. int ret=0;
  789. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  790. if(ret){
  791. vorbis_info_clear(vi);
  792. return ret;
  793. }
  794. ret=vorbis_encode_setup_init(vi);
  795. if(ret)
  796. vorbis_info_clear(vi);
  797. return(ret);
  798. }
  799. int vorbis_encode_setup_managed(vorbis_info *vi,
  800. long channels,
  801. long rate,
  802. long max_bitrate,
  803. long nominal_bitrate,
  804. long min_bitrate){
  805. codec_setup_info *ci=vi->codec_setup;
  806. highlevel_encode_setup *hi=&ci->hi;
  807. double tnominal=nominal_bitrate;
  808. int ret=0;
  809. if(nominal_bitrate<=0.){
  810. if(max_bitrate>0.){
  811. if(min_bitrate>0.)
  812. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  813. else
  814. nominal_bitrate=max_bitrate*.875;
  815. }else{
  816. if(min_bitrate>0.){
  817. nominal_bitrate=min_bitrate;
  818. }else{
  819. return(OV_EINVAL);
  820. }
  821. }
  822. }
  823. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  824. if(!hi->setup)return OV_EIMPL;
  825. ret=vorbis_encode_setup_setting(vi,channels,rate);
  826. if(ret){
  827. vorbis_info_clear(vi);
  828. return ret;
  829. }
  830. /* initialize management with sane defaults */
  831. hi->managed=1;
  832. hi->bitrate_min=min_bitrate;
  833. hi->bitrate_max=max_bitrate;
  834. hi->bitrate_av=tnominal;
  835. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  836. hi->bitrate_reservoir=nominal_bitrate*2;
  837. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  838. return(ret);
  839. }
  840. int vorbis_encode_init(vorbis_info *vi,
  841. long channels,
  842. long rate,
  843. long max_bitrate,
  844. long nominal_bitrate,
  845. long min_bitrate){
  846. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  847. max_bitrate,
  848. nominal_bitrate,
  849. min_bitrate);
  850. if(ret){
  851. vorbis_info_clear(vi);
  852. return(ret);
  853. }
  854. ret=vorbis_encode_setup_init(vi);
  855. if(ret)
  856. vorbis_info_clear(vi);
  857. return(ret);
  858. }
  859. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  860. if(vi){
  861. codec_setup_info *ci=vi->codec_setup;
  862. highlevel_encode_setup *hi=&ci->hi;
  863. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  864. if(setp && hi->set_in_stone)return(OV_EINVAL);
  865. switch(number){
  866. /* now deprecated *****************/
  867. case OV_ECTL_RATEMANAGE_GET:
  868. {
  869. struct ovectl_ratemanage_arg *ai=
  870. (struct ovectl_ratemanage_arg *)arg;
  871. ai->management_active=hi->managed;
  872. ai->bitrate_hard_window=ai->bitrate_av_window=
  873. (double)hi->bitrate_reservoir/vi->rate;
  874. ai->bitrate_av_window_center=1.;
  875. ai->bitrate_hard_min=hi->bitrate_min;
  876. ai->bitrate_hard_max=hi->bitrate_max;
  877. ai->bitrate_av_lo=hi->bitrate_av;
  878. ai->bitrate_av_hi=hi->bitrate_av;
  879. }
  880. return(0);
  881. /* now deprecated *****************/
  882. case OV_ECTL_RATEMANAGE_SET:
  883. {
  884. struct ovectl_ratemanage_arg *ai=
  885. (struct ovectl_ratemanage_arg *)arg;
  886. if(ai==NULL){
  887. hi->managed=0;
  888. }else{
  889. hi->managed=ai->management_active;
  890. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  891. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  892. }
  893. }
  894. return 0;
  895. /* now deprecated *****************/
  896. case OV_ECTL_RATEMANAGE_AVG:
  897. {
  898. struct ovectl_ratemanage_arg *ai=
  899. (struct ovectl_ratemanage_arg *)arg;
  900. if(ai==NULL){
  901. hi->bitrate_av=0;
  902. }else{
  903. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  904. }
  905. }
  906. return(0);
  907. /* now deprecated *****************/
  908. case OV_ECTL_RATEMANAGE_HARD:
  909. {
  910. struct ovectl_ratemanage_arg *ai=
  911. (struct ovectl_ratemanage_arg *)arg;
  912. if(ai==NULL){
  913. hi->bitrate_min=0;
  914. hi->bitrate_max=0;
  915. }else{
  916. hi->bitrate_min=ai->bitrate_hard_min;
  917. hi->bitrate_max=ai->bitrate_hard_max;
  918. hi->bitrate_reservoir=ai->bitrate_hard_window*
  919. (hi->bitrate_max+hi->bitrate_min)*.5;
  920. }
  921. if(hi->bitrate_reservoir<128.)
  922. hi->bitrate_reservoir=128.;
  923. }
  924. return(0);
  925. /* replacement ratemanage interface */
  926. case OV_ECTL_RATEMANAGE2_GET:
  927. {
  928. struct ovectl_ratemanage2_arg *ai=
  929. (struct ovectl_ratemanage2_arg *)arg;
  930. if(ai==NULL)return OV_EINVAL;
  931. ai->management_active=hi->managed;
  932. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  933. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  934. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  935. ai->bitrate_average_damping=hi->bitrate_av_damp;
  936. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  937. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  938. }
  939. return (0);
  940. case OV_ECTL_RATEMANAGE2_SET:
  941. {
  942. struct ovectl_ratemanage2_arg *ai=
  943. (struct ovectl_ratemanage2_arg *)arg;
  944. if(ai==NULL){
  945. hi->managed=0;
  946. }else{
  947. /* sanity check; only catch invariant violations */
  948. if(ai->bitrate_limit_min_kbps>0 &&
  949. ai->bitrate_average_kbps>0 &&
  950. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  951. return OV_EINVAL;
  952. if(ai->bitrate_limit_max_kbps>0 &&
  953. ai->bitrate_average_kbps>0 &&
  954. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  955. return OV_EINVAL;
  956. if(ai->bitrate_limit_min_kbps>0 &&
  957. ai->bitrate_limit_max_kbps>0 &&
  958. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  959. return OV_EINVAL;
  960. if(ai->bitrate_average_damping <= 0.)
  961. return OV_EINVAL;
  962. if(ai->bitrate_limit_reservoir_bits < 0)
  963. return OV_EINVAL;
  964. if(ai->bitrate_limit_reservoir_bias < 0.)
  965. return OV_EINVAL;
  966. if(ai->bitrate_limit_reservoir_bias > 1.)
  967. return OV_EINVAL;
  968. hi->managed=ai->management_active;
  969. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  970. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  971. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  972. hi->bitrate_av_damp=ai->bitrate_average_damping;
  973. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  974. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  975. }
  976. }
  977. return 0;
  978. case OV_ECTL_LOWPASS_GET:
  979. {
  980. double *farg=(double *)arg;
  981. *farg=hi->lowpass_kHz;
  982. }
  983. return(0);
  984. case OV_ECTL_LOWPASS_SET:
  985. {
  986. double *farg=(double *)arg;
  987. hi->lowpass_kHz=*farg;
  988. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  989. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  990. }
  991. return(0);
  992. case OV_ECTL_IBLOCK_GET:
  993. {
  994. double *farg=(double *)arg;
  995. *farg=hi->impulse_noisetune;
  996. }
  997. return(0);
  998. case OV_ECTL_IBLOCK_SET:
  999. {
  1000. double *farg=(double *)arg;
  1001. hi->impulse_noisetune=*farg;
  1002. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  1003. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  1004. }
  1005. return(0);
  1006. }
  1007. return(OV_EIMPL);
  1008. }
  1009. return(OV_EINVAL);
  1010. }