comparison quickspec.cpp @ 5:5f3c32dc6e17

* Adjust comment syntax to permit Doxygen to generate HTML documentation; add Doxyfile
author Chris Cannam
date Wed, 06 Oct 2010 15:19:49 +0100
parents fc19d45615d1
children 9b1c0825cc77
comparison
equal deleted inserted replaced
4:92ee28024c05 5:5f3c32dc6e17
2 2
3 #include <math.h> 3 #include <math.h>
4 #include <memory.h> 4 #include <memory.h>
5 #include "quickspec.h" 5 #include "quickspec.h"
6 6
7 7 /** \file quickspec.h */
8 //--------------------------------------------------------------------------- 8
9 /* 9 //---------------------------------------------------------------------------
10 /**
10 method TQuickSpectrogram::TQuickSpectrogram: 11 method TQuickSpectrogram::TQuickSpectrogram:
11 12
12 In: AParent: pointer argument for calling G, if G is specified 13 In: AParent: pointer argument for calling G, if G is specified
13 AnId: integer argument for calling G, if G is specified 14 AnId: integer argument for calling G, if G is specified
14 G: pointer to a function that supplies buffers used for FFT, 0 by default 15 G: pointer to a function that supplies buffers used for FFT, 0 by default
37 free8(fwin); 38 free8(fwin);
38 free(fhbi); 39 free(fhbi);
39 }//~TQuickSpectrogram 40 }//~TQuickSpectrogram
40 41
41 //--------------------------------------------------------------------------- 42 //---------------------------------------------------------------------------
42 /* 43 /**
43 method TQuickSpectrogram::A: accesses amplitude spectrogram by frame 44 method TQuickSpectrogram::A: accesses amplitude spectrogram by frame
44 45
45 In: fr: frame index, 0-based 46 In: fr: frame index, 0-based
46 47
47 Returns pointer to amplitude spectrum of the fr'th frame, NULL if N/A 48 Returns pointer to amplitude spectrum of the fr'th frame, NULL if N/A
53 if (Frame[fr]<0 || !Valid[fr]) CalculateSpectrum(fr); 54 if (Frame[fr]<0 || !Valid[fr]) CalculateSpectrum(fr);
54 return fA[Frame[fr]]; 55 return fA[Frame[fr]];
55 }//A 56 }//A
56 57
57 //--------------------------------------------------------------------------- 58 //---------------------------------------------------------------------------
58 /* 59 /**
59 method TQuickSpectrogram::AddBuffer: increases internal buffer by BufferSize frames. Allocated buffers 60 method TQuickSpectrogram::AddBuffer: increases internal buffer by BufferSize frames. Allocated buffers
60 beyond Capacity frames will not be indexed or used by TQuickSpectrogram. 61 beyond Capacity frames will not be indexed or used by TQuickSpectrogram.
61 */ 62 */
62 void TQuickSpectrogram::AddBuffer() 63 void TQuickSpectrogram::AddBuffer()
63 { 64 {
79 else break; 80 else break;
80 } 81 }
81 BufferCount++; 82 BufferCount++;
82 }//AddBuffer 83 }//AddBuffer
83 84
84 /* 85 /**
85 method TQuickSpectrogram::AddBuffer: increase internal buffer by a multiple of BufferSize so that 86 method TQuickSpectrogram::AddBuffer: increase internal buffer by a multiple of BufferSize so that
86 it will be enough to host another AddFrCount frames. 87 it will be enough to host another AddFrCount frames.
87 */ 88 */
88 void TQuickSpectrogram::AddBuffer(int AddFrCount) 89 void TQuickSpectrogram::AddBuffer(int AddFrCount)
89 { 90 {
90 while (FrCount+AddFrCount>BufferSize*BufferCount) AddBuffer(); 91 while (FrCount+AddFrCount>BufferSize*BufferCount) AddBuffer();
91 }//AddBuffer 92 }//AddBuffer
92 93
93 //--------------------------------------------------------------------------- 94 //---------------------------------------------------------------------------
94 /* 95 /**
95 function IntToDouble: copy content of integer array to double array 96 function IntToDouble: copy content of integer array to double array
96 97
97 In: in: pointer to integer array 98 In: in: pointer to integer array
98 BytesPerSample: number of bytes each integer takes 99 BytesPerSample: number of bytes each integer takes
99 Count: size of integer array, in integers 100 Count: size of integer array, in integers
106 if (BytesPerSample==1){unsigned char* in8=(unsigned char*)in; for (int k=0; k<Count; k++) *(out++)=*(in8++)-128.0;} 107 if (BytesPerSample==1){unsigned char* in8=(unsigned char*)in; for (int k=0; k<Count; k++) *(out++)=*(in8++)-128.0;}
107 else if (BytesPerSample==2) {__int16* in16=(__int16*)in; for (int k=0; k<Count; k++) *(out++)=*(in16++);} 108 else if (BytesPerSample==2) {__int16* in16=(__int16*)in; for (int k=0; k<Count; k++) *(out++)=*(in16++);}
108 else {__pint24 in24=(__pint24)in; for (int k=0; k<Count; k++) *(out++)=*(in24++);} 109 else {__pint24 in24=(__pint24)in; for (int k=0; k<Count; k++) *(out++)=*(in24++);}
109 }//IntToDouble 110 }//IntToDouble
110 111
111 /* 112 /**
112 function CalculateSpectrum: calculate spectrum of a signal in integer format 113 function CalculateSpectrum: calculate spectrum of a signal in integer format
113 114
114 In: Data[Wid]: integer array hosting waveform data 115 In: Data[Wid]: integer array hosting waveform data
115 BytesPerSample: number of bytes each integer in Data[] takes 116 BytesPerSample: number of bytes each integer in Data[] takes
116 win[Wid]: window function used for computing spectrum 117 win[Wid]: window function used for computing spectrum
130 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y); 131 Amp[j]=sqrt(x[j].x*x[j].x+x[j].y*x[j].y);
131 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x); 132 if (Arg) Arg[j]=(x[j].y==0 && x[j].x==0)?0:atan2(x[j].y, x[j].x);
132 } 133 }
133 }//CalculateSpectrum 134 }//CalculateSpectrum
134 135
135 /* 136 /**
136 function CalculateSpectrum: calculate spectrum of a signal in integer format, allowing the signal 137 function CalculateSpectrum: calculate spectrum of a signal in integer format, allowing the signal
137 length $eff be shorter than the DFT size Wid. 138 length $eff be shorter than the DFT size Wid.
138 139
139 In: Data[eff]: integer array hosting waveform data 140 In: Data[eff]: integer array hosting waveform data
140 BytesPerSample: number of bytes each integer in Data[] takes 141 BytesPerSample: number of bytes each integer in Data[] takes
166 } 167 }
167 else 168 else
168 CalculateSpectrum(Data, BytesPerSample, win, Amp, Arg, Wid, w, x, hbi); 169 CalculateSpectrum(Data, BytesPerSample, win, Amp, Arg, Wid, w, x, hbi);
169 }//CalculateSpectrum 170 }//CalculateSpectrum
170 171
171 /* 172 /**
172 method TQuickSpectrogram::CalculateSpectrum: computes spectrogram at fr'th frame. 173 method TQuickSpectrogram::CalculateSpectrum: computes spectrogram at fr'th frame.
173 174
174 In: fr: index to the frame whose spectrum is to be computed. fr must be between 0 and Capacity-1. 175 In: fr: index to the frame whose spectrum is to be computed. fr must be between 0 and Capacity-1.
175 */ 176 */
176 void __fastcall TQuickSpectrogram::CalculateSpectrum(int fr) 177 void __fastcall TQuickSpectrogram::CalculateSpectrum(int fr)
227 //tag this frame as computed and valid 228 //tag this frame as computed and valid
228 Valid[fr]=1; 229 Valid[fr]=1;
229 }//CalculateSpectrum 230 }//CalculateSpectrum
230 231
231 //--------------------------------------------------------------------------- 232 //---------------------------------------------------------------------------
232 /* 233 /**
233 method TQuickSpectrogram::FreeBuffers: discards all computed spectra and free all internal buffers. 234 method TQuickSpectrogram::FreeBuffers: discards all computed spectra and free all internal buffers.
234 This returns the TQuickSpectrogram to its initial state before any frame is accessed. After calling 235 This returns the TQuickSpectrogram to its initial state before any frame is accessed. After calling
235 FreeBuffers() all frames will be recomputed when they are accessed. 236 FreeBuffers() all frames will be recomputed when they are accessed.
236 */ 237 */
237 void TQuickSpectrogram::FreeBuffers() 238 void TQuickSpectrogram::FreeBuffers()
247 if (usex) {free(fSpec); fSpec=0;} 248 if (usex) {free(fSpec); fSpec=0;}
248 } 249 }
249 }//FreeBuffers 250 }//FreeBuffers
250 251
251 //--------------------------------------------------------------------------- 252 //---------------------------------------------------------------------------
252 /* 253 /**
253 method TQuickSpectrogram::Invalidate: renders all frames that have overlap with interval [From, To], 254 method TQuickSpectrogram::Invalidate: renders all frames that have overlap with interval [From, To],
254 measured in samples, as invalid. Invalid frames are recomputed when they are accessed again. 255 measured in samples, as invalid. Invalid frames are recomputed when they are accessed again.
255 256
256 In: [From, To]: an interval spectrogram over which needs to be updated. 257 In: [From, To]: an interval spectrogram over which needs to be updated.
257 258
269 } 270 }
270 return result; 271 return result;
271 }//Invalidate 272 }//Invalidate
272 273
273 //--------------------------------------------------------------------------- 274 //---------------------------------------------------------------------------
274 /* 275 /**
275 method TQuickSpectrogram::Ph: accesses phase spectrogram by frame 276 method TQuickSpectrogram::Ph: accesses phase spectrogram by frame
276 277
277 In: fr: frame index, 0-based 278 In: fr: frame index, 0-based
278 279
279 Returns pointer to phase spectrum of the fr'th frame, NULL if N/A 280 Returns pointer to phase spectrum of the fr'th frame, NULL if N/A
285 if (Frame[fr]<0 || !Valid[fr]) CalculateSpectrum(fr); 286 if (Frame[fr]<0 || !Valid[fr]) CalculateSpectrum(fr);
286 return fPh[Frame[fr]]; 287 return fPh[Frame[fr]];
287 }//Ph 288 }//Ph
288 289
289 //--------------------------------------------------------------------------- 290 //---------------------------------------------------------------------------
290 /* 291 /**
291 method TQuickSpectrogram::SetFrCapacity: sets the capacity, i.e. the maximal number of frames handled 292 method TQuickSpectrogram::SetFrCapacity: sets the capacity, i.e. the maximal number of frames handled
292 by this TQuickSpectrogram. 293 by this TQuickSpectrogram.
293 294
294 In: AnFrCapacity: the new Capacity, in frames 295 In: AnFrCapacity: the new Capacity, in frames
295 296
329 } 330 }
330 Capacity=AnFrCapacity; 331 Capacity=AnFrCapacity;
331 }//SetFrCapacity 332 }//SetFrCapacity
332 333
333 //--------------------------------------------------------------------------- 334 //---------------------------------------------------------------------------
334 /* 335 /**
335 method TQuickSpectrogram::Ph: accesses complex spectrogram by frame 336 method TQuickSpectrogram::Ph: accesses complex spectrogram by frame
336 337
337 In: fr: frame index, 0-based 338 In: fr: frame index, 0-based
338 339
339 Returns pointer to complex spectrum of the fr'th frame, NULL if N/A 340 Returns pointer to complex spectrum of the fr'th frame, NULL if N/A