Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * |
michael@0 | 9 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: psychoacoustics not including preecho |
michael@0 | 14 | last mod: $Id: psy.c 18077 2011-09-02 02:49:00Z giles $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #include <stdlib.h> |
michael@0 | 19 | #include <math.h> |
michael@0 | 20 | #include <string.h> |
michael@0 | 21 | #include "vorbis/codec.h" |
michael@0 | 22 | #include "codec_internal.h" |
michael@0 | 23 | |
michael@0 | 24 | #include "masking.h" |
michael@0 | 25 | #include "psy.h" |
michael@0 | 26 | #include "os.h" |
michael@0 | 27 | #include "lpc.h" |
michael@0 | 28 | #include "smallft.h" |
michael@0 | 29 | #include "scales.h" |
michael@0 | 30 | #include "misc.h" |
michael@0 | 31 | |
michael@0 | 32 | #define NEGINF -9999.f |
michael@0 | 33 | static const double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10}; |
michael@0 | 34 | static const double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10}; |
michael@0 | 35 | |
michael@0 | 36 | vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){ |
michael@0 | 37 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 38 | vorbis_info_psy_global *gi=&ci->psy_g_param; |
michael@0 | 39 | vorbis_look_psy_global *look=_ogg_calloc(1,sizeof(*look)); |
michael@0 | 40 | |
michael@0 | 41 | look->channels=vi->channels; |
michael@0 | 42 | |
michael@0 | 43 | look->ampmax=-9999.; |
michael@0 | 44 | look->gi=gi; |
michael@0 | 45 | return(look); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void _vp_global_free(vorbis_look_psy_global *look){ |
michael@0 | 49 | if(look){ |
michael@0 | 50 | memset(look,0,sizeof(*look)); |
michael@0 | 51 | _ogg_free(look); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | void _vi_gpsy_free(vorbis_info_psy_global *i){ |
michael@0 | 56 | if(i){ |
michael@0 | 57 | memset(i,0,sizeof(*i)); |
michael@0 | 58 | _ogg_free(i); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | void _vi_psy_free(vorbis_info_psy *i){ |
michael@0 | 63 | if(i){ |
michael@0 | 64 | memset(i,0,sizeof(*i)); |
michael@0 | 65 | _ogg_free(i); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | static void min_curve(float *c, |
michael@0 | 70 | float *c2){ |
michael@0 | 71 | int i; |
michael@0 | 72 | for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i]; |
michael@0 | 73 | } |
michael@0 | 74 | static void max_curve(float *c, |
michael@0 | 75 | float *c2){ |
michael@0 | 76 | int i; |
michael@0 | 77 | for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i]; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | static void attenuate_curve(float *c,float att){ |
michael@0 | 81 | int i; |
michael@0 | 82 | for(i=0;i<EHMER_MAX;i++) |
michael@0 | 83 | c[i]+=att; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n, |
michael@0 | 87 | float center_boost, float center_decay_rate){ |
michael@0 | 88 | int i,j,k,m; |
michael@0 | 89 | float ath[EHMER_MAX]; |
michael@0 | 90 | float workc[P_BANDS][P_LEVELS][EHMER_MAX]; |
michael@0 | 91 | float athc[P_LEVELS][EHMER_MAX]; |
michael@0 | 92 | float *brute_buffer=alloca(n*sizeof(*brute_buffer)); |
michael@0 | 93 | |
michael@0 | 94 | float ***ret=_ogg_malloc(sizeof(*ret)*P_BANDS); |
michael@0 | 95 | |
michael@0 | 96 | memset(workc,0,sizeof(workc)); |
michael@0 | 97 | |
michael@0 | 98 | for(i=0;i<P_BANDS;i++){ |
michael@0 | 99 | /* we add back in the ATH to avoid low level curves falling off to |
michael@0 | 100 | -infinity and unnecessarily cutting off high level curves in the |
michael@0 | 101 | curve limiting (last step). */ |
michael@0 | 102 | |
michael@0 | 103 | /* A half-band's settings must be valid over the whole band, and |
michael@0 | 104 | it's better to mask too little than too much */ |
michael@0 | 105 | int ath_offset=i*4; |
michael@0 | 106 | for(j=0;j<EHMER_MAX;j++){ |
michael@0 | 107 | float min=999.; |
michael@0 | 108 | for(k=0;k<4;k++) |
michael@0 | 109 | if(j+k+ath_offset<MAX_ATH){ |
michael@0 | 110 | if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset]; |
michael@0 | 111 | }else{ |
michael@0 | 112 | if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1]; |
michael@0 | 113 | } |
michael@0 | 114 | ath[j]=min; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | /* copy curves into working space, replicate the 50dB curve to 30 |
michael@0 | 118 | and 40, replicate the 100dB curve to 110 */ |
michael@0 | 119 | for(j=0;j<6;j++) |
michael@0 | 120 | memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j])); |
michael@0 | 121 | memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0])); |
michael@0 | 122 | memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0])); |
michael@0 | 123 | |
michael@0 | 124 | /* apply centered curve boost/decay */ |
michael@0 | 125 | for(j=0;j<P_LEVELS;j++){ |
michael@0 | 126 | for(k=0;k<EHMER_MAX;k++){ |
michael@0 | 127 | float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate; |
michael@0 | 128 | if(adj<0. && center_boost>0)adj=0.; |
michael@0 | 129 | if(adj>0. && center_boost<0)adj=0.; |
michael@0 | 130 | workc[i][j][k]+=adj; |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | /* normalize curves so the driving amplitude is 0dB */ |
michael@0 | 135 | /* make temp curves with the ATH overlayed */ |
michael@0 | 136 | for(j=0;j<P_LEVELS;j++){ |
michael@0 | 137 | attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0); |
michael@0 | 138 | memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc)); |
michael@0 | 139 | attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0); |
michael@0 | 140 | max_curve(athc[j],workc[i][j]); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | /* Now limit the louder curves. |
michael@0 | 144 | |
michael@0 | 145 | the idea is this: We don't know what the playback attenuation |
michael@0 | 146 | will be; 0dB SL moves every time the user twiddles the volume |
michael@0 | 147 | knob. So that means we have to use a single 'most pessimal' curve |
michael@0 | 148 | for all masking amplitudes, right? Wrong. The *loudest* sound |
michael@0 | 149 | can be in (we assume) a range of ...+100dB] SL. However, sounds |
michael@0 | 150 | 20dB down will be in a range ...+80], 40dB down is from ...+60], |
michael@0 | 151 | etc... */ |
michael@0 | 152 | |
michael@0 | 153 | for(j=1;j<P_LEVELS;j++){ |
michael@0 | 154 | min_curve(athc[j],athc[j-1]); |
michael@0 | 155 | min_curve(workc[i][j],athc[j]); |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | for(i=0;i<P_BANDS;i++){ |
michael@0 | 160 | int hi_curve,lo_curve,bin; |
michael@0 | 161 | ret[i]=_ogg_malloc(sizeof(**ret)*P_LEVELS); |
michael@0 | 162 | |
michael@0 | 163 | /* low frequency curves are measured with greater resolution than |
michael@0 | 164 | the MDCT/FFT will actually give us; we want the curve applied |
michael@0 | 165 | to the tone data to be pessimistic and thus apply the minimum |
michael@0 | 166 | masking possible for a given bin. That means that a single bin |
michael@0 | 167 | could span more than one octave and that the curve will be a |
michael@0 | 168 | composite of multiple octaves. It also may mean that a single |
michael@0 | 169 | bin may span > an eighth of an octave and that the eighth |
michael@0 | 170 | octave values may also be composited. */ |
michael@0 | 171 | |
michael@0 | 172 | /* which octave curves will we be compositing? */ |
michael@0 | 173 | bin=floor(fromOC(i*.5)/binHz); |
michael@0 | 174 | lo_curve= ceil(toOC(bin*binHz+1)*2); |
michael@0 | 175 | hi_curve= floor(toOC((bin+1)*binHz)*2); |
michael@0 | 176 | if(lo_curve>i)lo_curve=i; |
michael@0 | 177 | if(lo_curve<0)lo_curve=0; |
michael@0 | 178 | if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1; |
michael@0 | 179 | |
michael@0 | 180 | for(m=0;m<P_LEVELS;m++){ |
michael@0 | 181 | ret[i][m]=_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2)); |
michael@0 | 182 | |
michael@0 | 183 | for(j=0;j<n;j++)brute_buffer[j]=999.; |
michael@0 | 184 | |
michael@0 | 185 | /* render the curve into bins, then pull values back into curve. |
michael@0 | 186 | The point is that any inherent subsampling aliasing results in |
michael@0 | 187 | a safe minimum */ |
michael@0 | 188 | for(k=lo_curve;k<=hi_curve;k++){ |
michael@0 | 189 | int l=0; |
michael@0 | 190 | |
michael@0 | 191 | for(j=0;j<EHMER_MAX;j++){ |
michael@0 | 192 | int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz; |
michael@0 | 193 | int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1; |
michael@0 | 194 | |
michael@0 | 195 | if(lo_bin<0)lo_bin=0; |
michael@0 | 196 | if(lo_bin>n)lo_bin=n; |
michael@0 | 197 | if(lo_bin<l)l=lo_bin; |
michael@0 | 198 | if(hi_bin<0)hi_bin=0; |
michael@0 | 199 | if(hi_bin>n)hi_bin=n; |
michael@0 | 200 | |
michael@0 | 201 | for(;l<hi_bin && l<n;l++) |
michael@0 | 202 | if(brute_buffer[l]>workc[k][m][j]) |
michael@0 | 203 | brute_buffer[l]=workc[k][m][j]; |
michael@0 | 204 | } |
michael@0 | 205 | |
michael@0 | 206 | for(;l<n;l++) |
michael@0 | 207 | if(brute_buffer[l]>workc[k][m][EHMER_MAX-1]) |
michael@0 | 208 | brute_buffer[l]=workc[k][m][EHMER_MAX-1]; |
michael@0 | 209 | |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | /* be equally paranoid about being valid up to next half ocatve */ |
michael@0 | 213 | if(i+1<P_BANDS){ |
michael@0 | 214 | int l=0; |
michael@0 | 215 | k=i+1; |
michael@0 | 216 | for(j=0;j<EHMER_MAX;j++){ |
michael@0 | 217 | int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz; |
michael@0 | 218 | int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1; |
michael@0 | 219 | |
michael@0 | 220 | if(lo_bin<0)lo_bin=0; |
michael@0 | 221 | if(lo_bin>n)lo_bin=n; |
michael@0 | 222 | if(lo_bin<l)l=lo_bin; |
michael@0 | 223 | if(hi_bin<0)hi_bin=0; |
michael@0 | 224 | if(hi_bin>n)hi_bin=n; |
michael@0 | 225 | |
michael@0 | 226 | for(;l<hi_bin && l<n;l++) |
michael@0 | 227 | if(brute_buffer[l]>workc[k][m][j]) |
michael@0 | 228 | brute_buffer[l]=workc[k][m][j]; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | for(;l<n;l++) |
michael@0 | 232 | if(brute_buffer[l]>workc[k][m][EHMER_MAX-1]) |
michael@0 | 233 | brute_buffer[l]=workc[k][m][EHMER_MAX-1]; |
michael@0 | 234 | |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | |
michael@0 | 238 | for(j=0;j<EHMER_MAX;j++){ |
michael@0 | 239 | int bin=fromOC(j*.125+i*.5-2.)/binHz; |
michael@0 | 240 | if(bin<0){ |
michael@0 | 241 | ret[i][m][j+2]=-999.; |
michael@0 | 242 | }else{ |
michael@0 | 243 | if(bin>=n){ |
michael@0 | 244 | ret[i][m][j+2]=-999.; |
michael@0 | 245 | }else{ |
michael@0 | 246 | ret[i][m][j+2]=brute_buffer[bin]; |
michael@0 | 247 | } |
michael@0 | 248 | } |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | /* add fenceposts */ |
michael@0 | 252 | for(j=0;j<EHMER_OFFSET;j++) |
michael@0 | 253 | if(ret[i][m][j+2]>-200.f)break; |
michael@0 | 254 | ret[i][m][0]=j; |
michael@0 | 255 | |
michael@0 | 256 | for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--) |
michael@0 | 257 | if(ret[i][m][j+2]>-200.f) |
michael@0 | 258 | break; |
michael@0 | 259 | ret[i][m][1]=j; |
michael@0 | 260 | |
michael@0 | 261 | } |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | return(ret); |
michael@0 | 265 | } |
michael@0 | 266 | |
michael@0 | 267 | void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi, |
michael@0 | 268 | vorbis_info_psy_global *gi,int n,long rate){ |
michael@0 | 269 | long i,j,lo=-99,hi=1; |
michael@0 | 270 | long maxoc; |
michael@0 | 271 | memset(p,0,sizeof(*p)); |
michael@0 | 272 | |
michael@0 | 273 | p->eighth_octave_lines=gi->eighth_octave_lines; |
michael@0 | 274 | p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1; |
michael@0 | 275 | |
michael@0 | 276 | p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines; |
michael@0 | 277 | maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f; |
michael@0 | 278 | p->total_octave_lines=maxoc-p->firstoc+1; |
michael@0 | 279 | p->ath=_ogg_malloc(n*sizeof(*p->ath)); |
michael@0 | 280 | |
michael@0 | 281 | p->octave=_ogg_malloc(n*sizeof(*p->octave)); |
michael@0 | 282 | p->bark=_ogg_malloc(n*sizeof(*p->bark)); |
michael@0 | 283 | p->vi=vi; |
michael@0 | 284 | p->n=n; |
michael@0 | 285 | p->rate=rate; |
michael@0 | 286 | |
michael@0 | 287 | /* AoTuV HF weighting */ |
michael@0 | 288 | p->m_val = 1.; |
michael@0 | 289 | if(rate < 26000) p->m_val = 0; |
michael@0 | 290 | else if(rate < 38000) p->m_val = .94; /* 32kHz */ |
michael@0 | 291 | else if(rate > 46000) p->m_val = 1.275; /* 48kHz */ |
michael@0 | 292 | |
michael@0 | 293 | /* set up the lookups for a given blocksize and sample rate */ |
michael@0 | 294 | |
michael@0 | 295 | for(i=0,j=0;i<MAX_ATH-1;i++){ |
michael@0 | 296 | int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate); |
michael@0 | 297 | float base=ATH[i]; |
michael@0 | 298 | if(j<endpos){ |
michael@0 | 299 | float delta=(ATH[i+1]-base)/(endpos-j); |
michael@0 | 300 | for(;j<endpos && j<n;j++){ |
michael@0 | 301 | p->ath[j]=base+100.; |
michael@0 | 302 | base+=delta; |
michael@0 | 303 | } |
michael@0 | 304 | } |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | for(;j<n;j++){ |
michael@0 | 308 | p->ath[j]=p->ath[j-1]; |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | for(i=0;i<n;i++){ |
michael@0 | 312 | float bark=toBARK(rate/(2*n)*i); |
michael@0 | 313 | |
michael@0 | 314 | for(;lo+vi->noisewindowlomin<i && |
michael@0 | 315 | toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++); |
michael@0 | 316 | |
michael@0 | 317 | for(;hi<=n && (hi<i+vi->noisewindowhimin || |
michael@0 | 318 | toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++); |
michael@0 | 319 | |
michael@0 | 320 | p->bark[i]=((lo-1)<<16)+(hi-1); |
michael@0 | 321 | |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | for(i=0;i<n;i++) |
michael@0 | 325 | p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f; |
michael@0 | 326 | |
michael@0 | 327 | p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n, |
michael@0 | 328 | vi->tone_centerboost,vi->tone_decay); |
michael@0 | 329 | |
michael@0 | 330 | /* set up rolling noise median */ |
michael@0 | 331 | p->noiseoffset=_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset)); |
michael@0 | 332 | for(i=0;i<P_NOISECURVES;i++) |
michael@0 | 333 | p->noiseoffset[i]=_ogg_malloc(n*sizeof(**p->noiseoffset)); |
michael@0 | 334 | |
michael@0 | 335 | for(i=0;i<n;i++){ |
michael@0 | 336 | float halfoc=toOC((i+.5)*rate/(2.*n))*2.; |
michael@0 | 337 | int inthalfoc; |
michael@0 | 338 | float del; |
michael@0 | 339 | |
michael@0 | 340 | if(halfoc<0)halfoc=0; |
michael@0 | 341 | if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1; |
michael@0 | 342 | inthalfoc=(int)halfoc; |
michael@0 | 343 | del=halfoc-inthalfoc; |
michael@0 | 344 | |
michael@0 | 345 | for(j=0;j<P_NOISECURVES;j++) |
michael@0 | 346 | p->noiseoffset[j][i]= |
michael@0 | 347 | p->vi->noiseoff[j][inthalfoc]*(1.-del) + |
michael@0 | 348 | p->vi->noiseoff[j][inthalfoc+1]*del; |
michael@0 | 349 | |
michael@0 | 350 | } |
michael@0 | 351 | #if 0 |
michael@0 | 352 | { |
michael@0 | 353 | static int ls=0; |
michael@0 | 354 | _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0); |
michael@0 | 355 | _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0); |
michael@0 | 356 | _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0); |
michael@0 | 357 | } |
michael@0 | 358 | #endif |
michael@0 | 359 | } |
michael@0 | 360 | |
michael@0 | 361 | void _vp_psy_clear(vorbis_look_psy *p){ |
michael@0 | 362 | int i,j; |
michael@0 | 363 | if(p){ |
michael@0 | 364 | if(p->ath)_ogg_free(p->ath); |
michael@0 | 365 | if(p->octave)_ogg_free(p->octave); |
michael@0 | 366 | if(p->bark)_ogg_free(p->bark); |
michael@0 | 367 | if(p->tonecurves){ |
michael@0 | 368 | for(i=0;i<P_BANDS;i++){ |
michael@0 | 369 | for(j=0;j<P_LEVELS;j++){ |
michael@0 | 370 | _ogg_free(p->tonecurves[i][j]); |
michael@0 | 371 | } |
michael@0 | 372 | _ogg_free(p->tonecurves[i]); |
michael@0 | 373 | } |
michael@0 | 374 | _ogg_free(p->tonecurves); |
michael@0 | 375 | } |
michael@0 | 376 | if(p->noiseoffset){ |
michael@0 | 377 | for(i=0;i<P_NOISECURVES;i++){ |
michael@0 | 378 | _ogg_free(p->noiseoffset[i]); |
michael@0 | 379 | } |
michael@0 | 380 | _ogg_free(p->noiseoffset); |
michael@0 | 381 | } |
michael@0 | 382 | memset(p,0,sizeof(*p)); |
michael@0 | 383 | } |
michael@0 | 384 | } |
michael@0 | 385 | |
michael@0 | 386 | /* octave/(8*eighth_octave_lines) x scale and dB y scale */ |
michael@0 | 387 | static void seed_curve(float *seed, |
michael@0 | 388 | const float **curves, |
michael@0 | 389 | float amp, |
michael@0 | 390 | int oc, int n, |
michael@0 | 391 | int linesper,float dBoffset){ |
michael@0 | 392 | int i,post1; |
michael@0 | 393 | int seedptr; |
michael@0 | 394 | const float *posts,*curve; |
michael@0 | 395 | |
michael@0 | 396 | int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f); |
michael@0 | 397 | choice=max(choice,0); |
michael@0 | 398 | choice=min(choice,P_LEVELS-1); |
michael@0 | 399 | posts=curves[choice]; |
michael@0 | 400 | curve=posts+2; |
michael@0 | 401 | post1=(int)posts[1]; |
michael@0 | 402 | seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1); |
michael@0 | 403 | |
michael@0 | 404 | for(i=posts[0];i<post1;i++){ |
michael@0 | 405 | if(seedptr>0){ |
michael@0 | 406 | float lin=amp+curve[i]; |
michael@0 | 407 | if(seed[seedptr]<lin)seed[seedptr]=lin; |
michael@0 | 408 | } |
michael@0 | 409 | seedptr+=linesper; |
michael@0 | 410 | if(seedptr>=n)break; |
michael@0 | 411 | } |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | static void seed_loop(vorbis_look_psy *p, |
michael@0 | 415 | const float ***curves, |
michael@0 | 416 | const float *f, |
michael@0 | 417 | const float *flr, |
michael@0 | 418 | float *seed, |
michael@0 | 419 | float specmax){ |
michael@0 | 420 | vorbis_info_psy *vi=p->vi; |
michael@0 | 421 | long n=p->n,i; |
michael@0 | 422 | float dBoffset=vi->max_curve_dB-specmax; |
michael@0 | 423 | |
michael@0 | 424 | /* prime the working vector with peak values */ |
michael@0 | 425 | |
michael@0 | 426 | for(i=0;i<n;i++){ |
michael@0 | 427 | float max=f[i]; |
michael@0 | 428 | long oc=p->octave[i]; |
michael@0 | 429 | while(i+1<n && p->octave[i+1]==oc){ |
michael@0 | 430 | i++; |
michael@0 | 431 | if(f[i]>max)max=f[i]; |
michael@0 | 432 | } |
michael@0 | 433 | |
michael@0 | 434 | if(max+6.f>flr[i]){ |
michael@0 | 435 | oc=oc>>p->shiftoc; |
michael@0 | 436 | |
michael@0 | 437 | if(oc>=P_BANDS)oc=P_BANDS-1; |
michael@0 | 438 | if(oc<0)oc=0; |
michael@0 | 439 | |
michael@0 | 440 | seed_curve(seed, |
michael@0 | 441 | curves[oc], |
michael@0 | 442 | max, |
michael@0 | 443 | p->octave[i]-p->firstoc, |
michael@0 | 444 | p->total_octave_lines, |
michael@0 | 445 | p->eighth_octave_lines, |
michael@0 | 446 | dBoffset); |
michael@0 | 447 | } |
michael@0 | 448 | } |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | static void seed_chase(float *seeds, int linesper, long n){ |
michael@0 | 452 | long *posstack=alloca(n*sizeof(*posstack)); |
michael@0 | 453 | float *ampstack=alloca(n*sizeof(*ampstack)); |
michael@0 | 454 | long stack=0; |
michael@0 | 455 | long pos=0; |
michael@0 | 456 | long i; |
michael@0 | 457 | |
michael@0 | 458 | for(i=0;i<n;i++){ |
michael@0 | 459 | if(stack<2){ |
michael@0 | 460 | posstack[stack]=i; |
michael@0 | 461 | ampstack[stack++]=seeds[i]; |
michael@0 | 462 | }else{ |
michael@0 | 463 | while(1){ |
michael@0 | 464 | if(seeds[i]<ampstack[stack-1]){ |
michael@0 | 465 | posstack[stack]=i; |
michael@0 | 466 | ampstack[stack++]=seeds[i]; |
michael@0 | 467 | break; |
michael@0 | 468 | }else{ |
michael@0 | 469 | if(i<posstack[stack-1]+linesper){ |
michael@0 | 470 | if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] && |
michael@0 | 471 | i<posstack[stack-2]+linesper){ |
michael@0 | 472 | /* we completely overlap, making stack-1 irrelevant. pop it */ |
michael@0 | 473 | stack--; |
michael@0 | 474 | continue; |
michael@0 | 475 | } |
michael@0 | 476 | } |
michael@0 | 477 | posstack[stack]=i; |
michael@0 | 478 | ampstack[stack++]=seeds[i]; |
michael@0 | 479 | break; |
michael@0 | 480 | |
michael@0 | 481 | } |
michael@0 | 482 | } |
michael@0 | 483 | } |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | /* the stack now contains only the positions that are relevant. Scan |
michael@0 | 487 | 'em straight through */ |
michael@0 | 488 | |
michael@0 | 489 | for(i=0;i<stack;i++){ |
michael@0 | 490 | long endpos; |
michael@0 | 491 | if(i<stack-1 && ampstack[i+1]>ampstack[i]){ |
michael@0 | 492 | endpos=posstack[i+1]; |
michael@0 | 493 | }else{ |
michael@0 | 494 | endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is |
michael@0 | 495 | discarded in short frames */ |
michael@0 | 496 | } |
michael@0 | 497 | if(endpos>n)endpos=n; |
michael@0 | 498 | for(;pos<endpos;pos++) |
michael@0 | 499 | seeds[pos]=ampstack[i]; |
michael@0 | 500 | } |
michael@0 | 501 | |
michael@0 | 502 | /* there. Linear time. I now remember this was on a problem set I |
michael@0 | 503 | had in Grad Skool... I didn't solve it at the time ;-) */ |
michael@0 | 504 | |
michael@0 | 505 | } |
michael@0 | 506 | |
michael@0 | 507 | /* bleaugh, this is more complicated than it needs to be */ |
michael@0 | 508 | #include<stdio.h> |
michael@0 | 509 | static void max_seeds(vorbis_look_psy *p, |
michael@0 | 510 | float *seed, |
michael@0 | 511 | float *flr){ |
michael@0 | 512 | long n=p->total_octave_lines; |
michael@0 | 513 | int linesper=p->eighth_octave_lines; |
michael@0 | 514 | long linpos=0; |
michael@0 | 515 | long pos; |
michael@0 | 516 | |
michael@0 | 517 | seed_chase(seed,linesper,n); /* for masking */ |
michael@0 | 518 | |
michael@0 | 519 | pos=p->octave[0]-p->firstoc-(linesper>>1); |
michael@0 | 520 | |
michael@0 | 521 | while(linpos+1<p->n){ |
michael@0 | 522 | float minV=seed[pos]; |
michael@0 | 523 | long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc; |
michael@0 | 524 | if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit; |
michael@0 | 525 | while(pos+1<=end){ |
michael@0 | 526 | pos++; |
michael@0 | 527 | if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF) |
michael@0 | 528 | minV=seed[pos]; |
michael@0 | 529 | } |
michael@0 | 530 | |
michael@0 | 531 | end=pos+p->firstoc; |
michael@0 | 532 | for(;linpos<p->n && p->octave[linpos]<=end;linpos++) |
michael@0 | 533 | if(flr[linpos]<minV)flr[linpos]=minV; |
michael@0 | 534 | } |
michael@0 | 535 | |
michael@0 | 536 | { |
michael@0 | 537 | float minV=seed[p->total_octave_lines-1]; |
michael@0 | 538 | for(;linpos<p->n;linpos++) |
michael@0 | 539 | if(flr[linpos]<minV)flr[linpos]=minV; |
michael@0 | 540 | } |
michael@0 | 541 | |
michael@0 | 542 | } |
michael@0 | 543 | |
michael@0 | 544 | static void bark_noise_hybridmp(int n,const long *b, |
michael@0 | 545 | const float *f, |
michael@0 | 546 | float *noise, |
michael@0 | 547 | const float offset, |
michael@0 | 548 | const int fixed){ |
michael@0 | 549 | |
michael@0 | 550 | float *N=alloca(n*sizeof(*N)); |
michael@0 | 551 | float *X=alloca(n*sizeof(*N)); |
michael@0 | 552 | float *XX=alloca(n*sizeof(*N)); |
michael@0 | 553 | float *Y=alloca(n*sizeof(*N)); |
michael@0 | 554 | float *XY=alloca(n*sizeof(*N)); |
michael@0 | 555 | |
michael@0 | 556 | float tN, tX, tXX, tY, tXY; |
michael@0 | 557 | int i; |
michael@0 | 558 | |
michael@0 | 559 | int lo, hi; |
michael@0 | 560 | float R=0.f; |
michael@0 | 561 | float A=0.f; |
michael@0 | 562 | float B=0.f; |
michael@0 | 563 | float D=1.f; |
michael@0 | 564 | float w, x, y; |
michael@0 | 565 | |
michael@0 | 566 | tN = tX = tXX = tY = tXY = 0.f; |
michael@0 | 567 | |
michael@0 | 568 | y = f[0] + offset; |
michael@0 | 569 | if (y < 1.f) y = 1.f; |
michael@0 | 570 | |
michael@0 | 571 | w = y * y * .5; |
michael@0 | 572 | |
michael@0 | 573 | tN += w; |
michael@0 | 574 | tX += w; |
michael@0 | 575 | tY += w * y; |
michael@0 | 576 | |
michael@0 | 577 | N[0] = tN; |
michael@0 | 578 | X[0] = tX; |
michael@0 | 579 | XX[0] = tXX; |
michael@0 | 580 | Y[0] = tY; |
michael@0 | 581 | XY[0] = tXY; |
michael@0 | 582 | |
michael@0 | 583 | for (i = 1, x = 1.f; i < n; i++, x += 1.f) { |
michael@0 | 584 | |
michael@0 | 585 | y = f[i] + offset; |
michael@0 | 586 | if (y < 1.f) y = 1.f; |
michael@0 | 587 | |
michael@0 | 588 | w = y * y; |
michael@0 | 589 | |
michael@0 | 590 | tN += w; |
michael@0 | 591 | tX += w * x; |
michael@0 | 592 | tXX += w * x * x; |
michael@0 | 593 | tY += w * y; |
michael@0 | 594 | tXY += w * x * y; |
michael@0 | 595 | |
michael@0 | 596 | N[i] = tN; |
michael@0 | 597 | X[i] = tX; |
michael@0 | 598 | XX[i] = tXX; |
michael@0 | 599 | Y[i] = tY; |
michael@0 | 600 | XY[i] = tXY; |
michael@0 | 601 | } |
michael@0 | 602 | |
michael@0 | 603 | for (i = 0, x = 0.f;; i++, x += 1.f) { |
michael@0 | 604 | |
michael@0 | 605 | lo = b[i] >> 16; |
michael@0 | 606 | if( lo>=0 ) break; |
michael@0 | 607 | hi = b[i] & 0xffff; |
michael@0 | 608 | |
michael@0 | 609 | tN = N[hi] + N[-lo]; |
michael@0 | 610 | tX = X[hi] - X[-lo]; |
michael@0 | 611 | tXX = XX[hi] + XX[-lo]; |
michael@0 | 612 | tY = Y[hi] + Y[-lo]; |
michael@0 | 613 | tXY = XY[hi] - XY[-lo]; |
michael@0 | 614 | |
michael@0 | 615 | A = tY * tXX - tX * tXY; |
michael@0 | 616 | B = tN * tXY - tX * tY; |
michael@0 | 617 | D = tN * tXX - tX * tX; |
michael@0 | 618 | R = (A + x * B) / D; |
michael@0 | 619 | if (R < 0.f) |
michael@0 | 620 | R = 0.f; |
michael@0 | 621 | |
michael@0 | 622 | noise[i] = R - offset; |
michael@0 | 623 | } |
michael@0 | 624 | |
michael@0 | 625 | for ( ;; i++, x += 1.f) { |
michael@0 | 626 | |
michael@0 | 627 | lo = b[i] >> 16; |
michael@0 | 628 | hi = b[i] & 0xffff; |
michael@0 | 629 | if(hi>=n)break; |
michael@0 | 630 | |
michael@0 | 631 | tN = N[hi] - N[lo]; |
michael@0 | 632 | tX = X[hi] - X[lo]; |
michael@0 | 633 | tXX = XX[hi] - XX[lo]; |
michael@0 | 634 | tY = Y[hi] - Y[lo]; |
michael@0 | 635 | tXY = XY[hi] - XY[lo]; |
michael@0 | 636 | |
michael@0 | 637 | A = tY * tXX - tX * tXY; |
michael@0 | 638 | B = tN * tXY - tX * tY; |
michael@0 | 639 | D = tN * tXX - tX * tX; |
michael@0 | 640 | R = (A + x * B) / D; |
michael@0 | 641 | if (R < 0.f) R = 0.f; |
michael@0 | 642 | |
michael@0 | 643 | noise[i] = R - offset; |
michael@0 | 644 | } |
michael@0 | 645 | for ( ; i < n; i++, x += 1.f) { |
michael@0 | 646 | |
michael@0 | 647 | R = (A + x * B) / D; |
michael@0 | 648 | if (R < 0.f) R = 0.f; |
michael@0 | 649 | |
michael@0 | 650 | noise[i] = R - offset; |
michael@0 | 651 | } |
michael@0 | 652 | |
michael@0 | 653 | if (fixed <= 0) return; |
michael@0 | 654 | |
michael@0 | 655 | for (i = 0, x = 0.f;; i++, x += 1.f) { |
michael@0 | 656 | hi = i + fixed / 2; |
michael@0 | 657 | lo = hi - fixed; |
michael@0 | 658 | if(lo>=0)break; |
michael@0 | 659 | |
michael@0 | 660 | tN = N[hi] + N[-lo]; |
michael@0 | 661 | tX = X[hi] - X[-lo]; |
michael@0 | 662 | tXX = XX[hi] + XX[-lo]; |
michael@0 | 663 | tY = Y[hi] + Y[-lo]; |
michael@0 | 664 | tXY = XY[hi] - XY[-lo]; |
michael@0 | 665 | |
michael@0 | 666 | |
michael@0 | 667 | A = tY * tXX - tX * tXY; |
michael@0 | 668 | B = tN * tXY - tX * tY; |
michael@0 | 669 | D = tN * tXX - tX * tX; |
michael@0 | 670 | R = (A + x * B) / D; |
michael@0 | 671 | |
michael@0 | 672 | if (R - offset < noise[i]) noise[i] = R - offset; |
michael@0 | 673 | } |
michael@0 | 674 | for ( ;; i++, x += 1.f) { |
michael@0 | 675 | |
michael@0 | 676 | hi = i + fixed / 2; |
michael@0 | 677 | lo = hi - fixed; |
michael@0 | 678 | if(hi>=n)break; |
michael@0 | 679 | |
michael@0 | 680 | tN = N[hi] - N[lo]; |
michael@0 | 681 | tX = X[hi] - X[lo]; |
michael@0 | 682 | tXX = XX[hi] - XX[lo]; |
michael@0 | 683 | tY = Y[hi] - Y[lo]; |
michael@0 | 684 | tXY = XY[hi] - XY[lo]; |
michael@0 | 685 | |
michael@0 | 686 | A = tY * tXX - tX * tXY; |
michael@0 | 687 | B = tN * tXY - tX * tY; |
michael@0 | 688 | D = tN * tXX - tX * tX; |
michael@0 | 689 | R = (A + x * B) / D; |
michael@0 | 690 | |
michael@0 | 691 | if (R - offset < noise[i]) noise[i] = R - offset; |
michael@0 | 692 | } |
michael@0 | 693 | for ( ; i < n; i++, x += 1.f) { |
michael@0 | 694 | R = (A + x * B) / D; |
michael@0 | 695 | if (R - offset < noise[i]) noise[i] = R - offset; |
michael@0 | 696 | } |
michael@0 | 697 | } |
michael@0 | 698 | |
michael@0 | 699 | void _vp_noisemask(vorbis_look_psy *p, |
michael@0 | 700 | float *logmdct, |
michael@0 | 701 | float *logmask){ |
michael@0 | 702 | |
michael@0 | 703 | int i,n=p->n; |
michael@0 | 704 | float *work=alloca(n*sizeof(*work)); |
michael@0 | 705 | |
michael@0 | 706 | bark_noise_hybridmp(n,p->bark,logmdct,logmask, |
michael@0 | 707 | 140.,-1); |
michael@0 | 708 | |
michael@0 | 709 | for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i]; |
michael@0 | 710 | |
michael@0 | 711 | bark_noise_hybridmp(n,p->bark,work,logmask,0., |
michael@0 | 712 | p->vi->noisewindowfixed); |
michael@0 | 713 | |
michael@0 | 714 | for(i=0;i<n;i++)work[i]=logmdct[i]-work[i]; |
michael@0 | 715 | |
michael@0 | 716 | #if 0 |
michael@0 | 717 | { |
michael@0 | 718 | static int seq=0; |
michael@0 | 719 | |
michael@0 | 720 | float work2[n]; |
michael@0 | 721 | for(i=0;i<n;i++){ |
michael@0 | 722 | work2[i]=logmask[i]+work[i]; |
michael@0 | 723 | } |
michael@0 | 724 | |
michael@0 | 725 | if(seq&1) |
michael@0 | 726 | _analysis_output("median2R",seq/2,work,n,1,0,0); |
michael@0 | 727 | else |
michael@0 | 728 | _analysis_output("median2L",seq/2,work,n,1,0,0); |
michael@0 | 729 | |
michael@0 | 730 | if(seq&1) |
michael@0 | 731 | _analysis_output("envelope2R",seq/2,work2,n,1,0,0); |
michael@0 | 732 | else |
michael@0 | 733 | _analysis_output("envelope2L",seq/2,work2,n,1,0,0); |
michael@0 | 734 | seq++; |
michael@0 | 735 | } |
michael@0 | 736 | #endif |
michael@0 | 737 | |
michael@0 | 738 | for(i=0;i<n;i++){ |
michael@0 | 739 | int dB=logmask[i]+.5; |
michael@0 | 740 | if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1; |
michael@0 | 741 | if(dB<0)dB=0; |
michael@0 | 742 | logmask[i]= work[i]+p->vi->noisecompand[dB]; |
michael@0 | 743 | } |
michael@0 | 744 | |
michael@0 | 745 | } |
michael@0 | 746 | |
michael@0 | 747 | void _vp_tonemask(vorbis_look_psy *p, |
michael@0 | 748 | float *logfft, |
michael@0 | 749 | float *logmask, |
michael@0 | 750 | float global_specmax, |
michael@0 | 751 | float local_specmax){ |
michael@0 | 752 | |
michael@0 | 753 | int i,n=p->n; |
michael@0 | 754 | |
michael@0 | 755 | float *seed=alloca(sizeof(*seed)*p->total_octave_lines); |
michael@0 | 756 | float att=local_specmax+p->vi->ath_adjatt; |
michael@0 | 757 | for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF; |
michael@0 | 758 | |
michael@0 | 759 | /* set the ATH (floating below localmax, not global max by a |
michael@0 | 760 | specified att) */ |
michael@0 | 761 | if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt; |
michael@0 | 762 | |
michael@0 | 763 | for(i=0;i<n;i++) |
michael@0 | 764 | logmask[i]=p->ath[i]+att; |
michael@0 | 765 | |
michael@0 | 766 | /* tone masking */ |
michael@0 | 767 | seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax); |
michael@0 | 768 | max_seeds(p,seed,logmask); |
michael@0 | 769 | |
michael@0 | 770 | } |
michael@0 | 771 | |
michael@0 | 772 | void _vp_offset_and_mix(vorbis_look_psy *p, |
michael@0 | 773 | float *noise, |
michael@0 | 774 | float *tone, |
michael@0 | 775 | int offset_select, |
michael@0 | 776 | float *logmask, |
michael@0 | 777 | float *mdct, |
michael@0 | 778 | float *logmdct){ |
michael@0 | 779 | int i,n=p->n; |
michael@0 | 780 | float de, coeffi, cx;/* AoTuV */ |
michael@0 | 781 | float toneatt=p->vi->tone_masteratt[offset_select]; |
michael@0 | 782 | |
michael@0 | 783 | cx = p->m_val; |
michael@0 | 784 | |
michael@0 | 785 | for(i=0;i<n;i++){ |
michael@0 | 786 | float val= noise[i]+p->noiseoffset[offset_select][i]; |
michael@0 | 787 | if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp; |
michael@0 | 788 | logmask[i]=max(val,tone[i]+toneatt); |
michael@0 | 789 | |
michael@0 | 790 | |
michael@0 | 791 | /* AoTuV */ |
michael@0 | 792 | /** @ M1 ** |
michael@0 | 793 | The following codes improve a noise problem. |
michael@0 | 794 | A fundamental idea uses the value of masking and carries out |
michael@0 | 795 | the relative compensation of the MDCT. |
michael@0 | 796 | However, this code is not perfect and all noise problems cannot be solved. |
michael@0 | 797 | by Aoyumi @ 2004/04/18 |
michael@0 | 798 | */ |
michael@0 | 799 | |
michael@0 | 800 | if(offset_select == 1) { |
michael@0 | 801 | coeffi = -17.2; /* coeffi is a -17.2dB threshold */ |
michael@0 | 802 | val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */ |
michael@0 | 803 | |
michael@0 | 804 | if(val > coeffi){ |
michael@0 | 805 | /* mdct value is > -17.2 dB below floor */ |
michael@0 | 806 | |
michael@0 | 807 | de = 1.0-((val-coeffi)*0.005*cx); |
michael@0 | 808 | /* pro-rated attenuation: |
michael@0 | 809 | -0.00 dB boost if mdct value is -17.2dB (relative to floor) |
michael@0 | 810 | -0.77 dB boost if mdct value is 0dB (relative to floor) |
michael@0 | 811 | -1.64 dB boost if mdct value is +17.2dB (relative to floor) |
michael@0 | 812 | etc... */ |
michael@0 | 813 | |
michael@0 | 814 | if(de < 0) de = 0.0001; |
michael@0 | 815 | }else |
michael@0 | 816 | /* mdct value is <= -17.2 dB below floor */ |
michael@0 | 817 | |
michael@0 | 818 | de = 1.0-((val-coeffi)*0.0003*cx); |
michael@0 | 819 | /* pro-rated attenuation: |
michael@0 | 820 | +0.00 dB atten if mdct value is -17.2dB (relative to floor) |
michael@0 | 821 | +0.45 dB atten if mdct value is -34.4dB (relative to floor) |
michael@0 | 822 | etc... */ |
michael@0 | 823 | |
michael@0 | 824 | mdct[i] *= de; |
michael@0 | 825 | |
michael@0 | 826 | } |
michael@0 | 827 | } |
michael@0 | 828 | } |
michael@0 | 829 | |
michael@0 | 830 | float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){ |
michael@0 | 831 | vorbis_info *vi=vd->vi; |
michael@0 | 832 | codec_setup_info *ci=vi->codec_setup; |
michael@0 | 833 | vorbis_info_psy_global *gi=&ci->psy_g_param; |
michael@0 | 834 | |
michael@0 | 835 | int n=ci->blocksizes[vd->W]/2; |
michael@0 | 836 | float secs=(float)n/vi->rate; |
michael@0 | 837 | |
michael@0 | 838 | amp+=secs*gi->ampmax_att_per_sec; |
michael@0 | 839 | if(amp<-9999)amp=-9999; |
michael@0 | 840 | return(amp); |
michael@0 | 841 | } |
michael@0 | 842 | |
michael@0 | 843 | static float FLOOR1_fromdB_LOOKUP[256]={ |
michael@0 | 844 | 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F, |
michael@0 | 845 | 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F, |
michael@0 | 846 | 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F, |
michael@0 | 847 | 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F, |
michael@0 | 848 | 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F, |
michael@0 | 849 | 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F, |
michael@0 | 850 | 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F, |
michael@0 | 851 | 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F, |
michael@0 | 852 | 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F, |
michael@0 | 853 | 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F, |
michael@0 | 854 | 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F, |
michael@0 | 855 | 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F, |
michael@0 | 856 | 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F, |
michael@0 | 857 | 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F, |
michael@0 | 858 | 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F, |
michael@0 | 859 | 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F, |
michael@0 | 860 | 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F, |
michael@0 | 861 | 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F, |
michael@0 | 862 | 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F, |
michael@0 | 863 | 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F, |
michael@0 | 864 | 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F, |
michael@0 | 865 | 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F, |
michael@0 | 866 | 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F, |
michael@0 | 867 | 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F, |
michael@0 | 868 | 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F, |
michael@0 | 869 | 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F, |
michael@0 | 870 | 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F, |
michael@0 | 871 | 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F, |
michael@0 | 872 | 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F, |
michael@0 | 873 | 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F, |
michael@0 | 874 | 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F, |
michael@0 | 875 | 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F, |
michael@0 | 876 | 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F, |
michael@0 | 877 | 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F, |
michael@0 | 878 | 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F, |
michael@0 | 879 | 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F, |
michael@0 | 880 | 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F, |
michael@0 | 881 | 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F, |
michael@0 | 882 | 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F, |
michael@0 | 883 | 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F, |
michael@0 | 884 | 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F, |
michael@0 | 885 | 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F, |
michael@0 | 886 | 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F, |
michael@0 | 887 | 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F, |
michael@0 | 888 | 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F, |
michael@0 | 889 | 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F, |
michael@0 | 890 | 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F, |
michael@0 | 891 | 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F, |
michael@0 | 892 | 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F, |
michael@0 | 893 | 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F, |
michael@0 | 894 | 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F, |
michael@0 | 895 | 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F, |
michael@0 | 896 | 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F, |
michael@0 | 897 | 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F, |
michael@0 | 898 | 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F, |
michael@0 | 899 | 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F, |
michael@0 | 900 | 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F, |
michael@0 | 901 | 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F, |
michael@0 | 902 | 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F, |
michael@0 | 903 | 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F, |
michael@0 | 904 | 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F, |
michael@0 | 905 | 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F, |
michael@0 | 906 | 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F, |
michael@0 | 907 | 0.82788260F, 0.88168307F, 0.9389798F, 1.F, |
michael@0 | 908 | }; |
michael@0 | 909 | |
michael@0 | 910 | /* this is for per-channel noise normalization */ |
michael@0 | 911 | static int apsort(const void *a, const void *b){ |
michael@0 | 912 | float f1=**(float**)a; |
michael@0 | 913 | float f2=**(float**)b; |
michael@0 | 914 | return (f1<f2)-(f1>f2); |
michael@0 | 915 | } |
michael@0 | 916 | |
michael@0 | 917 | static void flag_lossless(int limit, float prepoint, float postpoint, float *mdct, |
michael@0 | 918 | float *floor, int *flag, int i, int jn){ |
michael@0 | 919 | int j; |
michael@0 | 920 | for(j=0;j<jn;j++){ |
michael@0 | 921 | float point = j>=limit-i ? postpoint : prepoint; |
michael@0 | 922 | float r = fabs(mdct[j])/floor[j]; |
michael@0 | 923 | if(r<point) |
michael@0 | 924 | flag[j]=0; |
michael@0 | 925 | else |
michael@0 | 926 | flag[j]=1; |
michael@0 | 927 | } |
michael@0 | 928 | } |
michael@0 | 929 | |
michael@0 | 930 | /* Overload/Side effect: On input, the *q vector holds either the |
michael@0 | 931 | quantized energy (for elements with the flag set) or the absolute |
michael@0 | 932 | values of the *r vector (for elements with flag unset). On output, |
michael@0 | 933 | *q holds the quantized energy for all elements */ |
michael@0 | 934 | static float noise_normalize(vorbis_look_psy *p, int limit, float *r, float *q, float *f, int *flags, float acc, int i, int n, int *out){ |
michael@0 | 935 | |
michael@0 | 936 | vorbis_info_psy *vi=p->vi; |
michael@0 | 937 | float **sort = alloca(n*sizeof(*sort)); |
michael@0 | 938 | int j,count=0; |
michael@0 | 939 | int start = (vi->normal_p ? vi->normal_start-i : n); |
michael@0 | 940 | if(start>n)start=n; |
michael@0 | 941 | |
michael@0 | 942 | /* force classic behavior where only energy in the current band is considered */ |
michael@0 | 943 | acc=0.f; |
michael@0 | 944 | |
michael@0 | 945 | /* still responsible for populating *out where noise norm not in |
michael@0 | 946 | effect. There's no need to [re]populate *q in these areas */ |
michael@0 | 947 | for(j=0;j<start;j++){ |
michael@0 | 948 | if(!flags || !flags[j]){ /* lossless coupling already quantized. |
michael@0 | 949 | Don't touch; requantizing based on |
michael@0 | 950 | energy would be incorrect. */ |
michael@0 | 951 | float ve = q[j]/f[j]; |
michael@0 | 952 | if(r[j]<0) |
michael@0 | 953 | out[j] = -rint(sqrt(ve)); |
michael@0 | 954 | else |
michael@0 | 955 | out[j] = rint(sqrt(ve)); |
michael@0 | 956 | } |
michael@0 | 957 | } |
michael@0 | 958 | |
michael@0 | 959 | /* sort magnitudes for noise norm portion of partition */ |
michael@0 | 960 | for(;j<n;j++){ |
michael@0 | 961 | if(!flags || !flags[j]){ /* can't noise norm elements that have |
michael@0 | 962 | already been loslessly coupled; we can |
michael@0 | 963 | only account for their energy error */ |
michael@0 | 964 | float ve = q[j]/f[j]; |
michael@0 | 965 | /* Despite all the new, more capable coupling code, for now we |
michael@0 | 966 | implement noise norm as it has been up to this point. Only |
michael@0 | 967 | consider promotions to unit magnitude from 0. In addition |
michael@0 | 968 | the only energy error counted is quantizations to zero. */ |
michael@0 | 969 | /* also-- the original point code only applied noise norm at > pointlimit */ |
michael@0 | 970 | if(ve<.25f && (!flags || j>=limit-i)){ |
michael@0 | 971 | acc += ve; |
michael@0 | 972 | sort[count++]=q+j; /* q is fabs(r) for unflagged element */ |
michael@0 | 973 | }else{ |
michael@0 | 974 | /* For now: no acc adjustment for nonzero quantization. populate *out and q as this value is final. */ |
michael@0 | 975 | if(r[j]<0) |
michael@0 | 976 | out[j] = -rint(sqrt(ve)); |
michael@0 | 977 | else |
michael@0 | 978 | out[j] = rint(sqrt(ve)); |
michael@0 | 979 | q[j] = out[j]*out[j]*f[j]; |
michael@0 | 980 | } |
michael@0 | 981 | }/* else{ |
michael@0 | 982 | again, no energy adjustment for error in nonzero quant-- for now |
michael@0 | 983 | }*/ |
michael@0 | 984 | } |
michael@0 | 985 | |
michael@0 | 986 | if(count){ |
michael@0 | 987 | /* noise norm to do */ |
michael@0 | 988 | qsort(sort,count,sizeof(*sort),apsort); |
michael@0 | 989 | for(j=0;j<count;j++){ |
michael@0 | 990 | int k=sort[j]-q; |
michael@0 | 991 | if(acc>=vi->normal_thresh){ |
michael@0 | 992 | out[k]=unitnorm(r[k]); |
michael@0 | 993 | acc-=1.f; |
michael@0 | 994 | q[k]=f[k]; |
michael@0 | 995 | }else{ |
michael@0 | 996 | out[k]=0; |
michael@0 | 997 | q[k]=0.f; |
michael@0 | 998 | } |
michael@0 | 999 | } |
michael@0 | 1000 | } |
michael@0 | 1001 | |
michael@0 | 1002 | return acc; |
michael@0 | 1003 | } |
michael@0 | 1004 | |
michael@0 | 1005 | /* Noise normalization, quantization and coupling are not wholly |
michael@0 | 1006 | seperable processes in depth>1 coupling. */ |
michael@0 | 1007 | void _vp_couple_quantize_normalize(int blobno, |
michael@0 | 1008 | vorbis_info_psy_global *g, |
michael@0 | 1009 | vorbis_look_psy *p, |
michael@0 | 1010 | vorbis_info_mapping0 *vi, |
michael@0 | 1011 | float **mdct, |
michael@0 | 1012 | int **iwork, |
michael@0 | 1013 | int *nonzero, |
michael@0 | 1014 | int sliding_lowpass, |
michael@0 | 1015 | int ch){ |
michael@0 | 1016 | |
michael@0 | 1017 | int i; |
michael@0 | 1018 | int n = p->n; |
michael@0 | 1019 | int partition=(p->vi->normal_p ? p->vi->normal_partition : 16); |
michael@0 | 1020 | int limit = g->coupling_pointlimit[p->vi->blockflag][blobno]; |
michael@0 | 1021 | float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]]; |
michael@0 | 1022 | float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]]; |
michael@0 | 1023 | #if 0 |
michael@0 | 1024 | float de=0.1*p->m_val; /* a blend of the AoTuV M2 and M3 code here and below */ |
michael@0 | 1025 | #endif |
michael@0 | 1026 | |
michael@0 | 1027 | /* mdct is our raw mdct output, floor not removed. */ |
michael@0 | 1028 | /* inout passes in the ifloor, passes back quantized result */ |
michael@0 | 1029 | |
michael@0 | 1030 | /* unquantized energy (negative indicates amplitude has negative sign) */ |
michael@0 | 1031 | float **raw = alloca(ch*sizeof(*raw)); |
michael@0 | 1032 | |
michael@0 | 1033 | /* dual pupose; quantized energy (if flag set), othersize fabs(raw) */ |
michael@0 | 1034 | float **quant = alloca(ch*sizeof(*quant)); |
michael@0 | 1035 | |
michael@0 | 1036 | /* floor energy */ |
michael@0 | 1037 | float **floor = alloca(ch*sizeof(*floor)); |
michael@0 | 1038 | |
michael@0 | 1039 | /* flags indicating raw/quantized status of elements in raw vector */ |
michael@0 | 1040 | int **flag = alloca(ch*sizeof(*flag)); |
michael@0 | 1041 | |
michael@0 | 1042 | /* non-zero flag working vector */ |
michael@0 | 1043 | int *nz = alloca(ch*sizeof(*nz)); |
michael@0 | 1044 | |
michael@0 | 1045 | /* energy surplus/defecit tracking */ |
michael@0 | 1046 | float *acc = alloca((ch+vi->coupling_steps)*sizeof(*acc)); |
michael@0 | 1047 | |
michael@0 | 1048 | /* The threshold of a stereo is changed with the size of n */ |
michael@0 | 1049 | if(n > 1000) |
michael@0 | 1050 | postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]]; |
michael@0 | 1051 | |
michael@0 | 1052 | raw[0] = alloca(ch*partition*sizeof(**raw)); |
michael@0 | 1053 | quant[0] = alloca(ch*partition*sizeof(**quant)); |
michael@0 | 1054 | floor[0] = alloca(ch*partition*sizeof(**floor)); |
michael@0 | 1055 | flag[0] = alloca(ch*partition*sizeof(**flag)); |
michael@0 | 1056 | |
michael@0 | 1057 | for(i=1;i<ch;i++){ |
michael@0 | 1058 | raw[i] = &raw[0][partition*i]; |
michael@0 | 1059 | quant[i] = &quant[0][partition*i]; |
michael@0 | 1060 | floor[i] = &floor[0][partition*i]; |
michael@0 | 1061 | flag[i] = &flag[0][partition*i]; |
michael@0 | 1062 | } |
michael@0 | 1063 | for(i=0;i<ch+vi->coupling_steps;i++) |
michael@0 | 1064 | acc[i]=0.f; |
michael@0 | 1065 | |
michael@0 | 1066 | for(i=0;i<n;i+=partition){ |
michael@0 | 1067 | int k,j,jn = partition > n-i ? n-i : partition; |
michael@0 | 1068 | int step,track = 0; |
michael@0 | 1069 | |
michael@0 | 1070 | memcpy(nz,nonzero,sizeof(*nz)*ch); |
michael@0 | 1071 | |
michael@0 | 1072 | /* prefill */ |
michael@0 | 1073 | memset(flag[0],0,ch*partition*sizeof(**flag)); |
michael@0 | 1074 | for(k=0;k<ch;k++){ |
michael@0 | 1075 | int *iout = &iwork[k][i]; |
michael@0 | 1076 | if(nz[k]){ |
michael@0 | 1077 | |
michael@0 | 1078 | for(j=0;j<jn;j++) |
michael@0 | 1079 | floor[k][j] = FLOOR1_fromdB_LOOKUP[iout[j]]; |
michael@0 | 1080 | |
michael@0 | 1081 | flag_lossless(limit,prepoint,postpoint,&mdct[k][i],floor[k],flag[k],i,jn); |
michael@0 | 1082 | |
michael@0 | 1083 | for(j=0;j<jn;j++){ |
michael@0 | 1084 | quant[k][j] = raw[k][j] = mdct[k][i+j]*mdct[k][i+j]; |
michael@0 | 1085 | if(mdct[k][i+j]<0.f) raw[k][j]*=-1.f; |
michael@0 | 1086 | floor[k][j]*=floor[k][j]; |
michael@0 | 1087 | } |
michael@0 | 1088 | |
michael@0 | 1089 | acc[track]=noise_normalize(p,limit,raw[k],quant[k],floor[k],NULL,acc[track],i,jn,iout); |
michael@0 | 1090 | |
michael@0 | 1091 | }else{ |
michael@0 | 1092 | for(j=0;j<jn;j++){ |
michael@0 | 1093 | floor[k][j] = 1e-10f; |
michael@0 | 1094 | raw[k][j] = 0.f; |
michael@0 | 1095 | quant[k][j] = 0.f; |
michael@0 | 1096 | flag[k][j] = 0; |
michael@0 | 1097 | iout[j]=0; |
michael@0 | 1098 | } |
michael@0 | 1099 | acc[track]=0.f; |
michael@0 | 1100 | } |
michael@0 | 1101 | track++; |
michael@0 | 1102 | } |
michael@0 | 1103 | |
michael@0 | 1104 | /* coupling */ |
michael@0 | 1105 | for(step=0;step<vi->coupling_steps;step++){ |
michael@0 | 1106 | int Mi = vi->coupling_mag[step]; |
michael@0 | 1107 | int Ai = vi->coupling_ang[step]; |
michael@0 | 1108 | int *iM = &iwork[Mi][i]; |
michael@0 | 1109 | int *iA = &iwork[Ai][i]; |
michael@0 | 1110 | float *reM = raw[Mi]; |
michael@0 | 1111 | float *reA = raw[Ai]; |
michael@0 | 1112 | float *qeM = quant[Mi]; |
michael@0 | 1113 | float *qeA = quant[Ai]; |
michael@0 | 1114 | float *floorM = floor[Mi]; |
michael@0 | 1115 | float *floorA = floor[Ai]; |
michael@0 | 1116 | int *fM = flag[Mi]; |
michael@0 | 1117 | int *fA = flag[Ai]; |
michael@0 | 1118 | |
michael@0 | 1119 | if(nz[Mi] || nz[Ai]){ |
michael@0 | 1120 | nz[Mi] = nz[Ai] = 1; |
michael@0 | 1121 | |
michael@0 | 1122 | for(j=0;j<jn;j++){ |
michael@0 | 1123 | |
michael@0 | 1124 | if(j<sliding_lowpass-i){ |
michael@0 | 1125 | if(fM[j] || fA[j]){ |
michael@0 | 1126 | /* lossless coupling */ |
michael@0 | 1127 | |
michael@0 | 1128 | reM[j] = fabs(reM[j])+fabs(reA[j]); |
michael@0 | 1129 | qeM[j] = qeM[j]+qeA[j]; |
michael@0 | 1130 | fM[j]=fA[j]=1; |
michael@0 | 1131 | |
michael@0 | 1132 | /* couple iM/iA */ |
michael@0 | 1133 | { |
michael@0 | 1134 | int A = iM[j]; |
michael@0 | 1135 | int B = iA[j]; |
michael@0 | 1136 | |
michael@0 | 1137 | if(abs(A)>abs(B)){ |
michael@0 | 1138 | iA[j]=(A>0?A-B:B-A); |
michael@0 | 1139 | }else{ |
michael@0 | 1140 | iA[j]=(B>0?A-B:B-A); |
michael@0 | 1141 | iM[j]=B; |
michael@0 | 1142 | } |
michael@0 | 1143 | |
michael@0 | 1144 | /* collapse two equivalent tuples to one */ |
michael@0 | 1145 | if(iA[j]>=abs(iM[j])*2){ |
michael@0 | 1146 | iA[j]= -iA[j]; |
michael@0 | 1147 | iM[j]= -iM[j]; |
michael@0 | 1148 | } |
michael@0 | 1149 | |
michael@0 | 1150 | } |
michael@0 | 1151 | |
michael@0 | 1152 | }else{ |
michael@0 | 1153 | /* lossy (point) coupling */ |
michael@0 | 1154 | if(j<limit-i){ |
michael@0 | 1155 | /* dipole */ |
michael@0 | 1156 | reM[j] += reA[j]; |
michael@0 | 1157 | qeM[j] = fabs(reM[j]); |
michael@0 | 1158 | }else{ |
michael@0 | 1159 | #if 0 |
michael@0 | 1160 | /* AoTuV */ |
michael@0 | 1161 | /** @ M2 ** |
michael@0 | 1162 | The boost problem by the combination of noise normalization and point stereo is eased. |
michael@0 | 1163 | However, this is a temporary patch. |
michael@0 | 1164 | by Aoyumi @ 2004/04/18 |
michael@0 | 1165 | */ |
michael@0 | 1166 | float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit))); |
michael@0 | 1167 | /* elliptical */ |
michael@0 | 1168 | if(reM[j]+reA[j]<0){ |
michael@0 | 1169 | reM[j] = - (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate); |
michael@0 | 1170 | }else{ |
michael@0 | 1171 | reM[j] = (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate); |
michael@0 | 1172 | } |
michael@0 | 1173 | #else |
michael@0 | 1174 | /* elliptical */ |
michael@0 | 1175 | if(reM[j]+reA[j]<0){ |
michael@0 | 1176 | reM[j] = - (qeM[j] = fabs(reM[j])+fabs(reA[j])); |
michael@0 | 1177 | }else{ |
michael@0 | 1178 | reM[j] = (qeM[j] = fabs(reM[j])+fabs(reA[j])); |
michael@0 | 1179 | } |
michael@0 | 1180 | #endif |
michael@0 | 1181 | |
michael@0 | 1182 | } |
michael@0 | 1183 | reA[j]=qeA[j]=0.f; |
michael@0 | 1184 | fA[j]=1; |
michael@0 | 1185 | iA[j]=0; |
michael@0 | 1186 | } |
michael@0 | 1187 | } |
michael@0 | 1188 | floorM[j]=floorA[j]=floorM[j]+floorA[j]; |
michael@0 | 1189 | } |
michael@0 | 1190 | /* normalize the resulting mag vector */ |
michael@0 | 1191 | acc[track]=noise_normalize(p,limit,raw[Mi],quant[Mi],floor[Mi],flag[Mi],acc[track],i,jn,iM); |
michael@0 | 1192 | track++; |
michael@0 | 1193 | } |
michael@0 | 1194 | } |
michael@0 | 1195 | } |
michael@0 | 1196 | |
michael@0 | 1197 | for(i=0;i<vi->coupling_steps;i++){ |
michael@0 | 1198 | /* make sure coupling a zero and a nonzero channel results in two |
michael@0 | 1199 | nonzero channels. */ |
michael@0 | 1200 | if(nonzero[vi->coupling_mag[i]] || |
michael@0 | 1201 | nonzero[vi->coupling_ang[i]]){ |
michael@0 | 1202 | nonzero[vi->coupling_mag[i]]=1; |
michael@0 | 1203 | nonzero[vi->coupling_ang[i]]=1; |
michael@0 | 1204 | } |
michael@0 | 1205 | } |
michael@0 | 1206 | } |