@@ -273,7 +273,7 @@ float funcgen::random_DC()
273
273
274
274
float funcgen::trapezium1 (float t)
275
275
{
276
- t += _phase + _period / 8 ; // zero point for t = 0
276
+ t += _phase + _period * _dutyCycle / 4 ; // zero point for t = 0
277
277
if (t < 0 )
278
278
{
279
279
t = -t;
@@ -282,26 +282,26 @@ float funcgen::trapezium1(float t)
282
282
283
283
if (t < _period * 0.5 * _dutyCycle) // rising part
284
284
{
285
- return -_amplitude + 2 * _amplitude * (t * 2 / (_period * _dutyCycle));
285
+ return _yShift + -_amplitude + 2 * _amplitude * (t * 2 / (_period * _dutyCycle));
286
286
}
287
287
else if (t < _period * 0.5 ) // high part
288
288
{
289
- return _amplitude;
289
+ return _yShift + _amplitude;
290
290
}
291
291
else if (t < _period * (0.5 + 0.5 * _dutyCycle)) // falling part
292
292
{
293
- return _amplitude - 2 * _amplitude * ( (t * 2 - _period) / (_period * _dutyCycle));
293
+ return _yShift + _amplitude - 2 * _amplitude * ( (t * 2 - _period) / (_period * _dutyCycle));
294
294
}
295
295
else // low part
296
296
{
297
- return -_amplitude;
297
+ return _yShift + -_amplitude;
298
298
}
299
299
}
300
300
301
301
302
302
float funcgen::trapezium2 (float t)
303
303
{
304
- t += _phase + _period / 8 ; // zero point for t = 0
304
+ t += _phase + _period * _dutyCycle / 4 ; // zero point for t = 0
305
305
if (t < 0 )
306
306
{
307
307
t = -t;
@@ -310,19 +310,19 @@ float funcgen::trapezium2(float t)
310
310
311
311
if (t < _period * 0.25 ) // rising part
312
312
{
313
- return -_amplitude + 2 * _amplitude * (t * 4 / _period);
313
+ return _yShift + -_amplitude + 2 * _amplitude * (t * 4 / _period);
314
314
}
315
315
else if (t < _period * (0.25 + 0.5 * _dutyCycle)) // high part
316
316
{
317
- return _amplitude;
317
+ return _yShift + _amplitude;
318
318
}
319
319
else if (t < _period * (0.5 + 0.5 * _dutyCycle)) // falling part
320
320
{
321
- return _amplitude - 2 * _amplitude * ((t - _period * (0.25 + 0.5 * _dutyCycle)) * 4 / _period);
321
+ return _yShift + _amplitude - 2 * _amplitude * ((t - _period * (0.25 + 0.5 * _dutyCycle)) * 4 / _period);
322
322
}
323
323
else // low part
324
324
{
325
- return -_amplitude;
325
+ return _yShift + -_amplitude;
326
326
}
327
327
}
328
328
@@ -331,6 +331,7 @@ float funcgen::trapezium2(float t)
331
331
// no DC version (50%
332
332
float funcgen::trapezium(float t)
333
333
{
334
+ t += _phase;
334
335
if (t < 0)
335
336
{
336
337
t = -t;
@@ -357,6 +358,35 @@ float funcgen::trapezium(float t)
357
358
*/
358
359
359
360
361
+ //
362
+ // EXPERIMENTAL HEARTBEAT (FREQ = 72.0 / 60.0 ~ 1.2
363
+ // based upon MultiMap
364
+ // in array is normalized to 0.0 - 1.0
365
+ //
366
+ // Heart beat phase P Q R S T U
367
+ float in[21 ] = { 0.0 , 0.07 , 0.13 , 0.20 , 0.27 , 0.33 , 0.40 , 0.46 , 0.53 , 0.60 , 0.66 , 0.73 , 0.80 , 0.86 , 0.93 , 1.00 };
368
+ float out[21 ] = { 0.0 , 0.00 , 0.10 , 0.25 , 0.10 , 0.10 , -0.05 , 1.00 , -0.25 , 0.20 , 0.25 , 0.30 , 0.30 , 0.20 , 0.00 , 0.00 };
369
+
370
+
371
+ float funcgen::mm (float t)
372
+ {
373
+ t += _phase;
374
+ t = fmod (t, _period);
375
+
376
+ // normalize t to 0.0 - 1.0
377
+ t *= _freq1;
378
+ // search interval
379
+ int idx = 0 ;
380
+ while (t > in[idx]) idx++;
381
+ if (t == in[idx]) return _yShift + _amplitude * out[idx];
382
+ idx--;
383
+ // interpolate.
384
+ float factor = (t - in[idx]) / (in[idx+1 ] - in[idx]);
385
+ return _yShift + _amplitude * (out[idx] + factor * (out[idx+1 ] - out[idx]));
386
+ }
387
+
388
+
389
+
360
390
// ///////////////////////////////////////////////////////////
361
391
//
362
392
// PRIVATE
0 commit comments