From 310e8fc768631e0d242472ac151bf5ab8fec7f4c Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 10 Apr 2022 20:48:40 +0200 Subject: [PATCH] Avoid using floating-point operation This has varying behavior depending on toolchain and processor. Fixes #1151 --- src/libespeak-ng/voices.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index add6b94e..6bd83838 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -222,7 +222,6 @@ static void SetToneAdjust(voice_t *voice, int *tone_pts) int freq2; int height1 = tone_pts[1]; int height2; - double rate; for (pt = 0; pt < 12; pt += 2) { if (tone_pts[pt] == -1) { @@ -233,10 +232,8 @@ static void SetToneAdjust(voice_t *voice, int *tone_pts) freq2 = tone_pts[pt] / 8; // 8Hz steps height2 = tone_pts[pt+1]; if ((freq2 - freq1) > 0) { - rate = (double)(height2-height1)/(freq2-freq1); - for (ix = freq1; ix < freq2; ix++) { - y = height1 + (int)(rate * (ix-freq1)); + y = height1 + (int)((ix-freq1) * (height2-height1) / (freq2-freq1)); if (y > 255) y = 255; voice->tone_adjust[ix] = y;