michael@0: /******************************************************************** michael@0: * * michael@0: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * michael@0: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * michael@0: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * michael@0: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * michael@0: * * michael@0: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * michael@0: * by the Xiph.Org Foundation http://www.xiph.org/ * michael@0: * * michael@0: ******************************************************************** michael@0: michael@0: function: simple programmatic interface for encoder mode setup michael@0: last mod: $Id: vorbisenc.c 17028 2010-03-25 05:22:15Z xiphmont $ michael@0: michael@0: ********************************************************************/ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "vorbis/codec.h" michael@0: #include "vorbis/vorbisenc.h" michael@0: michael@0: #include "codec_internal.h" michael@0: michael@0: #include "os.h" michael@0: #include "misc.h" michael@0: michael@0: /* careful with this; it's using static array sizing to make managing michael@0: all the modes a little less annoying. If we use a residue backend michael@0: with > 12 partition types, or a different division of iteration, michael@0: this needs to be updated. */ michael@0: typedef struct { michael@0: const static_codebook *books[12][4]; michael@0: } static_bookblock; michael@0: michael@0: typedef struct { michael@0: int res_type; michael@0: int limit_type; /* 0 lowpass limited, 1 point stereo limited */ michael@0: int grouping; michael@0: const vorbis_info_residue0 *res; michael@0: const static_codebook *book_aux; michael@0: const static_codebook *book_aux_managed; michael@0: const static_bookblock *books_base; michael@0: const static_bookblock *books_base_managed; michael@0: } vorbis_residue_template; michael@0: michael@0: typedef struct { michael@0: const vorbis_info_mapping0 *map; michael@0: const vorbis_residue_template *res; michael@0: } vorbis_mapping_template; michael@0: michael@0: typedef struct vp_adjblock{ michael@0: int block[P_BANDS]; michael@0: } vp_adjblock; michael@0: michael@0: typedef struct { michael@0: int data[NOISE_COMPAND_LEVELS]; michael@0: } compandblock; michael@0: michael@0: /* high level configuration information for setting things up michael@0: step-by-step with the detailed vorbis_encode_ctl interface. michael@0: There's a fair amount of redundancy such that interactive setup michael@0: does not directly deal with any vorbis_info or codec_setup_info michael@0: initialization; it's all stored (until full init) in this highlevel michael@0: setup, then flushed out to the real codec setup structs later. */ michael@0: michael@0: typedef struct { michael@0: int att[P_NOISECURVES]; michael@0: float boost; michael@0: float decay; michael@0: } att3; michael@0: typedef struct { int data[P_NOISECURVES]; } adj3; michael@0: michael@0: typedef struct { michael@0: int pre[PACKETBLOBS]; michael@0: int post[PACKETBLOBS]; michael@0: float kHz[PACKETBLOBS]; michael@0: float lowpasskHz[PACKETBLOBS]; michael@0: } adj_stereo; michael@0: michael@0: typedef struct { michael@0: int lo; michael@0: int hi; michael@0: int fixed; michael@0: } noiseguard; michael@0: typedef struct { michael@0: int data[P_NOISECURVES][17]; michael@0: } noise3; michael@0: michael@0: typedef struct { michael@0: int mappings; michael@0: const double *rate_mapping; michael@0: const double *quality_mapping; michael@0: int coupling_restriction; michael@0: long samplerate_min_restriction; michael@0: long samplerate_max_restriction; michael@0: michael@0: michael@0: const int *blocksize_short; michael@0: const int *blocksize_long; michael@0: michael@0: const att3 *psy_tone_masteratt; michael@0: const int *psy_tone_0dB; michael@0: const int *psy_tone_dBsuppress; michael@0: michael@0: const vp_adjblock *psy_tone_adj_impulse; michael@0: const vp_adjblock *psy_tone_adj_long; michael@0: const vp_adjblock *psy_tone_adj_other; michael@0: michael@0: const noiseguard *psy_noiseguards; michael@0: const noise3 *psy_noise_bias_impulse; michael@0: const noise3 *psy_noise_bias_padding; michael@0: const noise3 *psy_noise_bias_trans; michael@0: const noise3 *psy_noise_bias_long; michael@0: const int *psy_noise_dBsuppress; michael@0: michael@0: const compandblock *psy_noise_compand; michael@0: const double *psy_noise_compand_short_mapping; michael@0: const double *psy_noise_compand_long_mapping; michael@0: michael@0: const int *psy_noise_normal_start[2]; michael@0: const int *psy_noise_normal_partition[2]; michael@0: const double *psy_noise_normal_thresh; michael@0: michael@0: const int *psy_ath_float; michael@0: const int *psy_ath_abs; michael@0: michael@0: const double *psy_lowpass; michael@0: michael@0: const vorbis_info_psy_global *global_params; michael@0: const double *global_mapping; michael@0: const adj_stereo *stereo_modes; michael@0: michael@0: const static_codebook *const *const *const floor_books; michael@0: const vorbis_info_floor1 *floor_params; michael@0: const int floor_mappings; michael@0: const int **floor_mapping_list; michael@0: michael@0: const vorbis_mapping_template *maps; michael@0: } ve_setup_data_template; michael@0: michael@0: /* a few static coder conventions */ michael@0: static const vorbis_info_mode _mode_template[2]={ michael@0: {0,0,0,0}, michael@0: {1,0,0,1} michael@0: }; michael@0: michael@0: static const vorbis_info_mapping0 _map_nominal[2]={ michael@0: {1, {0,0}, {0}, {0}, 1,{0},{1}}, michael@0: {1, {0,0}, {1}, {1}, 1,{0},{1}} michael@0: }; michael@0: michael@0: #include "modes/setup_44.h" michael@0: #include "modes/setup_44u.h" michael@0: #include "modes/setup_44p51.h" michael@0: #include "modes/setup_32.h" michael@0: #include "modes/setup_8.h" michael@0: #include "modes/setup_11.h" michael@0: #include "modes/setup_16.h" michael@0: #include "modes/setup_22.h" michael@0: #include "modes/setup_X.h" michael@0: michael@0: static const ve_setup_data_template *const setup_list[]={ michael@0: &ve_setup_44_stereo, michael@0: &ve_setup_44_51, michael@0: &ve_setup_44_uncoupled, michael@0: michael@0: &ve_setup_32_stereo, michael@0: &ve_setup_32_uncoupled, michael@0: michael@0: &ve_setup_22_stereo, michael@0: &ve_setup_22_uncoupled, michael@0: &ve_setup_16_stereo, michael@0: &ve_setup_16_uncoupled, michael@0: michael@0: &ve_setup_11_stereo, michael@0: &ve_setup_11_uncoupled, michael@0: &ve_setup_8_stereo, michael@0: &ve_setup_8_uncoupled, michael@0: michael@0: &ve_setup_X_stereo, michael@0: &ve_setup_X_uncoupled, michael@0: &ve_setup_XX_stereo, michael@0: &ve_setup_XX_uncoupled, michael@0: 0 michael@0: }; michael@0: michael@0: static void vorbis_encode_floor_setup(vorbis_info *vi,int s, michael@0: const static_codebook *const *const *const books, michael@0: const vorbis_info_floor1 *in, michael@0: const int *x){ michael@0: int i,k,is=s; michael@0: vorbis_info_floor1 *f=_ogg_calloc(1,sizeof(*f)); michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: michael@0: memcpy(f,in+x[is],sizeof(*f)); michael@0: michael@0: /* books */ michael@0: { michael@0: int partitions=f->partitions; michael@0: int maxclass=-1; michael@0: int maxbook=-1; michael@0: for(i=0;ipartitionclass[i]>maxclass)maxclass=f->partitionclass[i]; michael@0: for(i=0;i<=maxclass;i++){ michael@0: if(f->class_book[i]>maxbook)maxbook=f->class_book[i]; michael@0: f->class_book[i]+=ci->books; michael@0: for(k=0;k<(1<class_subs[i]);k++){ michael@0: if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k]; michael@0: if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books; michael@0: } michael@0: } michael@0: michael@0: for(i=0;i<=maxbook;i++) michael@0: ci->book_param[ci->books++]=(static_codebook *)books[x[is]][i]; michael@0: } michael@0: michael@0: /* for now, we're only using floor 1 */ michael@0: ci->floor_type[ci->floors]=1; michael@0: ci->floor_param[ci->floors]=f; michael@0: ci->floors++; michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s, michael@0: const vorbis_info_psy_global *in, michael@0: const double *x){ michael@0: int i,is=s; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy_global *g=&ci->psy_g_param; michael@0: michael@0: memcpy(g,in+(int)x[is],sizeof(*g)); michael@0: michael@0: ds=x[is]*(1.-ds)+x[is+1]*ds; michael@0: is=(int)ds; michael@0: ds-=is; michael@0: if(ds==0 && is>0){ michael@0: is--; michael@0: ds=1.; michael@0: } michael@0: michael@0: /* interpolate the trigger threshholds */ michael@0: for(i=0;i<4;i++){ michael@0: g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds; michael@0: g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds; michael@0: } michael@0: g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec; michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_global_stereo(vorbis_info *vi, michael@0: const highlevel_encode_setup *const hi, michael@0: const adj_stereo *p){ michael@0: float s=hi->stereo_point_setting; michael@0: int i,is=s; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy_global *g=&ci->psy_g_param; michael@0: michael@0: if(p){ michael@0: memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS); michael@0: memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS); michael@0: michael@0: if(hi->managed){ michael@0: /* interpolate the kHz threshholds */ michael@0: for(i=0;icoupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; michael@0: g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; michael@0: g->coupling_pkHz[i]=kHz; michael@0: michael@0: kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds; michael@0: g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; michael@0: g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; michael@0: michael@0: } michael@0: }else{ michael@0: float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds; michael@0: for(i=0;icoupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; michael@0: g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; michael@0: g->coupling_pkHz[i]=kHz; michael@0: } michael@0: michael@0: kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds; michael@0: for(i=0;isliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0]; michael@0: g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1]; michael@0: } michael@0: } michael@0: }else{ michael@0: for(i=0;isliding_lowpass[0][i]=ci->blocksizes[0]; michael@0: g->sliding_lowpass[1][i]=ci->blocksizes[1]; michael@0: } michael@0: } michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_psyset_setup(vorbis_info *vi,double s, michael@0: const int *nn_start, michael@0: const int *nn_partition, michael@0: const double *nn_thresh, michael@0: int block){ michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: int is=s; michael@0: michael@0: if(block>=ci->psys) michael@0: ci->psys=block+1; michael@0: if(!p){ michael@0: p=_ogg_calloc(1,sizeof(*p)); michael@0: ci->psy_param[block]=p; michael@0: } michael@0: michael@0: memcpy(p,&_psy_info_template,sizeof(*p)); michael@0: p->blockflag=block>>1; michael@0: michael@0: if(hi->noise_normalize_p){ michael@0: p->normal_p=1; michael@0: p->normal_start=nn_start[is]; michael@0: p->normal_partition=nn_partition[is]; michael@0: p->normal_thresh=nn_thresh[is]; michael@0: } michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block, michael@0: const att3 *att, michael@0: const int *max, michael@0: const vp_adjblock *in){ michael@0: int i,is=s; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: michael@0: /* 0 and 2 are only used by bitmanagement, but there's no harm to always michael@0: filling the values in here */ michael@0: p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds; michael@0: p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds; michael@0: p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds; michael@0: p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds; michael@0: p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds; michael@0: michael@0: p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds; michael@0: michael@0: for(i=0;itoneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds; michael@0: return; michael@0: } michael@0: michael@0: michael@0: static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block, michael@0: const compandblock *in, michael@0: const double *x){ michael@0: int i,is=s; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: michael@0: ds=x[is]*(1.-ds)+x[is+1]*ds; michael@0: is=(int)ds; michael@0: ds-=is; michael@0: if(ds==0 && is>0){ michael@0: is--; michael@0: ds=1.; michael@0: } michael@0: michael@0: /* interpolate the compander settings */ michael@0: for(i=0;inoisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds; michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block, michael@0: const int *suppress){ michael@0: int is=s; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: michael@0: p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds; michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block, michael@0: const int *suppress, michael@0: const noise3 *in, michael@0: const noiseguard *guard, michael@0: double userbias){ michael@0: int i,is=s,j; michael@0: double ds=s-is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: michael@0: p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds; michael@0: p->noisewindowlomin=guard[block].lo; michael@0: p->noisewindowhimin=guard[block].hi; michael@0: p->noisewindowfixed=guard[block].fixed; michael@0: michael@0: for(j=0;jnoiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds; michael@0: michael@0: /* impulse blocks may take a user specified bias to boost the michael@0: nominal/high noise encoding depth */ michael@0: for(j=0;jnoiseoff[j][0]+6; /* the lowest it can go */ michael@0: for(i=0;inoiseoff[j][i]+=userbias; michael@0: if(p->noiseoff[j][i]noiseoff[j][i]=min; michael@0: } michael@0: } michael@0: michael@0: return; michael@0: } michael@0: michael@0: static void vorbis_encode_ath_setup(vorbis_info *vi,int block){ michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: vorbis_info_psy *p=ci->psy_param[block]; michael@0: michael@0: p->ath_adjatt=ci->hi.ath_floating_dB; michael@0: p->ath_maxatt=ci->hi.ath_absolute_dB; michael@0: return; michael@0: } michael@0: michael@0: michael@0: static int book_dup_or_new(codec_setup_info *ci,const static_codebook *book){ michael@0: int i; michael@0: for(i=0;ibooks;i++) michael@0: if(ci->book_param[i]==book)return(i); michael@0: michael@0: return(ci->books++); michael@0: } michael@0: michael@0: static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s, michael@0: const int *shortb,const int *longb){ michael@0: michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: int is=s; michael@0: michael@0: int blockshort=shortb[is]; michael@0: int blocklong=longb[is]; michael@0: ci->blocksizes[0]=blockshort; michael@0: ci->blocksizes[1]=blocklong; michael@0: michael@0: } michael@0: michael@0: static void vorbis_encode_residue_setup(vorbis_info *vi, michael@0: int number, int block, michael@0: const vorbis_residue_template *res){ michael@0: michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: int i; michael@0: michael@0: vorbis_info_residue0 *r=ci->residue_param[number]= michael@0: _ogg_malloc(sizeof(*r)); michael@0: michael@0: memcpy(r,res->res,sizeof(*r)); michael@0: if(ci->residues<=number)ci->residues=number+1; michael@0: michael@0: r->grouping=res->grouping; michael@0: ci->residue_type[number]=res->res_type; michael@0: michael@0: /* fill in all the books */ michael@0: { michael@0: int booklist=0,k; michael@0: michael@0: if(ci->hi.managed){ michael@0: for(i=0;ipartitions;i++) michael@0: for(k=0;k<4;k++) michael@0: if(res->books_base_managed->books[i][k]) michael@0: r->secondstages[i]|=(1<groupbook=book_dup_or_new(ci,res->book_aux_managed); michael@0: ci->book_param[r->groupbook]=(static_codebook *)res->book_aux_managed; michael@0: michael@0: for(i=0;ipartitions;i++){ michael@0: for(k=0;k<4;k++){ michael@0: if(res->books_base_managed->books[i][k]){ michael@0: int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]); michael@0: r->booklist[booklist++]=bookid; michael@0: ci->book_param[bookid]=(static_codebook *)res->books_base_managed->books[i][k]; michael@0: } michael@0: } michael@0: } michael@0: michael@0: }else{ michael@0: michael@0: for(i=0;ipartitions;i++) michael@0: for(k=0;k<4;k++) michael@0: if(res->books_base->books[i][k]) michael@0: r->secondstages[i]|=(1<groupbook=book_dup_or_new(ci,res->book_aux); michael@0: ci->book_param[r->groupbook]=(static_codebook *)res->book_aux; michael@0: michael@0: for(i=0;ipartitions;i++){ michael@0: for(k=0;k<4;k++){ michael@0: if(res->books_base->books[i][k]){ michael@0: int bookid=book_dup_or_new(ci,res->books_base->books[i][k]); michael@0: r->booklist[booklist++]=bookid; michael@0: ci->book_param[bookid]=(static_codebook *)res->books_base->books[i][k]; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* lowpass setup/pointlimit */ michael@0: { michael@0: double freq=ci->hi.lowpass_kHz*1000.; michael@0: vorbis_info_floor1 *f=ci->floor_param[block]; /* by convention */ michael@0: double nyq=vi->rate/2.; michael@0: long blocksize=ci->blocksizes[block]>>1; michael@0: michael@0: /* lowpass needs to be set in the floor and the residue. */ michael@0: if(freq>nyq)freq=nyq; michael@0: /* in the floor, the granularity can be very fine; it doesn't alter michael@0: the encoding structure, only the samples used to fit the floor michael@0: approximation */ michael@0: f->n=freq/nyq*blocksize; michael@0: michael@0: /* this res may by limited by the maximum pointlimit of the mode, michael@0: not the lowpass. the floor is always lowpass limited. */ michael@0: switch(res->limit_type){ michael@0: case 1: /* point stereo limited */ michael@0: if(ci->hi.managed) michael@0: freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.; michael@0: else michael@0: freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.; michael@0: if(freq>nyq)freq=nyq; michael@0: break; michael@0: case 2: /* LFE channel; lowpass at ~ 250Hz */ michael@0: freq=250; michael@0: break; michael@0: default: michael@0: /* already set */ michael@0: break; michael@0: } michael@0: michael@0: /* in the residue, we're constrained, physically, by partition michael@0: boundaries. We still lowpass 'wherever', but we have to round up michael@0: here to next boundary, or the vorbis spec will round it *down* to michael@0: previous boundary in encode/decode */ michael@0: if(ci->residue_type[number]==2){ michael@0: /* residue 2 bundles together multiple channels; used by stereo michael@0: and surround. Count the channels in use */ michael@0: /* Multiple maps/submaps can point to the same residue. In the case michael@0: of residue 2, they all better have the same number of michael@0: channels/samples. */ michael@0: int j,k,ch=0; michael@0: for(i=0;imaps&&ch==0;i++){ michael@0: vorbis_info_mapping0 *mi=(vorbis_info_mapping0 *)ci->map_param[i]; michael@0: for(j=0;jsubmaps && ch==0;j++) michael@0: if(mi->residuesubmap[j]==number) /* we found a submap referencing theis residue backend */ michael@0: for(k=0;kchannels;k++) michael@0: if(mi->chmuxlist[k]==j) /* this channel belongs to the submap */ michael@0: ch++; michael@0: } michael@0: michael@0: r->end=(int)((freq/nyq*blocksize*ch)/r->grouping+.9)* /* round up only if we're well past */ michael@0: r->grouping; michael@0: /* the blocksize and grouping may disagree at the end */ michael@0: if(r->end>blocksize*ch)r->end=blocksize*ch/r->grouping*r->grouping; michael@0: michael@0: }else{ michael@0: michael@0: r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */ michael@0: r->grouping; michael@0: /* the blocksize and grouping may disagree at the end */ michael@0: if(r->end>blocksize)r->end=blocksize/r->grouping*r->grouping; michael@0: michael@0: } michael@0: michael@0: if(r->end==0)r->end=r->grouping; /* LFE channel */ michael@0: michael@0: } michael@0: } michael@0: michael@0: /* we assume two maps in this encoder */ michael@0: static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s, michael@0: const vorbis_mapping_template *maps){ michael@0: michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: int i,j,is=s,modes=2; michael@0: const vorbis_info_mapping0 *map=maps[is].map; michael@0: const vorbis_info_mode *mode=_mode_template; michael@0: const vorbis_residue_template *res=maps[is].res; michael@0: michael@0: if(ci->blocksizes[0]==ci->blocksizes[1])modes=1; michael@0: michael@0: for(i=0;imap_param[i]=_ogg_calloc(1,sizeof(*map)); michael@0: ci->mode_param[i]=_ogg_calloc(1,sizeof(*mode)); michael@0: michael@0: memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template)); michael@0: if(i>=ci->modes)ci->modes=i+1; michael@0: michael@0: ci->map_type[i]=0; michael@0: memcpy(ci->map_param[i],map+i,sizeof(*map)); michael@0: if(i>=ci->maps)ci->maps=i+1; michael@0: michael@0: for(j=0;jcodec_setup; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup; michael@0: int is=hi->base_setting; michael@0: double ds=hi->base_setting-is; michael@0: int ch=vi->channels; michael@0: const double *r=setup->rate_mapping; michael@0: michael@0: if(r==NULL) michael@0: return(-1); michael@0: michael@0: return((r[is]*(1.-ds)+r[is+1]*ds)*ch); michael@0: } michael@0: michael@0: static const void *get_setup_template(long ch,long srate, michael@0: double req,int q_or_bitrate, michael@0: double *base_setting){ michael@0: int i=0,j; michael@0: if(q_or_bitrate)req/=ch; michael@0: michael@0: while(setup_list[i]){ michael@0: if(setup_list[i]->coupling_restriction==-1 || michael@0: setup_list[i]->coupling_restriction==ch){ michael@0: if(srate>=setup_list[i]->samplerate_min_restriction && michael@0: srate<=setup_list[i]->samplerate_max_restriction){ michael@0: int mappings=setup_list[i]->mappings; michael@0: const double *map=(q_or_bitrate? michael@0: setup_list[i]->rate_mapping: michael@0: setup_list[i]->quality_mapping); michael@0: michael@0: /* the template matches. Does the requested quality mode michael@0: fall within this template's modes? */ michael@0: if(reqmap[setup_list[i]->mappings]){++i;continue;} michael@0: for(j=0;j=map[j] && reqcodec_setup; michael@0: ve_setup_data_template *setup=NULL; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: michael@0: if(ci==NULL)return(OV_EINVAL); michael@0: if(!hi->impulse_block_p)i0=1; michael@0: michael@0: /* too low/high an ATH floater is nonsensical, but doesn't break anything */ michael@0: if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80; michael@0: if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200; michael@0: michael@0: /* again, bound this to avoid the app shooting itself int he foot michael@0: too badly */ michael@0: if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.; michael@0: if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.; michael@0: michael@0: /* get the appropriate setup template; matches the fetch in previous michael@0: stages */ michael@0: setup=(ve_setup_data_template *)hi->setup; michael@0: if(setup==NULL)return(OV_EINVAL); michael@0: michael@0: hi->set_in_stone=1; michael@0: /* choose block sizes from configured sizes as well as paying michael@0: attention to long_block_p and short_block_p. If the configured michael@0: short and long blocks are the same length, we set long_block_p michael@0: and unset short_block_p */ michael@0: vorbis_encode_blocksize_setup(vi,hi->base_setting, michael@0: setup->blocksize_short, michael@0: setup->blocksize_long); michael@0: if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1; michael@0: michael@0: /* floor setup; choose proper floor params. Allocated on the floor michael@0: stack in order; if we alloc only a single long floor, it's 0 */ michael@0: for(i=0;ifloor_mappings;i++) michael@0: vorbis_encode_floor_setup(vi,hi->base_setting, michael@0: setup->floor_books, michael@0: setup->floor_params, michael@0: setup->floor_mapping_list[i]); michael@0: michael@0: /* setup of [mostly] short block detection and stereo*/ michael@0: vorbis_encode_global_psych_setup(vi,hi->trigger_setting, michael@0: setup->global_params, michael@0: setup->global_mapping); michael@0: vorbis_encode_global_stereo(vi,hi,setup->stereo_modes); michael@0: michael@0: /* basic psych setup and noise normalization */ michael@0: vorbis_encode_psyset_setup(vi,hi->base_setting, michael@0: setup->psy_noise_normal_start[0], michael@0: setup->psy_noise_normal_partition[0], michael@0: setup->psy_noise_normal_thresh, michael@0: 0); michael@0: vorbis_encode_psyset_setup(vi,hi->base_setting, michael@0: setup->psy_noise_normal_start[0], michael@0: setup->psy_noise_normal_partition[0], michael@0: setup->psy_noise_normal_thresh, michael@0: 1); michael@0: if(!singleblock){ michael@0: vorbis_encode_psyset_setup(vi,hi->base_setting, michael@0: setup->psy_noise_normal_start[1], michael@0: setup->psy_noise_normal_partition[1], michael@0: setup->psy_noise_normal_thresh, michael@0: 2); michael@0: vorbis_encode_psyset_setup(vi,hi->base_setting, michael@0: setup->psy_noise_normal_start[1], michael@0: setup->psy_noise_normal_partition[1], michael@0: setup->psy_noise_normal_thresh, michael@0: 3); michael@0: } michael@0: michael@0: /* tone masking setup */ michael@0: vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0, michael@0: setup->psy_tone_masteratt, michael@0: setup->psy_tone_0dB, michael@0: setup->psy_tone_adj_impulse); michael@0: vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1, michael@0: setup->psy_tone_masteratt, michael@0: setup->psy_tone_0dB, michael@0: setup->psy_tone_adj_other); michael@0: if(!singleblock){ michael@0: vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2, michael@0: setup->psy_tone_masteratt, michael@0: setup->psy_tone_0dB, michael@0: setup->psy_tone_adj_other); michael@0: vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3, michael@0: setup->psy_tone_masteratt, michael@0: setup->psy_tone_0dB, michael@0: setup->psy_tone_adj_long); michael@0: } michael@0: michael@0: /* noise companding setup */ michael@0: vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0, michael@0: setup->psy_noise_compand, michael@0: setup->psy_noise_compand_short_mapping); michael@0: vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1, michael@0: setup->psy_noise_compand, michael@0: setup->psy_noise_compand_short_mapping); michael@0: if(!singleblock){ michael@0: vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2, michael@0: setup->psy_noise_compand, michael@0: setup->psy_noise_compand_long_mapping); michael@0: vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3, michael@0: setup->psy_noise_compand, michael@0: setup->psy_noise_compand_long_mapping); michael@0: } michael@0: michael@0: /* peak guarding setup */ michael@0: vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0, michael@0: setup->psy_tone_dBsuppress); michael@0: vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1, michael@0: setup->psy_tone_dBsuppress); michael@0: if(!singleblock){ michael@0: vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2, michael@0: setup->psy_tone_dBsuppress); michael@0: vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3, michael@0: setup->psy_tone_dBsuppress); michael@0: } michael@0: michael@0: /* noise bias setup */ michael@0: vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0, michael@0: setup->psy_noise_dBsuppress, michael@0: setup->psy_noise_bias_impulse, michael@0: setup->psy_noiseguards, michael@0: (i0==0?hi->impulse_noisetune:0.)); michael@0: vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1, michael@0: setup->psy_noise_dBsuppress, michael@0: setup->psy_noise_bias_padding, michael@0: setup->psy_noiseguards,0.); michael@0: if(!singleblock){ michael@0: vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2, michael@0: setup->psy_noise_dBsuppress, michael@0: setup->psy_noise_bias_trans, michael@0: setup->psy_noiseguards,0.); michael@0: vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3, michael@0: setup->psy_noise_dBsuppress, michael@0: setup->psy_noise_bias_long, michael@0: setup->psy_noiseguards,0.); michael@0: } michael@0: michael@0: vorbis_encode_ath_setup(vi,0); michael@0: vorbis_encode_ath_setup(vi,1); michael@0: if(!singleblock){ michael@0: vorbis_encode_ath_setup(vi,2); michael@0: vorbis_encode_ath_setup(vi,3); michael@0: } michael@0: michael@0: vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps); michael@0: michael@0: /* set bitrate readonlies and management */ michael@0: if(hi->bitrate_av>0) michael@0: vi->bitrate_nominal=hi->bitrate_av; michael@0: else{ michael@0: vi->bitrate_nominal=setting_to_approx_bitrate(vi); michael@0: } michael@0: michael@0: vi->bitrate_lower=hi->bitrate_min; michael@0: vi->bitrate_upper=hi->bitrate_max; michael@0: if(hi->bitrate_av) michael@0: vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av; michael@0: else michael@0: vi->bitrate_window=0.; michael@0: michael@0: if(hi->managed){ michael@0: ci->bi.avg_rate=hi->bitrate_av; michael@0: ci->bi.min_rate=hi->bitrate_min; michael@0: ci->bi.max_rate=hi->bitrate_max; michael@0: michael@0: ci->bi.reservoir_bits=hi->bitrate_reservoir; michael@0: ci->bi.reservoir_bias= michael@0: hi->bitrate_reservoir_bias; michael@0: michael@0: ci->bi.slew_damp=hi->bitrate_av_damp; michael@0: michael@0: } michael@0: michael@0: return(0); michael@0: michael@0: } michael@0: michael@0: static void vorbis_encode_setup_setting(vorbis_info *vi, michael@0: long channels, michael@0: long rate){ michael@0: int i,is; michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: const ve_setup_data_template *setup=hi->setup; michael@0: double ds; michael@0: michael@0: vi->version=0; michael@0: vi->channels=channels; michael@0: vi->rate=rate; michael@0: michael@0: hi->impulse_block_p=1; michael@0: hi->noise_normalize_p=1; michael@0: michael@0: is=hi->base_setting; michael@0: ds=hi->base_setting-is; michael@0: michael@0: hi->stereo_point_setting=hi->base_setting; michael@0: michael@0: if(!hi->lowpass_altered) michael@0: hi->lowpass_kHz= michael@0: setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds; michael@0: michael@0: hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+ michael@0: setup->psy_ath_float[is+1]*ds; michael@0: hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+ michael@0: setup->psy_ath_abs[is+1]*ds; michael@0: michael@0: hi->amplitude_track_dBpersec=-6.; michael@0: hi->trigger_setting=hi->base_setting; michael@0: michael@0: for(i=0;i<4;i++){ michael@0: hi->block[i].tone_mask_setting=hi->base_setting; michael@0: hi->block[i].tone_peaklimit_setting=hi->base_setting; michael@0: hi->block[i].noise_bias_setting=hi->base_setting; michael@0: hi->block[i].noise_compand_setting=hi->base_setting; michael@0: } michael@0: } michael@0: michael@0: int vorbis_encode_setup_vbr(vorbis_info *vi, michael@0: long channels, michael@0: long rate, michael@0: float quality){ michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: michael@0: quality+=.0000001; michael@0: if(quality>=1.)quality=.9999; michael@0: michael@0: hi->req=quality; michael@0: hi->setup=get_setup_template(channels,rate,quality,0,&hi->base_setting); michael@0: if(!hi->setup)return OV_EIMPL; michael@0: michael@0: vorbis_encode_setup_setting(vi,channels,rate); michael@0: hi->managed=0; michael@0: hi->coupling_p=1; michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: int vorbis_encode_init_vbr(vorbis_info *vi, michael@0: long channels, michael@0: long rate, michael@0: michael@0: float base_quality /* 0. to 1. */ michael@0: ){ michael@0: int ret=0; michael@0: michael@0: ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality); michael@0: michael@0: if(ret){ michael@0: vorbis_info_clear(vi); michael@0: return ret; michael@0: } michael@0: ret=vorbis_encode_setup_init(vi); michael@0: if(ret) michael@0: vorbis_info_clear(vi); michael@0: return(ret); michael@0: } michael@0: michael@0: int vorbis_encode_setup_managed(vorbis_info *vi, michael@0: long channels, michael@0: long rate, michael@0: michael@0: long max_bitrate, michael@0: long nominal_bitrate, michael@0: long min_bitrate){ michael@0: michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: double tnominal=nominal_bitrate; michael@0: michael@0: if(nominal_bitrate<=0.){ michael@0: if(max_bitrate>0.){ michael@0: if(min_bitrate>0.) michael@0: nominal_bitrate=(max_bitrate+min_bitrate)*.5; michael@0: else michael@0: nominal_bitrate=max_bitrate*.875; michael@0: }else{ michael@0: if(min_bitrate>0.){ michael@0: nominal_bitrate=min_bitrate; michael@0: }else{ michael@0: return(OV_EINVAL); michael@0: } michael@0: } michael@0: } michael@0: michael@0: hi->req=nominal_bitrate; michael@0: hi->setup=get_setup_template(channels,rate,nominal_bitrate,1,&hi->base_setting); michael@0: if(!hi->setup)return OV_EIMPL; michael@0: michael@0: vorbis_encode_setup_setting(vi,channels,rate); michael@0: michael@0: /* initialize management with sane defaults */ michael@0: hi->coupling_p=1; michael@0: hi->managed=1; michael@0: hi->bitrate_min=min_bitrate; michael@0: hi->bitrate_max=max_bitrate; michael@0: hi->bitrate_av=tnominal; michael@0: hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */ michael@0: hi->bitrate_reservoir=nominal_bitrate*2; michael@0: hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */ michael@0: michael@0: return(0); michael@0: michael@0: } michael@0: michael@0: int vorbis_encode_init(vorbis_info *vi, michael@0: long channels, michael@0: long rate, michael@0: michael@0: long max_bitrate, michael@0: long nominal_bitrate, michael@0: long min_bitrate){ michael@0: michael@0: int ret=vorbis_encode_setup_managed(vi,channels,rate, michael@0: max_bitrate, michael@0: nominal_bitrate, michael@0: min_bitrate); michael@0: if(ret){ michael@0: vorbis_info_clear(vi); michael@0: return(ret); michael@0: } michael@0: michael@0: ret=vorbis_encode_setup_init(vi); michael@0: if(ret) michael@0: vorbis_info_clear(vi); michael@0: return(ret); michael@0: } michael@0: michael@0: int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){ michael@0: if(vi){ michael@0: codec_setup_info *ci=vi->codec_setup; michael@0: highlevel_encode_setup *hi=&ci->hi; michael@0: int setp=(number&0xf); /* a read request has a low nibble of 0 */ michael@0: michael@0: if(setp && hi->set_in_stone)return(OV_EINVAL); michael@0: michael@0: switch(number){ michael@0: michael@0: /* now deprecated *****************/ michael@0: case OV_ECTL_RATEMANAGE_GET: michael@0: { michael@0: michael@0: struct ovectl_ratemanage_arg *ai= michael@0: (struct ovectl_ratemanage_arg *)arg; michael@0: michael@0: ai->management_active=hi->managed; michael@0: ai->bitrate_hard_window=ai->bitrate_av_window= michael@0: (double)hi->bitrate_reservoir/vi->rate; michael@0: ai->bitrate_av_window_center=1.; michael@0: ai->bitrate_hard_min=hi->bitrate_min; michael@0: ai->bitrate_hard_max=hi->bitrate_max; michael@0: ai->bitrate_av_lo=hi->bitrate_av; michael@0: ai->bitrate_av_hi=hi->bitrate_av; michael@0: michael@0: } michael@0: return(0); michael@0: michael@0: /* now deprecated *****************/ michael@0: case OV_ECTL_RATEMANAGE_SET: michael@0: { michael@0: struct ovectl_ratemanage_arg *ai= michael@0: (struct ovectl_ratemanage_arg *)arg; michael@0: if(ai==NULL){ michael@0: hi->managed=0; michael@0: }else{ michael@0: hi->managed=ai->management_active; michael@0: vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg); michael@0: vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg); michael@0: } michael@0: } michael@0: return 0; michael@0: michael@0: /* now deprecated *****************/ michael@0: case OV_ECTL_RATEMANAGE_AVG: michael@0: { michael@0: struct ovectl_ratemanage_arg *ai= michael@0: (struct ovectl_ratemanage_arg *)arg; michael@0: if(ai==NULL){ michael@0: hi->bitrate_av=0; michael@0: }else{ michael@0: hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5; michael@0: } michael@0: } michael@0: return(0); michael@0: /* now deprecated *****************/ michael@0: case OV_ECTL_RATEMANAGE_HARD: michael@0: { michael@0: struct ovectl_ratemanage_arg *ai= michael@0: (struct ovectl_ratemanage_arg *)arg; michael@0: if(ai==NULL){ michael@0: hi->bitrate_min=0; michael@0: hi->bitrate_max=0; michael@0: }else{ michael@0: hi->bitrate_min=ai->bitrate_hard_min; michael@0: hi->bitrate_max=ai->bitrate_hard_max; michael@0: hi->bitrate_reservoir=ai->bitrate_hard_window* michael@0: (hi->bitrate_max+hi->bitrate_min)*.5; michael@0: } michael@0: if(hi->bitrate_reservoir<128.) michael@0: hi->bitrate_reservoir=128.; michael@0: } michael@0: return(0); michael@0: michael@0: /* replacement ratemanage interface */ michael@0: case OV_ECTL_RATEMANAGE2_GET: michael@0: { michael@0: struct ovectl_ratemanage2_arg *ai= michael@0: (struct ovectl_ratemanage2_arg *)arg; michael@0: if(ai==NULL)return OV_EINVAL; michael@0: michael@0: ai->management_active=hi->managed; michael@0: ai->bitrate_limit_min_kbps=hi->bitrate_min/1000; michael@0: ai->bitrate_limit_max_kbps=hi->bitrate_max/1000; michael@0: ai->bitrate_average_kbps=hi->bitrate_av/1000; michael@0: ai->bitrate_average_damping=hi->bitrate_av_damp; michael@0: ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir; michael@0: ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias; michael@0: } michael@0: return (0); michael@0: case OV_ECTL_RATEMANAGE2_SET: michael@0: { michael@0: struct ovectl_ratemanage2_arg *ai= michael@0: (struct ovectl_ratemanage2_arg *)arg; michael@0: if(ai==NULL){ michael@0: hi->managed=0; michael@0: }else{ michael@0: /* sanity check; only catch invariant violations */ michael@0: if(ai->bitrate_limit_min_kbps>0 && michael@0: ai->bitrate_average_kbps>0 && michael@0: ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_limit_max_kbps>0 && michael@0: ai->bitrate_average_kbps>0 && michael@0: ai->bitrate_limit_max_kbpsbitrate_average_kbps) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_limit_min_kbps>0 && michael@0: ai->bitrate_limit_max_kbps>0 && michael@0: ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_average_damping <= 0.) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_limit_reservoir_bits < 0) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_limit_reservoir_bias < 0.) michael@0: return OV_EINVAL; michael@0: michael@0: if(ai->bitrate_limit_reservoir_bias > 1.) michael@0: return OV_EINVAL; michael@0: michael@0: hi->managed=ai->management_active; michael@0: hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000; michael@0: hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000; michael@0: hi->bitrate_av=ai->bitrate_average_kbps * 1000; michael@0: hi->bitrate_av_damp=ai->bitrate_average_damping; michael@0: hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits; michael@0: hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias; michael@0: } michael@0: } michael@0: return 0; michael@0: michael@0: case OV_ECTL_LOWPASS_GET: michael@0: { michael@0: double *farg=(double *)arg; michael@0: *farg=hi->lowpass_kHz; michael@0: } michael@0: return(0); michael@0: case OV_ECTL_LOWPASS_SET: michael@0: { michael@0: double *farg=(double *)arg; michael@0: hi->lowpass_kHz=*farg; michael@0: michael@0: if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.; michael@0: if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.; michael@0: hi->lowpass_altered=1; michael@0: } michael@0: return(0); michael@0: case OV_ECTL_IBLOCK_GET: michael@0: { michael@0: double *farg=(double *)arg; michael@0: *farg=hi->impulse_noisetune; michael@0: } michael@0: return(0); michael@0: case OV_ECTL_IBLOCK_SET: michael@0: { michael@0: double *farg=(double *)arg; michael@0: hi->impulse_noisetune=*farg; michael@0: michael@0: if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.; michael@0: if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.; michael@0: } michael@0: return(0); michael@0: case OV_ECTL_COUPLING_GET: michael@0: { michael@0: int *iarg=(int *)arg; michael@0: *iarg=hi->coupling_p; michael@0: } michael@0: return(0); michael@0: case OV_ECTL_COUPLING_SET: michael@0: { michael@0: const void *new_template; michael@0: double new_base=0.; michael@0: int *iarg=(int *)arg; michael@0: hi->coupling_p=((*iarg)!=0); michael@0: michael@0: /* Fetching a new template can alter the base_setting, which michael@0: many other parameters are based on. Right now, the only michael@0: parameter drawn from the base_setting that can be altered michael@0: by an encctl is the lowpass, so that is explictly flagged michael@0: to not be overwritten when we fetch a new template and michael@0: recompute the dependant settings */ michael@0: new_template = get_setup_template(hi->coupling_p?vi->channels:-1, michael@0: vi->rate, michael@0: hi->req, michael@0: hi->managed, michael@0: &new_base); michael@0: if(!hi->setup)return OV_EIMPL; michael@0: hi->setup=new_template; michael@0: hi->base_setting=new_base; michael@0: vorbis_encode_setup_setting(vi,vi->channels,vi->rate); michael@0: } michael@0: return(0); michael@0: } michael@0: return(OV_EIMPL); michael@0: } michael@0: return(OV_EINVAL); michael@0: }