Debian Codegraph @

ext/psmplug/snd_flt.cpp

raw symbols SCIP
1 /*
2 * This source code is public domain.
3 *
4 * Authors: Olivier Lapicque <[email protected]>
5 */
6
7 #include "stdafx.h"
8 #include "sndfile.h"
9
10 // AWE32: cutoff = reg[0-255] * 31.25 + 100 -> [100Hz-8060Hz]
11 // EMU10K1 docs: cutoff = reg[0-127]*62+100
12 #define FILTER_PRECISION 8192
13
14 #ifndef NO_FILTER
15
16 #include <math.h>
17
18 DWORD CSoundFile::CutOffToFrequency(UINT nCutOff, int flt_modifier) const
19 //-----------------------------------------------------------------------
20 {
21 float Fc;
22
23 if (m_dwSongFlags & SONG_EXFILTERRANGE)
24 Fc = 110.0f * pow(2.0f, 0.25f + ((float)(nCutOff*(flt_modifier+256)))/(21.0f*512.0f));
25 else
26 Fc = 110.0f * pow(2.0f, 0.25f + ((float)(nCutOff*(flt_modifier+256)))/(24.0f*512.0f));
27 LONG freq = (LONG)Fc;
28 if (freq < 120) return 120;
29 if (freq > 10000) return 10000;
30 if (freq*2 > (LONG)gdwMixingFreq) freq = gdwMixingFreq>>1;
31 return (DWORD)freq;
32 }
33
34
35 // Simple 2-poles resonant filter
36 void CSoundFile::SetupChannelFilter(MODCHANNEL *pChn, BOOL bReset, int flt_modifier) const
37 //----------------------------------------------------------------------------------------
38 {
39 float fc = (float)CutOffToFrequency(pChn->nCutOff, flt_modifier);
40 float fs = (float)gdwMixingFreq;
41 float fg, fb0, fb1;
42
43 fc *= (float)(2.0*3.14159265358/fs);
44 float dmpfac = pow(10.0f, -((24.0f / 128.0f)*(float)pChn->nResonance) / 20.0f);
45 float d = (1.0f-2.0f*dmpfac)* fc;
46 if (d>2.0) d = 2.0;
47 d = (2.0f*dmpfac - d)/fc;
48 float e = pow(1.0f/fc,2.0f);
49
50 fg=1/(1+d+e);
51 fb0=(d+e+e)/(1+d+e);
52 fb1=-e/(1+d+e);
53
54 pChn->nFilter_A0 = (int)(fg * FILTER_PRECISION);
55 pChn->nFilter_B0 = (int)(fb0 * FILTER_PRECISION);
56 pChn->nFilter_B1 = (int)(fb1 * FILTER_PRECISION);
57
58 if (bReset)
59 {
60 pChn->nFilter_Y1 = pChn->nFilter_Y2 = 0;
61 pChn->nFilter_Y3 = pChn->nFilter_Y4 = 0;
62 }
63 pChn->dwFlags |= CHN_FILTER;
64 }
65
66 #endif // NO_FILTER