1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-1999 *
9 * by 1999 Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: random psychoacoustics (not including preecho)
15 author: Monty <xiphmont@mit.edu>
16 modifications by: Monty
17 last modification date: Aug 08 1999
19 ********************************************************************/
36 /* Find the mean log energy of a given 'band'; used to evaluate tones
37 against background noise */
39 /* This is faster than a real convolution, gives us roughly the log f
40 scale we seek, and gives OK results. So, that means it's a good
43 /* To add: f scale noise attenuation curve */
45 void _vp_noise_floor(double *f, double *m,int n){
51 long newlo=i*LNOISE-NOISEBIAS;
52 long newhi=i*HNOISE+NOISEBIAS;
58 for(j=hi;j<newhi;j++){
62 for(j=lo;j<newlo;j++){
70 temp=fromdB(acc/div+NOISEdB); /* The NOISEdB constant should be an
72 if(m[i]<temp)m[i]=temp;
76 /* figure the masking curve. linear rolloff on a dB scale, adjusted
78 void _vp_mask_floor(double *f, double *m,int n){
79 double ocSCALE=1./log(2);
80 double curmask=-9.e40;
81 double curoc=log(MASKBIAS)*ocSCALE;
84 /* run mask forward then backward */
86 double newmask=todB(f[i])-MASKdB;
87 double newoc=log(i+MASKBIAS)*ocSCALE;
88 double roll=curmask-(newoc-curoc)*HROLL;
95 if(m[i]<lroll)m[i]=lroll;
99 curoc=log(n+MASKBIAS)*ocSCALE;
101 double newmask=todB(f[i])-MASKdB;
102 double newoc=log(i+MASKBIAS)*ocSCALE;
103 double roll=curmask-(curoc-newoc)*LROLL;
106 roll=curmask=newmask;
110 if(m[i]<lroll)m[i]=lroll;
114 void _vp_psy_quantize(double *f, double *m,int n){
117 int val=rint(f[i]/m[i]);
124 void _vp_psy_sparsify(double *f, double *m,int n){
127 if(fabs(f[i])<m[i])f[i]=0;
130 void _vp_psy_make_lsp(vorbis_block *vb){