-
Notifications
You must be signed in to change notification settings - Fork 0
/
synth.jl
69 lines (50 loc) · 1.11 KB
/
synth.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# using Interpolations
Fs=44100.0
fqA4=440.0
type Phase
phi::Float64 # dérivée de fréquence instantanée en Hz
end
function freqToNote(f::Float64)
return log(f/fqA4)*12/log(2)
end
function noteToFreq(x::Float64)
return fqA4*exp(x*log(2)/12)
end
function incrementPhaseByFreq!(phase::Phase,freq::Float64)
phase.phi = rem( phase.phi + freq/Fs , 1.0 )
end
#=
function incrementPhaseByNote(phase::Phase,note::Float64)
phase.phi = rem( phase.phi + noteToFreq(note)/Fs , 1.0 )
end
=#
function saw(phase::Phase)
return 2*(phase.phi-0.5)
end
function sine(phase::Phase)
return sin(2*pi*phase.phi)
end
function square(phase::Phase)
if phase.phi<0.5
return 1
else
return -1
end
end
function triangle(phase::Phase)
if phase.phi<0.5
return -4*phase.phi + 1
else
return 4*(phase.phi-0.5)-1
end
end
#=
function linearInterpolation(x,y,t)
# wrapper
# interpolates the (x[i],y[i]) and produces a piecewise linear function such as f(x[i])=y[i]
end
=#
#=
function getSampleFromPeriodicBuffer(buf::Array{Float64,1},phase::Float64)
end
=#