11 #include "fcoeffs098.h"
13 static uint32 mrindex;
14 static uint32 mrratio;
17 void SexyFilter2(int32 *in, int32 count)
24 x=2*M_PI*6000/FSettings.SndRate;
25 p=((double)2-cos(x)) - sqrt(pow((double)2-cos(x),2) -1 );
28 //printf("%f\n",(double)c/0x100000);
35 dropcurrent=((*in<<16)-acc)>>3;
40 //acc=((int64)0x100000-c)* *in + ((c*acc)>>20);
47 void SexyFilter(int32 *in, int16 *out, int32 count)
49 static int64 acc1=0,acc2=0;
52 mul1=(94<<16)/FSettings.SndRate;
53 mul2=(24<<16)/FSettings.SndRate;
54 vmul=(FSettings.SoundVolume<<16)*3/4/100;
57 if(FSettings.soundq) vmul/=4;
60 vmul*=2; /* TODO: Increase volume in low quality sound rendering code itself */
64 int64 ino=(int64)*in*vmul;
65 acc1+=((ino-acc1)*mul1)>>16;
66 acc2+=((ino-acc1-acc2)*mul2)>>16;
70 int32 t=(acc1-ino+acc2)>>16;
71 //if(t>32767 || t<-32768) printf("Flow: %d\n",t);
73 if(t<-32768) t=-32768;
82 /* Returns number of samples written to out. */
83 /* leftover is set to the number of samples that need to be copied
84 from the end of in to the beginning of in.
87 //static uint32 mva=1000;
89 /* This filtering code assumes that almost all input values stay below 32767.
90 Do not adjust the volume in the wlookup tables and the expansion sound
91 code to be higher, or you *might* overflow the FIR code.
95 int32 NeoFilterSound(int32 *in, int32 *out, uint32 inlen, int32 *leftover)
102 // for(x=0;x<inlen;x++)
104 // if(in[x]>mva){ mva=in[x]; printf("%ld\n",in[x]);}
108 if(FSettings.soundq==2)
109 for(x=mrindex;x<max;x+=mrratio)
115 for(c=SQ2NCOEFFS,S=&in[(x>>16)-SQ2NCOEFFS],D=sq2coeffs;c;c--,D++)
118 acc2+=(S[1+c]**D)>>6;
121 acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11);
127 for(x=mrindex;x<max;x+=mrratio)
133 for(c=NCOEFFS,S=&in[(x>>16)-NCOEFFS],D=coeffs;c;c--,D++)
136 acc2+=(S[1+c]**D)>>6;
139 acc=((int64)acc*(65536-(x&65535))+(int64)acc2*(x&65535))>>(16+11);
147 if(FSettings.soundq==2)
149 mrindex+=SQ2NCOEFFS*65536;
150 *leftover=SQ2NCOEFFS+1;
154 mrindex+=NCOEFFS*65536;
158 if(GameExpSound.NeoFill)
159 GameExpSound.NeoFill(outsave,count);
161 SexyFilter(outsave,outsave,count);
162 if(FSettings.lowpass)
163 SexyFilter2(outsave,count);
168 void MakeFilters(int32 rate)
170 int32 *tabs[6]={C44100NTSC,C44100PAL,C48000NTSC,C48000PAL,C96000NTSC,
173 int32 *sq2tabs[6]={SQ2C44100NTSC,SQ2C44100PAL,SQ2C48000NTSC,SQ2C48000PAL,
174 SQ2C96000NTSC,SQ2C96000PAL};
182 if(FSettings.soundq==2)
189 mrratio=(PAL?(int64)(PAL_CPU*65536):(int64)(NTSC_CPU*65536))/rate;
192 if(FSettings.soundq==2)
193 tmp=sq2tabs[(PAL?1:0)|(rate==48000?2:0)|(rate==96000?4:0)];
196 tmp=tabs[(PAL?1:0)|(rate==48000?2:0)|(rate==96000?4:0)];
199 if(FSettings.soundq==2)
200 for(x=0;x<SQ2NCOEFFS>>1;x++)
201 sq2coeffs[x]=sq2coeffs[SQ2NCOEFFS-1-x]=tmp[x];
204 for(x=0;x<NCOEFFS>>1;x++)
205 coeffs[x]=coeffs[NCOEFFS-1-x]=tmp[x];
208 /* Some tests involving precision and error. */
212 for(x=0;x<SQ2NCOEFFS;x++)
213 acc+=(int64)32767*sq2coeffs[x];
214 printf("Foo: %lld\n",acc);