soundbox/generate.py

65 lines
1.6 KiB
Python
Raw Normal View History

2020-12-19 20:04:56 +00:00
import numpy as np
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
2020-12-19 20:04:56 +00:00
def sharp_sine(dur, freq, value=1):
2020-12-17 22:08:07 +00:00
return soundbox.envelope(
2020-12-19 20:04:56 +00:00
attack=.005, decay=.1, release=.1,
signal=soundbox.sine(dur + .2, freq, value))
2020-12-17 22:08:07 +00:00
2020-12-19 20:04:56 +00:00
def smooth_sine(dur, freq, value=1):
return soundbox.envelope(
attack=.1, decay=.2, release=.1,
signal=soundbox.sine(dur + .2, freq, value))
length = 9
signal = soundbox.silence(length)
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)),
)
2020-12-19 20:04:56 +00:00
for shift in np.arange(.5, length - 4, 4):
2020-12-17 22:08:07 +00:00
for i in range(len(chords_l)):
soundbox.add_signal(signal, start=i / 2 + shift,
source=soundbox.chord(
2020-12-19 20:04:56 +00:00
instr=smooth_sine, dur=.6 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(
2020-12-19 20:04:56 +00:00
instr=sharp_sine, dur=0.9,
2020-12-17 22:08:07 +00:00
freqs=soundbox.note_freqs(chords_r[i]),
value=.4
2020-12-17 22:08:07 +00:00
))
soundbox.save_signal(output_file, signal)