void onAudio(AudioIOData& io){ while(io()){ if(tmr()){ // Our sequence of pitches float pitches[] = {0,0,12,0,0,10,-5,0}; // Map pitch class to a frequency in Hz float f = 55 * pow(2, pitches[step]/12.); // Increment step counter step = (step + 1) % 8; // Set new target frequence of portamento freq = f; // Restart envelope using a soft reset (to avoid clicks) env.resetSoft(); } // Set saw frequency from portamento filter saw.freq(freq()); // Get next envelope value float e = env(); // Map envelope value to cutoff frequency lpf.freq(e * (modCutoff.paraU()*6000 + 500) + 40); // Generate next saw sample float s = saw() * 0.3; // Filter saw sample s = lpf(s) * e; // Send sample to DAC io.out(0) = io.out(1) = s; } }
int main() { tmr.period(3); // Reset the envelope every 3 seconds env.attack(0.01); // Attack time env.decay(0.05); // Decay time // Delays, lowpass, and allpass filters setup code goes here // lpf.type(LOW_PASS); lpf.freq(2600); lpf.res(sqrt(2.0)/2.0); AudioIO audioIO(frameCount, samplingRate, audioCallBack, NULL, channelsOut, channelsIn); Sync::master().spu(audioIO.framesPerSecond()); audioIO.start(); printf("Press 'enter' to quit...\n"); getchar(); return 0; }
void audioCB(AudioIOData& io){ while(io()){ if(tmr()){ switch(cnt){ case 0: filt.type(Filter::LP); printf("Low-pass\n"); break; case 1: filt.type(Filter::HP); printf("High-pass\n"); break; case 2: filt.type(Filter::BP); printf("Band-pass\n"); break; case 3: filt.type(Filter::BR); printf("Band-reject\n"); break; } ++cnt %= 4; } float cutoff = scl::pow3(mod.triU()) * 10000; filt.res(4); filt.freq(cutoff); float s = filt(src()); io.out(0) = io.out(1) = s * 0.1f; } }