Skip to content

Commit 37845a2

Browse files
committed
SineFromTable - change freq only at 360 degrees
1 parent 03a8d27 commit 37845a2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/AudioEffects/SoundGenerator.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ class SineWaveGenerator : public SoundGenerator<T>{
220220
float m_deltaTime = 0.0;
221221
float m_phase = 0.0;
222222
float double_Pi = PI * 2.0;
223-
float divisor = 1000000;
224223

225224

226225
void logStatus() {
@@ -490,11 +489,14 @@ class SineFromTable : public SoundGenerator<T> {
490489
angle += step;
491490
if (angle >= 360){
492491
angle -= 360;
492+
// update frequency at start of circle (near 0 degrees)
493+
step = step_new;
493494
}
494495
return amplitude * interpolate(angle);
495496
}
496497

497498
bool begin() {
499+
is_first = true;
498500
GeneratorFromArray<float>::begin();
499501
base_frequency = SoundGenerator<T>::audioInfo().sample_rate / 360.0; //122.5 hz (at 44100); 61 hz (at 22050)
500502
return true;
@@ -507,14 +509,20 @@ class SineFromTable : public SoundGenerator<T> {
507509
}
508510

509511
void setFrequency(float freq) {
510-
step = freq / base_frequency;
511-
LOGI("step: %f", step);
512+
step_new = freq / base_frequency;
513+
if (is_first){
514+
step = step_new;
515+
is_first = false;
516+
}
517+
LOGI("step: %f", step_new);
512518
}
513519

514520
protected:
521+
bool is_first = true;
515522
float amplitude;
516523
float base_frequency;
517524
float step = 1.0;
525+
float step_new = 1.0;
518526
float angle = 0;
519527
const float values[181] = {0, 0.0174524, 0.0348995, 0.052336, 0.0697565, 0.0871557, 0.104528, 0.121869, 0.139173, 0.156434, 0.173648, 0.190809, 0.207912, 0.224951, 0.241922, 0.258819, 0.275637, 0.292372, 0.309017, 0.325568, 0.34202, 0.358368, 0.374607, 0.390731, 0.406737, 0.422618, 0.438371, 0.45399, 0.469472, 0.48481, 0.5, 0.515038, 0.529919, 0.544639, 0.559193, 0.573576, 0.587785, 0.601815, 0.615661, 0.62932, 0.642788, 0.656059, 0.669131, 0.681998, 0.694658, 0.707107, 0.71934, 0.731354, 0.743145, 0.75471, 0.766044, 0.777146, 0.788011, 0.798636, 0.809017, 0.819152, 0.829038, 0.838671, 0.848048, 0.857167, 0.866025, 0.87462, 0.882948, 0.891007, 0.898794, 0.906308, 0.913545, 0.920505, 0.927184, 0.93358, 0.939693, 0.945519, 0.951057, 0.956305, 0.961262, 0.965926, 0.970296, 0.97437, 0.978148, 0.981627, 0.984808, 0.987688, 0.990268, 0.992546, 0.994522, 0.996195, 0.997564, 0.99863, 0.999391, 0.999848, 1, 0.999848, 0.999391, 0.99863, 0.997564, 0.996195, 0.994522, 0.992546, 0.990268, 0.987688, 0.984808, 0.981627, 0.978148, 0.97437, 0.970296, 0.965926, 0.961262, 0.956305, 0.951057, 0.945519, 0.939693, 0.93358, 0.927184, 0.920505, 0.913545, 0.906308, 0.898794, 0.891007, 0.882948, 0.87462, 0.866025, 0.857167, 0.848048, 0.838671, 0.829038, 0.819152, 0.809017, 0.798636, 0.788011, 0.777146, 0.766044, 0.75471, 0.743145, 0.731354, 0.71934, 0.707107, 0.694658, 0.681998, 0.669131, 0.656059, 0.642788, 0.62932, 0.615661, 0.601815, 0.587785, 0.573576, 0.559193, 0.544639, 0.529919, 0.515038, 0.5, 0.48481, 0.469472, 0.45399, 0.438371, 0.422618, 0.406737, 0.390731, 0.374607, 0.358368, 0.34202, 0.325568, 0.309017, 0.292372, 0.275637, 0.258819, 0.241922, 0.224951, 0.207912, 0.190809, 0.173648, 0.156434, 0.139173, 0.121869, 0.104528, 0.0871557, 0.0697565, 0.052336, 0.0348995, 0.0174524, 0};
520528

0 commit comments

Comments
 (0)