aboutsummaryrefslogtreecommitdiff
path: root/yue.py
diff options
context:
space:
mode:
authorAnthony Wang2023-03-21 22:56:34 -0400
committerAnthony Wang2023-03-21 22:56:34 -0400
commit5bba29570edb05a58845236134ab5f917bb0a70d (patch)
treea068382fdd7b44bbe77c43701cbe7ceea5820ce0 /yue.py
parent838cdb14879a80199579fbbb7cc828589f391559 (diff)
Implement saw wave and honk waveformHEADmaster
Diffstat (limited to 'yue.py')
-rw-r--r--yue.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/yue.py b/yue.py
index 5ded276..7435d48 100644
--- a/yue.py
+++ b/yue.py
@@ -8,6 +8,13 @@ bitrate = 44100
music = []
+def saw(x):
+ """
+ Sawtooth wave
+ """
+ return x / 2 / math.pi % 1
+
+
def freq(octave, step):
"""
Returns the frequency of a note
@@ -45,6 +52,16 @@ def seething(f, t):
return Y
+def honk(f, t):
+ """
+ Returns the intensity of the "honk" waveform of frequency f sampled at time t
+ """
+ w = 2 * math.pi * f
+ Y = sum([(saw(i * w * t) / 3 + math.sin(i * w * t)) * math.exp(-0.002 * w * t) for i in range(1, 6)]) / 2
+ Y = math.copysign(abs(Y) ** (1 / 2), Y)
+ return Y
+
+
def at(t):
"""
Returns the total intensity of music sampled at time t