adds multiple voices and the ability to iterate/deiterate between them
This commit is contained in:
		
							parent
							
								
									a8fd65d86f
								
							
						
					
					
						commit
						9828aba2a1
					
				
					 3 changed files with 53 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1,23 +1,35 @@
 | 
			
		|||
#include "voices.h"
 | 
			
		||||
 | 
			
		||||
// these are imported from audio.c
 | 
			
		||||
extern uint16_t envelope_index;
 | 
			
		||||
extern float note_timbre;
 | 
			
		||||
extern float polyphony_rate;
 | 
			
		||||
 | 
			
		||||
voice_type voice = default_voice;
 | 
			
		||||
voice_type voice = duty_osc;
 | 
			
		||||
 | 
			
		||||
void set_voice(voice_type v) {
 | 
			
		||||
    voice = v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void voice_iterate() {
 | 
			
		||||
    voice = (voice + 1) % number_of_voices;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void voice_deiterate() {
 | 
			
		||||
    voice = (voice - 1) % number_of_voices;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float voice_envelope(float frequency) {
 | 
			
		||||
    // envelope_index ranges from 0 to 0xFFFF, which is preserved at 880.0 Hz
 | 
			
		||||
    uint16_t compensated_index = (uint16_t)((float)envelope_index * (880.0 / frequency));
 | 
			
		||||
 | 
			
		||||
    switch (voice) {
 | 
			
		||||
        case default_voice:
 | 
			
		||||
            // nothing here on purpose
 | 
			
		||||
            note_timbre = TIMBRE_50;
 | 
			
		||||
            polyphony_rate = 0;
 | 
			
		||||
        break;
 | 
			
		||||
        case butts_fader:
 | 
			
		||||
            polyphony_rate = 0;
 | 
			
		||||
            switch (compensated_index) {
 | 
			
		||||
                case 0 ... 9:
 | 
			
		||||
                    frequency = frequency / 4;
 | 
			
		||||
| 
						 | 
				
			
			@ -36,6 +48,7 @@ float voice_envelope(float frequency) {
 | 
			
		|||
            }
 | 
			
		||||
        break;
 | 
			
		||||
        case octave_crunch:
 | 
			
		||||
            polyphony_rate = 0;
 | 
			
		||||
            switch (compensated_index) {
 | 
			
		||||
                case 0 ... 9:
 | 
			
		||||
                case 20 ... 24:
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +67,20 @@ float voice_envelope(float frequency) {
 | 
			
		|||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        break;
 | 
			
		||||
        case duty_osc:
 | 
			
		||||
            // This slows the loop down a substantial amount, so higher notes may freeze
 | 
			
		||||
            polyphony_rate = 0;
 | 
			
		||||
            switch (compensated_index) {
 | 
			
		||||
                default:
 | 
			
		||||
                    #define SPEED 10
 | 
			
		||||
                    #define AMP   .75
 | 
			
		||||
                    // sine wave is slow
 | 
			
		||||
                    // note_timbre = (sin((float)compensated_index/10000*SPEED) * AMP / 2) + .5;
 | 
			
		||||
                    // triangle wave is a bit faster
 | 
			
		||||
                    note_timbre = (float)abs((compensated_index*SPEED % 3000) - 1500) * ( AMP / 1500 ) + (1 - AMP) / 2;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return frequency;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue