Initial commit
This commit is contained in:
commit
778fe31c38
35 changed files with 1849 additions and 0 deletions
70
level5.py
Normal file
70
level5.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
"""
|
||||
Niveau 5
|
||||
Nouveaux instruments
|
||||
"""
|
||||
|
||||
import synthlib, math, sys
|
||||
|
||||
rate = 44100
|
||||
|
||||
def sine(t, f):
|
||||
return math.sin(t/rate*f*2*math.pi)
|
||||
|
||||
def cosine(t, f):
|
||||
return math.cosin(t/rate*f*2*math.pi)
|
||||
|
||||
def sine2(t, f):
|
||||
return math.atan(math.sin(t/rate*f*2*math.pi))
|
||||
|
||||
def sine3(t, f):
|
||||
return (sine(t,f) - sine2(t,f))*math.pi
|
||||
|
||||
def sine4(t, f):
|
||||
return (cosine(t,f) - sine3(t,f))*2
|
||||
|
||||
polynome = [32, 30, 8, 4, 2, 1]
|
||||
lpolynome = len(polynome)
|
||||
spolynome = sum(polynome)
|
||||
def polynomial(t, f):
|
||||
return sum(j*math.sin(t/rate*f*2*math.pi*i) for i,j in enumerate(polynome)) / spolynome
|
||||
|
||||
music = synthlib.midi()
|
||||
|
||||
active = {}
|
||||
wait = 0
|
||||
tt = 0
|
||||
t = 0
|
||||
loop = True
|
||||
|
||||
sound_encoder = synthlib.SoundEncoder(env={
|
||||
"sampling": rate,
|
||||
"signed": True,
|
||||
"verbose": False,
|
||||
"bits": 32,
|
||||
"msbfirst": True,
|
||||
"tempo": 130
|
||||
})
|
||||
while loop:
|
||||
if wait == 0:
|
||||
while True:
|
||||
event = music[tt]
|
||||
tt += 1
|
||||
if event.type == synthlib.Note:
|
||||
if event.velocity == 0:
|
||||
if event.number in active:
|
||||
active.pop(event.number)
|
||||
else:
|
||||
active[event.number] = event.velocity
|
||||
#sys.stderr.write(str(event.velocity)+"\n")
|
||||
elif event.type == synthlib.Wait:
|
||||
wait = int(event.value*rate/2)
|
||||
break
|
||||
elif event.type == synthlib.End:
|
||||
loop = False
|
||||
break
|
||||
else:
|
||||
wait -= 1
|
||||
|
||||
sound_encoder.write_sample(sum([active[number]*polynomial(t, 440*2**(number/12)) for number in active])/max(1,len(active)))
|
||||
t += 1
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue