Sounderzeugung
This commit is contained in:
parent
fd221aa68b
commit
c934c858d3
Binary file not shown.
21
sound/gensound_test.py
Normal file
21
sound/gensound_test.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
from gensound import Sine, Triangle, Square, Pan
|
||||||
|
|
||||||
|
sig = Triangle # Sine? Square?
|
||||||
|
|
||||||
|
beat = 0.5e3 # 120 bpm
|
||||||
|
fermata = 0.1 # make fermatas in the melody slightly longer
|
||||||
|
pause = 0.6 # and breathe for a moment before starting the next phrase
|
||||||
|
|
||||||
|
S = sig(f"r D5 D=2 C#=1 B-13=2 A=1 D E=2 F#-13={2+fermata} r={pause} F#=1 F#=2 F#=1 E=2 F#-13=1 G F#-13=2 E={2+fermata} r={pause} "
|
||||||
|
f"D+16=1 E=2 F#-13=1 E=2 D+16=1 B-13 C#=2 D+9={2+fermata} r={pause} A'=1 F#-13=2 D+16=1 E=2 G=1 F#-13 E=2 D=3", beat)
|
||||||
|
A = sig(f"r A4 B=2 A+16=1 G=2 F#-13=1 F# B-13 A A={2+fermata} r={pause} C#=1 B=2 B=1 B A A A D A A={2+fermata} r={pause} "
|
||||||
|
f"B=1 A=2 A=1 B-13 A=0.5 G F#=1 B-13 B A#-13 B={2+fermata} r={pause} A=1 A=2 B=1 A=2 A=1 A B-13 A F#-13=3", beat)
|
||||||
|
T = sig(f"r F#4-13 F#=2 F#=1 D=2 D=1 D D C#-13 D={2+fermata} r={pause} C#=1 D+16=2 D+16=1 D C#-13 D E A, D C#-13={2+fermata} r={pause} "
|
||||||
|
f"F#=1 E=2 D=1 D C#-13 D+16 D G+5 F# F#={2+fermata} r={pause} E=1 F#-13=2 F#=1 E=2 C#-13=1 A B C#-13 D=3", beat)
|
||||||
|
B = sig(f"r D3 B-16 D F# G B-13 D B-16 G A D,={2+fermata} r={pause} A#'-13=1 B=2 A=1 G#-13 A F#-13 C#-13 D F#-13 A={2+fermata} r={pause} "
|
||||||
|
f"B=1 C#-13=2 D=1 G, A B G E F# B,={2+fermata} r={pause} C#'-13=1 D C# B C#-13 B A D G, A D,=3", beat)
|
||||||
|
|
||||||
|
chorale = S*Pan(25) + B*Pan(-25) + T*Pan(80) + A*Pan(-80) # position the voices in the stereo field
|
||||||
|
chorale.play() # can you spot the parallel octaves?
|
86
tk_first_steps/toene_mvc.py
Normal file
86
tk_first_steps/toene_mvc.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import tkinter as tk
|
||||||
|
from gensound import Sine
|
||||||
|
|
||||||
|
# Konstanten
|
||||||
|
|
||||||
|
c5= 523
|
||||||
|
b = 494
|
||||||
|
a = 440
|
||||||
|
g = 392
|
||||||
|
f = 349
|
||||||
|
e = 330
|
||||||
|
d = 294
|
||||||
|
c = 262
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------
|
||||||
|
|
||||||
|
# Melodie / Model
|
||||||
|
|
||||||
|
class Melody():
|
||||||
|
def __init__(self, melody = "c,e,g,c5,g,e,c"):
|
||||||
|
self.melody = melody
|
||||||
|
|
||||||
|
def play(self, duration = 0.5, amplitude = 0.5):
|
||||||
|
dur = duration * 1000
|
||||||
|
ampl = amplitude
|
||||||
|
|
||||||
|
s = Sine(frequency=440, duration=1)
|
||||||
|
|
||||||
|
tone_list = self.melody.split(',')
|
||||||
|
for tone in tone_list:
|
||||||
|
if tone == "c5":
|
||||||
|
s = s | Sine(frequency=c5, duration=dur)*0.5
|
||||||
|
elif tone == "b":
|
||||||
|
s = s | Sine(frequency=b, duration=dur)*0.5
|
||||||
|
elif tone == "a":
|
||||||
|
s = s | Sine(frequency=a, duration=dur)*0.5
|
||||||
|
elif tone == "g":
|
||||||
|
s = s | Sine(frequency=g, duration=dur)*0.5
|
||||||
|
elif tone == "f":
|
||||||
|
s = s | Sine(frequency=f, duration=dur)*0.5
|
||||||
|
elif tone == "e":
|
||||||
|
s = s | Sine(frequency=e, duration=dur)*0.5
|
||||||
|
elif tone == "d":
|
||||||
|
s = s | Sine(frequency=d, duration=dur)*0.5
|
||||||
|
elif tone == "c":
|
||||||
|
s = s | Sine(frequency=c, duration=dur)*0.5
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
s.play()
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Controller
|
||||||
|
|
||||||
|
class Controller():
|
||||||
|
def __init__(self):
|
||||||
|
self.m = Melody()
|
||||||
|
|
||||||
|
def ton(self):
|
||||||
|
m = self.m
|
||||||
|
m.play()
|
||||||
|
# View
|
||||||
|
|
||||||
|
class Application(tk.Frame):
|
||||||
|
def __init__(self, master=None):
|
||||||
|
super().__init__(master)
|
||||||
|
self.pack()
|
||||||
|
self.create_widgets()
|
||||||
|
|
||||||
|
def create_widgets(self):
|
||||||
|
self.b1 = tk.Button(self)
|
||||||
|
self.b1["text"] = "Ton"
|
||||||
|
self.b1["command"] = con.ton
|
||||||
|
self.b1.pack(side="top")
|
||||||
|
|
||||||
|
self.quit = tk.Button(self, text="QUIT", fg="red",
|
||||||
|
command=root.destroy)
|
||||||
|
self.quit.pack(side="bottom")
|
||||||
|
|
||||||
|
|
||||||
|
# --- Ausführung ---
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
con = Controller()
|
||||||
|
app = Application(master=root)
|
||||||
|
app.mainloop()
|
Loading…
Reference in New Issue
Block a user