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] def sine(dur, freq, value=1): return soundbox.envelope( attack=.01, decay=.2, release=.2, signal=soundbox.sine(dur, freq, value)) def square(dur, freq, value=1): return soundbox.envelope( attack=.2, decay=.2, release=.2, signal=soundbox.square(dur, freq, value)) signal = soundbox.silence(9) 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=square, dur=.4, freqs=soundbox.note_freqs(chords_l[i]), value=.04 )) 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=.5 )) soundbox.save_signal(output_file, signal)