soundbox/generate.py

57 lines
1.3 KiB
Python
Raw Normal View History

2020-12-17 22:08:07 +00:00
import soundbox
import sys
if len(sys.argv) != 2:
print(f"""Utilisation: {sys.argv[0]} [output]
Génère un morceau au synthétiseur dans le fichier [output].""")
sys.exit(1)
output_file = sys.argv[1]
2020-12-17 22:08:07 +00:00
def sine(dur, freq, value=1):
return soundbox.envelope(
attack=.01, decay=.2, release=.2,
signal=soundbox.sine(dur, freq, value))
signal = soundbox.silence(10)
2020-12-17 22:08:07 +00:00
chords_l = (
(('do', 2),),
(('sol', 2),),
(('la', 2),),
(('sol', 2),),
(('do', 2),),
(('sol', 2),),
(('la', 2),),
(('sol', 2),),
)
chords_r = (
(('do', 3), ('mi', 3), ('sol', 3)),
(('sol', 3), ('si', 3), ('re', 4)),
(('la', 3), ('do', 4), ('mi', 4)),
(('fa', 3), ('la', 3), ('do', 4)),
)
for shift in (.5, 4.5):
for i in range(len(chords_l)):
soundbox.add_signal(signal, start=i / 2 + shift,
source=soundbox.chord(
instr=sine, dur=.8 if shift == 4.5 and i == 7 else .4,
2020-12-17 22:08:07 +00:00
freqs=soundbox.note_freqs(chords_l[i]),
value=.4
2020-12-17 22:08:07 +00:00
))
for i in range(len(chords_r)):
soundbox.add_signal(signal, start=i + shift,
source=soundbox.chord(
instr=sine, dur=1.1,
freqs=soundbox.note_freqs(chords_r[i]),
value=.4
2020-12-17 22:08:07 +00:00
))
soundbox.save_signal(output_file, signal)