""" Niveau 6 Filtre audio """ import synth import math import random music = synth.Midi(32000) encoder = synth.Encoder() encoder.sampling = 32000 instruments = [ lambda t, f: round(math.sin(t * f * 2*math.pi)) + random.random() * 0.3, lambda t, f: math.sin(t * f * 2*math.pi), lambda t, f: math.sin(t * f * 2*math.pi)*0.6 + math.sin(t * f * 4*math.pi)*0.3 + math.sin(t * f * 8*math.pi)*0.1, 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, ] delay1 = [0] * 1000 delay2 = [0] * 3000 delay3 = [0] * 5000 phaser = [0] * 50 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] total = total * (math.sin(t/32000 * 20 * 2*math.pi)/8+7/8) total += delay1.pop(0) * 0.1 total += delay2.pop(0) * 0.3 total += delay3.pop(0) * 0.4 delay1.append(total) delay2.append(total) delay3.append(total) lfo = math.sin(t/32000 * 0.2 * 2*math.pi) phaser.append(total) phaser.pop(0) total += phaser[int((lfo/2+0.5)*(len(phaser)-1))] encoder.write(total * 0.1) t = t + 1