Expressed triangular wave as a function of the associated sawtooth-shape wave

This commit is contained in:
Fabio Manganiello 2018-12-27 17:33:05 +01:00
parent debf9a017b
commit 2e82651dbf

View file

@ -145,12 +145,11 @@ class Sound(object):
if self.shape == WaveShape.SQUARE:
wave[wave < 0] = -1
wave[wave >= 0] = 1
elif self.shape == WaveShape.SAWTOOTH:
elif self.shape == WaveShape.SAWTOOTH or self.shape == WaveShape.TRIANG:
wave = 2 * (self.frequency*x -
np.floor(0.5 + self.frequency*x))
elif self.shape == WaveShape.TRIANG:
wave = 2 * np.abs(2 * (self.frequency*x -
np.floor(0.5 + self.frequency*x))) -1
if self.shape == WaveShape.TRIANG:
wave = 2 * np.abs(wave) - 1
else:
raise RuntimeError('Unsupported wave shape: {}'.format(self.shape))