""" Niveau 5 Jouer une partition """ import synth import math music = synth.Midi(32000) encoder = synth.Encoder() encoder.sampling = 32000 instruments = [ lambda t, f: math.sin(t * f * 2*math.pi), lambda t, f: math.sin(t * f * 2*math.pi) + math.sin(t * f * 4*math.pi)/2, lambda t, f: math.sin(t * f * 2*math.pi) + math.sin(t * f * 4*math.pi)/2, lambda t, f: t * f % 1 - 0.5, ] t = 0 for notes in music: total = 0 for note in notes: total = total + instruments[note[0]](t/32000, 440 * 2**(note[1]/12)) * note[2] encoder.write(total * 0.3) t = t + 1