Created
February 21, 2023 22:31
-
-
Save severak/85870c1464ae7222e5aa07beb9963be7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* You can use a this template to start a program */ | |
fun pitchToRate(d) return 8.1758*exp(0.0577623*d)/44100.0; | |
fun saw(rate:real) { | |
mem phase; | |
phase = (phase + rate) % 1.0; | |
return (phase*2.0)-1.0; | |
} | |
fun sqr(rate:real) { | |
mem phase; | |
phase = (phase + rate) % 1.0; | |
return if phase > 0.5 then -1.0 else 1.0; | |
} | |
// Main processing function | |
// 'input' is by default a sine wave at 440 Hz | |
fun process(input:real){ | |
mem rates; | |
mem volume; | |
val acc = 0.0; | |
//val n = 0; | |
//while (n < 2) { | |
// acc = acc + saw(rates[n]); | |
// n = n +1; | |
//} | |
acc = acc + saw(rates[0]); | |
acc = acc + saw(rates[1]); | |
acc = acc + saw(rates[2]); | |
return acc * volume; | |
} | |
// Called when a note On is received | |
and noteOn(note:int,velocity:int,channel:int){ | |
} | |
// Called when a note Off is received | |
and noteOff(note:int,channel:int){ | |
} | |
// Called when a control changes | |
and controlChange(control:int,value:int,channel:int){ | |
if (control==30) rates[0] = pitchToRate(( ( real(value) /127.0 ) * 100.0) + 21.0); | |
if (control==31) rates[1] = pitchToRate(( ( real(value) /127.0 ) * 100.0) + 21.0); | |
if (control==32) rates[2] = pitchToRate(( ( real(value) /127.0 ) * 100.0) + 21.0); | |
if (control==41) volume = (real(value) /127.0); | |
} | |
// Called on initialization to define initial values | |
and default(){ | |
volume = 0.01; | |
rates = [pitchToRate(45.0), pitchToRate(55.0), pitchToRate(59.0)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment