Last active
December 26, 2015 09:19
-
-
Save zeffii/7128826 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
// author: anonymou5 | |
// date: tomorrow | |
// oscillators: Sin, Tri, and Square. | |
SinOsc s => dac; | |
TriOsc t => dac; | |
SqrOsc sq => dac; | |
/* set each .gain to some low value to avoid saturation. | |
ie if their combined output exceeds 1.0 there will be digital | |
clipping */ | |
0.1 => s.gain; | |
0.1 => t.gain; | |
0.1 => sq.gain; | |
class Note{ | |
int n; | |
float hz; | |
fun int to_note(string str, int oct){ | |
// check if within supported range | |
if (str == "off") return -1; | |
if (oct < 0 || oct > 10) return -1; | |
string notes_list[]; | |
["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] @=> notes_list; | |
// note must be in this list, else return -1 at the end | |
for (0 => int i; i < notes_list.cap(); i++){ | |
if (str == notes_list[i]){ | |
return (i + oct * 12); | |
} | |
} | |
return -1; | |
} | |
fun float int_to_freq(int m){ | |
return 440.0 * Math.pow(2, ((m-69.0)/12.0)); | |
} | |
fun float make(string s, int oct) { | |
to_note(s, oct) => n; | |
int_to_freq(n) => hz; | |
return hz; | |
} | |
} | |
Note n; | |
// define and fill an N dimensional array for | |
// pitch, note length (in ticks), and note volume | |
float arr[][]; | |
[ | |
[n.make("E", 5), 4.0, 0.1], | |
[n.make("G", 5), 3.0, 0.1], | |
[n.make("E", 5), 2.0, 0.1], | |
[n.make("E", 5), 1.0, 0.08], | |
[n.make("A", 5), 2.0, 0.1], | |
[n.make("E", 5), 2.0, 0.1], | |
[n.make("D", 5), 2.0, 0.1], | |
[n.make("E", 5), 4.0, 0.1], | |
[n.make("B", 5), 3.0, 0.1], | |
[n.make("E", 5), 2.0, 0.1], | |
[n.make("E", 5), 1.0, 0.1], | |
[n.make("C", 6), 2.0, 0.1], | |
[n.make("B", 5), 2.0, 0.1], | |
[n.make("G", 5), 2.0, 0.1], | |
[n.make("E", 5), 2.0, 0.1], | |
[n.make("B", 5), 2.0, 0.1], | |
[n.make("E", 6), 2.0, 0.1], | |
[n.make("E", 5), 1.0, 0.1], | |
[n.make("D", 5), 2.0, 0.1], | |
[n.make("D", 5), 1.0, 0.1], | |
[n.make("B", 4), 2.0, 0.1], | |
[n.make("F#", 5), 2.0, 0.1], | |
[n.make("E", 5), 18.0, 0.1] | |
] @=> arr; | |
// each tick will last 0.12 second | |
0.12 => float tick; | |
// iterate through the N dimensional array, until cap() | |
// cap seems to represent len() or .length. | |
for (0 => int i; i < arr.cap(); i++){ | |
// assign nested array members to local variables | |
arr[i][0]/3 => float pitch; | |
arr[i][1] * tick => float note_length; | |
arr[i][2] => float volume; | |
// use incoming pitch, modified for the three osc | |
pitch => s.freq; | |
pitch => t.freq; | |
pitch => sq.freq; | |
// use same volume for all osc | |
volume/5.2 => s.gain; | |
volume/2 => t.gain; | |
volume/2 => sq.gain; | |
note_length::second => now; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment