MCPcopy Create free account
hub / github.com/BatchDrake/SigDigger / sampleZeroCrossing

Method sampleZeroCrossing

Tasks/WaveSampler.cpp:215–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215bool
216WaveSampler::sampleZeroCrossing(void)
217{
218 long amount = SCAST(long, this->properties.length) - this->p;
219 long p = this->p;
220 bool last = false;
221 long i = 0;
222 SUCOMPLEX x = 0, prev = this->prevSample;
223 SUFLOAT var = 0, prevVar = this->prevVar;
224 SUFLOAT thres = 0;
225
226 if (amount > SIGDIGGER_WAVESAMPLER_FEEDER_BLOCK_LENGTH)
227 amount = SIGDIGGER_WAVESAMPLER_FEEDER_BLOCK_LENGTH;
228
229 last = p + amount >= SCAST(long, this->properties.length);
230
231 this->set.len = 0;
232
233 if (this->properties.amplitude)
234 thres = SU_C_REAL(
235 this->properties.threshold * SU_C_CONJ(this->properties.threshold));
236 else
237 thres = SU_C_REAL(
238 this->properties.threshold * this->properties.zeroCrossingAngle);
239
240 while (amount--) {
241 switch (this->properties.space) {
242 case AMPLITUDE:
243 if (this->properties.amplitude)
244 var = SU_C_REAL(
245 this->properties.data[p]
246 * SU_C_CONJ(this->properties.data[p]));
247 else
248 var = SU_C_REAL(
249 this->properties.data[p]
250 * this->properties.zeroCrossingAngle);
251
252 var -= thres;
253 break;
254
255 case PHASE:
256 var = SU_C_ARG(
257 this->properties.data[p] * this->properties.zeroCrossingAngle);
258 break;
259
260 case FREQUENCY:
261 x = this->properties.data[p];
262 var = SU_C_ARG(I * x * SU_C_CONJ(prev));
263 prev = x;
264 break;
265 }
266
267 if ((var > 0 || var < 0) || last) {
268 /* Zero crossing? */
269 if (var * prevVar < 0 || last) {
270 long samples = p - this->lastZc;
271 long symbols = SCAST(long, round(samples * this->bnor));
272

Callers 1

workMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected