Esempio n. 1
0
	void onAudio(AudioIOData& io){

		while(io()){

			// Increment waveform type
			if(tmr()) (++waveform)%=13;

			// Modulate modifier parameter with raised cosine
			osc.mod(mod.cosU());
		
			float s = 0.f;
			
			switch(waveform){ 
					
				// non-modifiable generators ordered from dull to bright:
				case  0: s = osc.cos();		break;		// Cosine approximation: one harmonic
				case  1: s = osc.even3();	break;		// Even harmonic sine-like wave (3rd order)
				case  2: s = osc.even5();	break;		// Even harmonic sine-like wave (5th order)
				case  3: s = osc.tri();		break;		// Triangle wave: 1/f^2 odd harmonics
				case  4: s = osc.para();	break;		// Parabola train: 1/f^2 all harmonics
				case  5: s = osc.sqr()/4;	break;		// Square wave: 1/f odd harmonics
				case  6: s = osc.down()/4;	break;		// Downward saw wave: 1/f all harmonics
				case  7: s = osc.up()/4;	break;		// Upward saw wave: 1/f all harmonics
				case  8: s = osc.imp()/4;	break;		// Impulse train: flat spectrum all harmonics
				
				// modifiable generators ordered from dull to bright:
				case  9: s = osc.stair()/4;	break;		// Mix between a square and impulse
				case 10: s = osc.pulse()/4;	break;		// Mix between up and down
				case 11: s = osc.line2()/4;	break;		// Mix between a saw and a triangle
				case 12: s = osc.up2()/4;	break;		// Mix between two saws
			}
			
			io.out(0) = io.out(1) = s * 0.2f;
		}
	}
void audioCB(AudioIOData& io){

	while(io()){
	
		if(tmr()){
			if(cnt()){
				modMode ^= true;			// increment LFO type, switch mod mode when wraps
				printf("\nMod mode: %s modulation\n", modMode? "Amp" : "Freq");
			}
		}
			
		env.mod(mod.cosU());	// modulate modifier parameter with unipolar cosine wave

		float s = 0.f;			// initialize current sample to zero

		switch(cnt.val){			
				
			// non-modifiable generators ordered from smooth to sharp:
			case  0: s = env.cosU();	break;	// unipolar cosine
			case  1: s = env.hann();	break;	// a computed hann window (inverted cosU)
			case  2: s = env.triU();	break;	// unipolar triangle
			case  3: s = env.upU();		break;  // unipolar upward ramp
			case  4: s = env.downU();	break;  // unipolar downward ramp
			case  5: s = env.sqrU();	break;	// unipolar square

			// modifiable generator ordered from smooth to sharp:
			case  6: s = env.pulseU();	break;	// Mix between upward ramp and downward ramp
			case  7: s = env.stairU();	break;	// Mix between a square and impulse. 
			case  8: s = env.line2U();	break;	// Mix between a ramp and a triangle
			case  9: s = env.up2U();	break;  // Mix between two ramps			
		}
		
		if(modMode){			// amplitude modulate noise with envelope
			s *= noise();
		}
		else{					   // frequency modulate oscillator with envelope
			osc.freq(s*400 + 200); // between 100 and 200 hz
			s = osc.cos();
		}
		
		io.out(0) = io.out(1) = s*0.2;
	}
}