3 // these are imported from audio.c
4 extern uint16_t envelope_index;
5 extern float note_timbre;
6 extern float polyphony_rate;
8 voice_type voice = duty_osc;
10 void set_voice(voice_type v) {
14 void voice_iterate() {
15 voice = (voice + 1) % number_of_voices;
18 void voice_deiterate() {
19 voice = (voice - 1) % number_of_voices;
22 float voice_envelope(float frequency) {
23 // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
24 uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
28 note_timbre = TIMBRE_50;
33 switch (compensated_index) {
35 frequency = frequency / 4;
36 note_timbre = TIMBRE_12;
39 frequency = frequency / 2;
40 note_timbre = TIMBRE_12;
43 note_timbre = .125 - pow(((float)compensated_index - 20) / (200 - 20), 2)*.125;
52 switch (compensated_index) {
56 frequency = frequency / 2;
57 note_timbre = TIMBRE_12;
62 frequency = frequency * 2;
63 note_timbre = TIMBRE_12;
66 note_timbre = TIMBRE_12;
71 // This slows the loop down a substantial amount, so higher notes may freeze
73 switch (compensated_index) {
78 // note_timbre = (sin((float)compensated_index/10000*OCS_SPEED) * OCS_AMP / 2) + .5;
79 // triangle wave is a bit faster
80 note_timbre = (float)abs((compensated_index*OCS_SPEED % 3000) - 1500) * ( OCS_AMP / 1500 ) + (1 - OCS_AMP) / 2;
84 case duty_octave_down:
86 note_timbre = (envelope_index % 2) * .125 + .375 * 2;
87 if ((envelope_index % 4) == 0)
89 if ((envelope_index % 8) == 0)
94 if ((envelope_index % 5) == 0)
97 case duty_fourth_down:
98 if ((envelope_index % 12) == 0)