From 40e63482e0dca386581753d7019ff94517dcc5d6 Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Fri, 30 Sep 2011 08:22:41 +0100 Subject: [PATCH] klatt.cpp: fix a sound spike in setzeroabc when f == 0. If setzeroabc is passed f == 0, rp->a will be set to 0 and when the coefficients get inverted (a'=1/a, b'=b/a, c'=c/a) then a', b' and c' get set to INF. This results in an audible sound spike when these resonators get used. Found when investigating an issue in klatt with example1.par when using the cascade synthesis mode. Bug: https://github.com/rhdunn/klatt/issues/1. --- src/klatt.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/klatt.cpp b/src/klatt.cpp index f8b3a647..7048dcb6 100644 --- a/src/klatt.cpp +++ b/src/klatt.cpp @@ -884,11 +884,6 @@ static void setzeroabc(long int f, long int bw, resonator_ptr rp) f = -f; - if(f>=0) - { - f = -1; - } - /* First compute ordinary resonator coefficients */ /* Let r = exp(-pi bw t) */ arg = kt_globals.minus_pi_t * bw; @@ -904,10 +899,17 @@ static void setzeroabc(long int f, long int bw, resonator_ptr rp) /* Let a = 1.0 - b - c */ rp->a = 1.0 - rp->b - rp->c; - /* Now convert to antiresonator coefficients (a'=1/a, b'=b/a, c'=c/a) */ - rp->a = 1.0 / rp->a; - rp->c *= -rp->a; - rp->b *= -rp->a; + /* If f == 0 then rp->a gets set to 0 which makes a'=1/a set a', b' and c' to + * INF, causing an audible sound spike when triggered (e.g. apiration with the + * nasal register set to f=0, bw=0). + */ + if (rp->a != 0) + { + /* Now convert to antiresonator coefficients (a'=1/a, b'=b/a, c'=c/a) */ + rp->a = 1.0 / rp->a; + rp->c *= -rp->a; + rp->b *= -rp->a; + } }