Mercurial > hg > x
comparison procedures.h @ 1:6422640a802f
first upload
author | Wen X <xue.wen@elec.qmul.ac.uk> |
---|---|
date | Tue, 05 Oct 2010 10:45:57 +0100 |
parents | |
children | 5f3c32dc6e17 |
comparison
equal
deleted
inserted
replaced
0:9b9f21935f24 | 1:6422640a802f |
---|---|
1 #ifndef proceduresH | |
2 #define proceduresH | |
3 | |
4 /* | |
5 procedures.cpp - this file collects miscellaneous structures and functions. Not all of these are | |
6 referenced somewhere else. | |
7 */ | |
8 | |
9 | |
10 //--------------------------------------------------------------------------- | |
11 #include <memory.h> | |
12 #include <stdlib.h> | |
13 #include <values.h> | |
14 #include "fft.h" | |
15 #include "windowfunctions.h" | |
16 | |
17 /* | |
18 macro testnn: non-negative test. This macro throws out an exception if the value of x is negative. | |
19 */ | |
20 #ifndef testnn | |
21 #define testnn(x) {try{if (x<0) throw("testnn");}catch(...){x=0;}} | |
22 #endif | |
23 | |
24 /* | |
25 macro AllocateGMM and ReleaseGMM: allocates and frees buffers that hosts descriptors of a Gaussian- | |
26 mixture model. | |
27 */ | |
28 #define AllocateGMM(_MIXS, _DIM, _P, _M, _DEV) \ | |
29 double* _P=new double[_MIXS]; double** _M=new double*[_MIXS]; double ** _DEV=new double*[_MIXS]; \ | |
30 _M[0]=new double[(_MIXS)*(_DIM)]; _DEV[0]=new double[(_MIXS)*(_DIM)]; \ | |
31 for (int _MIX=1; _MIX<_MIXS; _MIX++) _M[_MIX]=&_M[0][_MIX*(_DIM)], _DEV[_MIX]=&_DEV[0][_MIX*(_DIM)]; | |
32 #define ReleaseGMM(_P, _M, _DEV) \ | |
33 delete[] _P; if (_M) {delete[] _M[0]; delete[] _M;} if (_DEV) {delete[] _DEV[0]; delete[] _DEV;} | |
34 | |
35 | |
36 //--------------------------------------------------------------------------- | |
37 /* | |
38 Tick count tool (stop watch) is made up of a TickClock struct and three macros that uses this | |
39 structure as augument. | |
40 | |
41 Use of TickClock: declare the instance directly. Use StartClock() and StopClock() to start and stop | |
42 tick counting. Each time the clock is stopped the interval between last start and stop operations is | |
43 added to run-time t. Clear the recorded run-time with ResetClock(). | |
44 */ | |
45 struct TickClock //tick counter struct | |
46 { | |
47 double t; //accumulated run time | |
48 __int64 Ticks; //tick count recorded at start trigger | |
49 __int64 Ticks2; //tick count recorded at stop trigger | |
50 }; | |
51 #define ResetClock(AClock) {AClock.t=0;} | |
52 #define StartClock(AClock) {AClock.Ticks=GetTickCount();} | |
53 #define StopClock(AClock) {AClock.Ticks2=GetTickCount(); AClock.t+=0.001*(AClock.Ticks2-AClock.Ticks);} | |
54 | |
55 //--------------------------------------------------------------------------- | |
56 | |
57 struct fftparams //buffers used by FFT routines | |
58 { | |
59 double* Amp; //amplitude output buffer | |
60 double* Arg; //phase angle output buffer | |
61 cdouble* w; //twiddle factor buffer | |
62 cdouble* x; //data buffer | |
63 }; | |
64 | |
65 struct TGMM //Gaussian mixture model | |
66 { | |
67 public: | |
68 bool mcs; | |
69 int mixs; //number of mixtures | |
70 int dim; //data dimension | |
71 double* p; //mixture weights | |
72 double** m; //mixture component centres | |
73 double** dev; //diagonal mixture component correlation | |
74 double acct; | |
75 TGMM(); | |
76 ~TGMM(); | |
77 }; | |
78 | |
79 struct TTFSpan //a rectanguar area in the T-F plane | |
80 { | |
81 int T1; //start time | |
82 int T2; //finish time | |
83 double F1; //lowest frequency | |
84 double F2; //highest frequency | |
85 }; | |
86 | |
87 struct TSpecPeak //spectral peak | |
88 { | |
89 int t; //time in samples | |
90 int tres; //time resolution | |
91 double f; //digital frequency | |
92 double fres; //frequency resolution | |
93 double df; //derivative of f | |
94 double am; //amplitude | |
95 double ph; //phase angle | |
96 }; | |
97 | |
98 /* | |
99 TSpecTrack is a class that maintains a list of TSpecPeak objects that form a spectral track. It models | |
100 a sinusid track in sinusoid modeling. | |
101 */ | |
102 class TSpecTrack | |
103 { | |
104 private: | |
105 int Capacity; //number of peaks the current storage space is allocated to host | |
106 public: | |
107 int t1; //time of first peak | |
108 int t2; //time of last peak | |
109 double fmin; //minimum peak frequency | |
110 double fmax; //maximum peak frequency | |
111 | |
112 int Count; //number of peaks in the track | |
113 TSpecPeak* Peaks; //peaks in the track, ordered by time | |
114 | |
115 TSpecTrack(int ACapacity=50); | |
116 ~TSpecTrack(); | |
117 | |
118 void InsertPeak(TSpecPeak& APeak, int index); | |
119 int LocatePeak(TSpecPeak& APeak); | |
120 int Add(TSpecPeak& APeak); | |
121 }; | |
122 | |
123 /* | |
124 TTFSpans is a class that maintains a list of TFSpans. This is used to mark selected areas in the time- | |
125 frequency plane for further processing. | |
126 */ | |
127 class TTFSpans | |
128 { | |
129 public: | |
130 int Count; //number of spans | |
131 int Capacity; //number of spans the current storage space is allocated to host | |
132 TTFSpan* Items; //the hosted spans | |
133 | |
134 TTFSpans(); | |
135 ~TTFSpans(); | |
136 void Add(TTFSpan& ATFSpan); | |
137 void Clear(); | |
138 int Delete(int Index); | |
139 }; | |
140 | |
141 double ACPower(double* data, int Count, void*); | |
142 void Add(double* dest, double* source, int Count); | |
143 void Add(double* out, double* addend, double* adder, int count); | |
144 void ApplyWindow(double* OutBuffer, double* Buffer, double* Weights, int Size); | |
145 double Avg(double*, int, void*); | |
146 void AvgFilter(double* dataout, double* data, int Count, int HWid); | |
147 int BitInv(int value, int order); | |
148 void CalculateSpectrogram(double* data, int Count, int start, int end, int Wid, int Offst, double* Window=0, double** Spec=0, double** Ph=0, double amp=1, bool half=true); | |
149 void Conv(double* out, int N1, double* in1, int N2, double* in2); | |
150 void DCT( double* output, double* input, int N); | |
151 void IDCT( double* output, double* input, int N); | |
152 double DCAmplitude(double*, int, void*); | |
153 double DCPower(double*, int, void*); | |
154 double ddIPHann(double, void*); | |
155 void DeDC(double* data, int Count, int HWid); | |
156 void DeDC_static(double* data, int Count); | |
157 void DoubleToInt(void* out, int BytesPerSample, double* in, int Count); | |
158 void DoubleToIntAdd(void* out, int BytesPerSample, double* in, int Count); | |
159 double DPower(double* data, int Count, void*); | |
160 double Energy(double* data, int Count); | |
161 double ExpOnsetFilter(double* dataout, double* data, int Count, double Tr, double Ta); | |
162 double ExpOnsetFilter_balanced(double* dataout, double* data, int Count, double Tr, double Ta, int bal=5); | |
163 double ExtractLinearComponent(double* dataout, double* data, int Count); | |
164 void FFTConv(double* dest, double* source1, int size1, double* source2, int size2, int zero=0, double* pre_buffer=NULL, double* post_buffer=NULL); | |
165 void FFTConv(unsigned char* dest, unsigned char* source1, int bps, int size1, double* source2, int size2, int zero=0, unsigned char* pre_buffer=NULL, unsigned char* post_buffer=NULL); | |
166 void FFTConv(double* dest, double* source1, int size1, double* source2, int size2, double* pre_buffer=NULL); | |
167 void FFTFilter(double* dataout, double* data, int Count, int Wid, int On, int Off); | |
168 void FFTFilterOLA(double* dataout, double* data, int Count, int Wid, int On, int Off, double* pre_buffer=NULL); | |
169 void FFTFilterOLA(unsigned char* dataout, unsigned char* data, int BytesPerSample, int Count, int Wid, int On, int Off, unsigned char* pre_buffer=NULL); | |
170 void FFTFilterOLA(double* dataout, double* data, int Count, double* amp, double* ph, int Wid, double* pre_buffer=NULL); | |
171 double FFTMask(double* dataout, double* data, int Count, int Wid, double DigiOn, double DigiOff, double maskcoef=1); | |
172 int FindInc(double value, double* data, int Count); | |
173 double Gaussian(int Dim, double* Vector, double* Mean, double* Dev, bool StartFrom1); | |
174 void HalfDCT(double* data, int Count, double* CC, int order); | |
175 double Hamming(double f, double T); | |
176 double Hann(double x, double N); | |
177 double HannSq(double x, double N); | |
178 int HxPeak2(double*& hps, double*& vhps, double (*F)(double, void*), double (*dF)(double, void*), double(*ddF)(double, void*), void* params, double st, double en, double epf=1e-6); | |
179 double I0(double x); | |
180 int InsertDec(double value, double* data, int Count); | |
181 int InsertDec(int value, int* data, int Count); | |
182 int InsertDec(double value, int index, double* data, int* indices, int Count); | |
183 int InsertInc(void* value, void** data, int Count, int (*Compare)(void*, void*)); | |
184 int InsertInc(double value, double* data, int Count, bool doinsert=true); | |
185 int InsertInc(double value, int index, double* data, int* indices, int Count); | |
186 int InsertInc(double value, double index, double* data, double* indices, int Count); | |
187 int InsertInc(double value, int* data, int Count, bool doinsert=true); | |
188 int InsertIncApp(double value, double* data, int Count); | |
189 double InstantFreq(int k, int hwid, cdouble* x, int mode=1); | |
190 void InstantFreq(double* freqspec, int hwid, cdouble* x, int mode=1); | |
191 void IntToDouble(double* out, void* in, int BytesPerSample, int Count); | |
192 double IPHannC(double f, cdouble* x, int N, int K1, int K2); | |
193 double IPHannC(double f, void* params); | |
194 double IPHannCP(double f, void* params); | |
195 void lse(double* x, double* y, int Count, double& a, double& b); | |
196 void memdoubleadd(double* dest, double* source, int count); | |
197 void MFCC(int FrameWidth, int NumBands, int Ceps_Order, double* Data, double* Bands, double* C, double* Amps, cdouble* W, cdouble* X); | |
198 double* MFCCPrepareBands(int NumberOfBands, int SamplesPerSec, int NumberOfBins); | |
199 void Multi(double* data, int count, double mul); | |
200 void Multi(double* out, double* in, int count, double mul); | |
201 void MultiAdd(double* out, double* in, double* adder, int count, double mul); | |
202 int NearestPeak(double* data, int count, int anindex); | |
203 double NegativeExp(double* x, double* y, int Count, double& lmd, int sample=1, double step=0.05, double eps=1e-6, int maxiter=50); | |
204 double NL(double* data, int Count, int Wid); | |
205 double Normalize(double* data, int Count, double Maxi=1); | |
206 double Normalize2(double* data, int Count, double Norm=1); | |
207 double nextdouble(double x, double dir); | |
208 double PhaseSpan(double* data, int Count, void*); | |
209 void PolyFit(int P, double* a, int N, double* x, double* y); | |
210 void Pow(double* data, int Count, double ex); | |
211 //int prevcand(candid** cands, int p, int n, int ap); | |
212 int Rectify(double* data, int Count, double th=0); | |
213 double Res(double in, double mod); | |
214 double Romberg(int n, double(*f)(double, void*), double a, double b, void* params=0); | |
215 double Romberg(double(*f)(double, void*), double a, double b, void* params=0, int maxiter=50, double ep=1e-6); | |
216 double sinca(double x); | |
217 double sincd_unn(double x, int N); | |
218 double SmoothPhase(double* Arg, int Count, int mpi=2); | |
219 //int SortCandid(candid cand, candid* cands, int newN); | |
220 double StiffB(double f0, double fm, int m); | |
221 double StiffFm(double f0, int m, double B); | |
222 double StiffF0(double fm, int m, double B); | |
223 double StiffM(double f0, double fm, double B); | |
224 void TFFilter(double* data, double* dataout, int Count, int Wid, TTFSpans* Spans, bool Pass, WindowType wt, double windp, int Sps, int TOffst=0); | |
225 void TFFilter(void* data, void* dataout, int BytesPerSample, int Count, int Wid, TTFSpans* Spans, bool Pass, WindowType wt, double windp, int Sps, int TOffst); | |
226 void TFMask(double* data, double* dataout, int Count, int Wid, TTFSpans* Spans, double masklevel, WindowType wt, double windp, int Sps, int TOffst); | |
227 void TFMask(void* data, void* dataout, int BytesPerSec, int Count, int Wid, TTFSpans* Spans, double masklevel, WindowType wt, double windp, int Sps, int TOffst); | |
228 //double dIPHannC(double f, void* params); | |
229 //void ddsIPWindowStiff(double& df0f0, double& df0B, double& dBB, double& df0, double& dB, double& y, double f0, double B, cdouble* x, int N, int M, double* c, double iH2, double hB, int maxp); | |
230 //void dsIPWindowStiff(double& df0, double& dB, double& y, double f0, double B, cdouble* x, int N, int M, double* c, double iH2, double hB, int maxp); | |
231 //double IPWindowStiff(double f0, double B, cdouble* x, int N, int M, double* c, double iH2, double* ffp, double* vfp, double* pfp, double hB, int maxp); | |
232 //double sIPWindowStiff(double f0, double B, cdouble* x, int N, int M, double* c, double iH2, double* ffp, double* vfp, double* pfp, double hB, int maxp); | |
233 //double sIPWindowStiff(double f0, double B, cdouble* x, int N, int M, double* c, double iH2, double hB, int maxp); | |
234 //double IPWindowMulti(double* f, int ss, cdouble* x, int N, int M, double* c, double iH2, int K1, int K2); | |
235 | |
236 #endif |