diff --git a/analyze_tonedetect_F32.cpp b/analyze_tonedetect_F32.cpp index 86affea..760a7b8 100644 --- a/analyze_tonedetect_F32.cpp +++ b/analyze_tonedetect_F32.cpp @@ -99,7 +99,7 @@ float AudioAnalyzeToneDetect_F32::read(void) { len = length; __enable_irq(); power = q1*q1 + q2*q2 - q1*q2*coef; - return 2.0f*sqrtf(power)/(float)len; // Scale to (0.0, 1.0) + return 2.0f*gain*sqrtf(power)/(float)len; // Scaled to gain*(0.0, 1.0) } AudioAnalyzeToneDetect_F32::operator bool() { @@ -112,7 +112,7 @@ AudioAnalyzeToneDetect_F32::operator bool() { q2 = out2; len = length; __enable_irq(); - power = q1*q1 + q2*q2 - q1*q2*coef; + power = gain*gain*(q1*q1 + q2*q2 - q1*q2*coef); trigger = (float)len * thresh; trigger *= trigger; //Serial.println("bool: power, trigger = "); Serial.print(power, 6); Serial.print(", "); Serial.println(trigger, 6); diff --git a/analyze_tonedetect_F32.h b/analyze_tonedetect_F32.h index 1ec40ac..ff56c72 100644 --- a/analyze_tonedetect_F32.h +++ b/analyze_tonedetect_F32.h @@ -32,6 +32,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + // Added setGain(gain) March 2023 Bob L #ifndef analyze_tonedetect_F32_h_ #define analyze_tonedetect_F32_h_ @@ -63,6 +64,10 @@ public: //(uint16_t)( ( (float)sample_rate_Hz/freq*(float)cycles) + 0.5f) ); } + void setGain(float _gain) { + gain = _gain; + } + bool available(void) { __disable_irq(); bool flag = new_output; @@ -91,6 +96,7 @@ private: float s1, s2; // Goertzel algorithm state float out1, out2; // Goertzel algorithm state output float power; + float gain = 1.0f; // Voltage gain, added Mar 2023 uint16_t length; // number of samples to analyze uint16_t count; // how many left to analyze uint16_t ncycles; // number of waveform cycles to seek