Hello Everyone!
My first post, and a bug + solution report
I have been working on a Teensy3.1 + Audio board based test signal generator oriented towards building music instruments and various effects. You can see and here the first concept testing here:
While doing this i encountered two bugs in the synth_tonesweep.cpp component.
The first one is allowing the t_time variable to be zero, which results in divide by zero operation and makes the sweep hang - it never stops.
line #57 in synth_tonesweep.cpp
should be changed to
The second one is related to negative sweeps, when the tone_hi is less than tone_lo.
The problem shows up when the sweep is quite fast, resulting in a higher tone_incr value, which might end up being more than the low threshold (or start frequency).
It may lead to tone_freq underflow, as it is an unsigned type variable and never meeting the (tmp < tone_hi) stop condition.
Here is my proposed solution:
starting from line #107 in synth_tonesweep.cpp
The last one is not an issue, but an upgrade.
I wanted to display the currently generated frequency. For that i added a short function getFreq().
In synth_tonesweep.h add
in the public section.
The body of the function is placed in synth_tonesweep.cpp
Ie, having the start and stop frequencies + the current sweep position it is possible to display it as a nice bargraph.
Cheers!
--
Piotr
My first post, and a bug + solution report
I have been working on a Teensy3.1 + Audio board based test signal generator oriented towards building music instruments and various effects. You can see and here the first concept testing here:
While doing this i encountered two bugs in the synth_tonesweep.cpp component.
The first one is allowing the t_time variable to be zero, which results in divide by zero operation and makes the sweep hang - it never stops.
line #57 in synth_tonesweep.cpp
Code:
if(t_time < 0)return false;
Code:
if(t_time <= 0)return false;
The second one is related to negative sweeps, when the tone_hi is less than tone_lo.
The problem shows up when the sweep is quite fast, resulting in a higher tone_incr value, which might end up being more than the low threshold (or start frequency).
It may lead to tone_freq underflow, as it is an unsigned type variable and never meeting the (tmp < tone_hi) stop condition.
Here is my proposed solution:
starting from line #107 in synth_tonesweep.cpp
Code:
if(tone_sign > 0) {
if(tmp > tone_hi) {
sweep_busy = 0;
break;
}
tone_freq += tone_incr;
} else {
if(tmp < tone_hi || tone_freq < tone_incr){ //we need to check if the actual current frequency
//is not less than the freq step, too
sweep_busy = 0; //otherwise tone_freq will underflow...
break;
}
tone_freq -= tone_incr; //...right here
}
The last one is not an issue, but an upgrade.
I wanted to display the currently generated frequency. For that i added a short function getFreq().
In synth_tonesweep.h add
Code:
int getFreq(void);
The body of the function is placed in synth_tonesweep.cpp
Code:
int AudioSynthToneSweep::getFreq(void)
{
return(tone_freq>>32);
}
Ie, having the start and stop frequencies + the current sweep position it is possible to display it as a nice bargraph.
Cheers!
--
Piotr