thanks for the ideas, ill definitely try them out!
In my simple tests, using nim, without SIMD, the Goerzel algorithem is two to three times as fast as the rotating vector in the youtube clip and about 10-11 times as fast as the standard sin (from C).
It takes just one multiplication and one subtraction, after the pre-calculation of the first two values.
A python example:
import math
def goerzel_sinosc(freq, duration, samplerate):
N = int(duration * samplerate)
w = 2.0 * math.pi * freq / samplerate
c = 2.0 * math.cos(w)
d1 = 0.0
d2 = 0.0
sine_wave = []
for n in range(N):
if n == 0:
d0 = 0.0
elif n == 1:
d0 = math.sin(w)
else:
d0 = c * d1 - d2
sine_wave.append(d0)
d2 = d1
d1 = d0
return sine_wave
frequency = 440
duration = 1.0
samplerate = 44100
sine_wave = goerzel_sinosc(frequency, duration, samplerate)
2 Likes