Пример #1
0
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()) burst.reset();
		
		//float s = io.in(0)[i];
		float s = burst()*2;
		
		// This short-hand method is convenient for simple delays.
		s += delay(s);
		
		// The delay-line can also be read from and written to using separate calls.
		//delay.write(s);
		//s += delay();
		
		// We can create infinite echoes by feeding back a small amount of the 
		// output back into the input on each iteration.
		//s = delay(s + delay()*0.2);
		
		// We can also create mult-tap delay-lines through multiple calls to 
		// the read() method.
		//s += delay(s) + delay.read(0.15) + delay.read(0.39);

		// How about multi-tap feedback?
		//s += delay(s + delay.read(0.197)*0.3 + delay.read(0.141)*0.4 + delay.read(0.093)*0.2)*0.5;
	
		io.out(0) = io.out(1) = s;
	}
}
Пример #2
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;
		}
	}
Пример #3
0
void audioCB(AudioIOData& io){
    
	while(io()){
        if(tmr()){
            //good way to get random numbers in gamma.  Uniform distribution between two numbers
            int tempHarmonic = rnd::uni(1,6);
 
            //set the center frequency by calling freq(freqYouWant)
            filter.freq(tempHarmonic*fundamentalFrequency);
            
            float tempWidth = (tempHarmonic*fundamentalFrequency)/rnd::uni(2,100);
            
            //set the filter's width (related to Q) by calling width(widthYouWant).
            filter.width(tempWidth);
            
            //print the filter's center frequency and width
            cout<< "frequency: " << (tempHarmonic*fundamentalFrequency) << endl << "width: " << tempWidth << endl;
        }          
        
        //this is how we filter our source.  
        float s = filter(src())*5.0;
        
		io.out(0) = io.out(1) = s; 
	}
}
Пример #4
0
	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;
		}
	}
Пример #5
0
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			switch(feedType){
			case 0:	printf("Low-pass feedforward\n");
				comb.feeds( 1,0); break;
			case 1:	printf("High-pass feedforward\n");
				comb.feeds(-1,0); break;
			case 2:	printf("Low-pass feedback\n");
				comb.feeds(0,0.7); break;
			case 3:	printf("High-pass feedback\n");
				comb.feeds(0,-0.7); break;
			case 4:	printf("Low-pass dual-feed\n");
				comb.feeds(0.7,0.7); break;
			case 5:	printf("High-pass dual-feed\n");
				comb.feeds(-0.7,-0.7); break;
			case 6:	printf("All-pass 1\n");
				comb.feeds(0.9,-0.9); break;
			case 7:	printf("All-pass 2\n");
				comb.feeds(-0.9,0.9); break;
			}
			(++feedType) %= 8;
		}
		
		float s = src()*0.4;
		
		comb.ipolType(ipl::ROUND);
		comb.delay(mod.triU() * 1./400 + 1./10000);
		s = comb(s);

		io.out(0) = io.out(1) = s;
	}
}
Пример #6
0
	// Audio callback
	virtual void onSound(AudioIOData& io){
	
		// Set the base frequency to 55 Hz
		double freq = 55/io.framesPerSecond();
	
		while(io()){
		
			// Update the oscillators' phase
			phase += freq;
			if(phase > 1) phase -= 1;

			// Generate two sine waves at the 5th and 4th harmonics
			float out1 = cos(5*phase * 2*M_PI);
			float out2 = sin(4*phase * 2*M_PI);

			// Write the waveforms to the ring buffer.
			// Note that this call CANNOT block or wait on a lock from somewhere else. The audio
			// thread must keep writing to the buffer without regard for what other threads
			// might be reading from it.
			ring.write(Vec2f(out1, out2));

			// Send scaled waveforms to output...
			io.out(0) = out1*0.2;
			io.out(1) = out2*0.2;
		}
	}
Пример #7
0
	void onAudio(AudioIOData& io){
		while(io()){
			float s = src()*4;

			if(stft(s)){
				// Set period of pluck envelopes, in seconds.
				// This is negative to get a downward ramp going from 1 to 0.
				pluckEnvs.period(-60);

				// Create a moving ramp function in the aux buffer
				float amp = pluckEnvs();
				for(unsigned k=0; k<stft.numBins(); ++k){
					float A = scl::wrap(amp + float(k)/stft.numBins());
					// This gives the envelopes an exponential-like decay
					for(int j=0; j<5; ++j) A*=A;
					stft.aux(0)[k] = A;
				}

				// Do a seeded random shuffle of the envelopes so we don't hear
				// a pattern.
				rnd::push(14122);
				rnd::permute(stft.aux(0), stft.numBins());
				rnd::pop();

				for(unsigned k=0; k<stft.numBins(); ++k){
					stft.bin(k) *= stft.aux(0)[k];
				}
			}

			io.out(0) = io.out(1) = stft();
		}
	}
Пример #8
0
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			switch(flangeType){
			case 0:	printf("Low-pass feedforward\n");
				flanger.feeds(0.7, 0); break;
			case 1:	printf("High-pass feedforward\n");
				flanger.feeds(-0.7,0); break;
			case 2:	printf("Low-pass feedback\n");
				flanger.feeds(0,0.7); break;
			case 3:	printf("High-pass feedback\n");
				flanger.feeds(0,-0.7); break;
			case 4:	printf("Low-pass dual-feed\n");
				flanger.feeds(0.7,0.7); break;
			case 5:	printf("High-pass dual-feed\n");
				flanger.feeds(-0.7,-0.7); break;
			case 6:	printf("All-pass 1\n");
				flanger.feeds(0.9,-0.9); break;
			case 7:	printf("All-pass 2\n");
				flanger.feeds(-0.9,0.9); break;
			}
			(++flangeType) %= 8;
		}
		
		float s = src.up();
		s = flanger(s)*0.1;

		io.out(0) = io.out(1) = s;
	}
}
Пример #9
0
    void onAudio(AudioIOData& io) {
        while(io()) {
            // Our signal is a saw wave plus a little noise
            float s = saw()*0.3 + noise()*0.04;

            if(stft(s)) {

                for(unsigned k=0; k<stft.numBins(); ++k) {

                    // Get the bin magnitude (the first bin element)
                    float mag = stft.bin(k)[0];

                    // If the bin magnitude is less than our threshold, then we
                    // zero its magnitude. The assumption here is that noisy bins
                    // will have a relatively small magnitude.
                    if(mag < 0.0004) stft.bin(k)[0] = 0;

                    // If we flip the comparison, then we keep only the noise.
                    //if(mag > 0.0001) stft.bin(k)[0] = 0;
                }
            }

            // Get next resynthesized sample
            // (Comment this out to hear the original signal with noise.)
            s = stft();

            io.out(0) =  io.out(1) = s;
        }
    }
Пример #10
0
	void onAudio(AudioIOData& io){
		while(io()){
			if(syncMode()){
				softSync^=true;
				printf("%s sync\n", softSync?"soft":"hard");
			}

			// When the sync osc completes cycle, reset the phase of the formant osc
			float w = sync.up();
			if(sync.cycled()) formant.phase(0);

			// Set the pitch of the formants
			formant.freq(mod.triU()*2200+200);

			// The formant oscillator determines the spectral envelope
			float s = formant.tri();

			// Drop amp to zero at sync points?
			if(softSync){
				w = 1.f - scl::pow8(w);	// flattop window
				s *= w;					// apply window
			}

			io.out(0) = io.out(1) = s*0.2;
		}
	}
Пример #11
0
	void onAudio(AudioIOData& io){
		while(io()){
			float s = (player1() + player2()) * 0.5;
			player1.loop();
			player2.loop();
			io.out(0) = io.out(1) = s;
		}
	}
Пример #12
0
	void onProcess(AudioIOData& io){
    while(io()){
      float2 s = float2(io.out(0), io.out(1));
      s = chorus(s)*0.5;
      io.out(0) += s[0];
      io.out(1) += s[1];
    }
  }
Пример #13
0
void audioCB(AudioIOData& io){

	while(io()){

		float s = (osc1() + osc2()) * 0.1;

		io.out(0) = io.out(1) = s;
	}
}
Пример #14
0
void audioCB(AudioIOData& io){

	while(io()){
	
		float s = sweep();		// upward ramp between 0 and 1
		s = table[int(s*N)];

		io.out(0) = io.out(1) = s*0.2;
	}
}
Пример #15
0
	static void audioCB(AudioIOData& io){
		MyApp * self = (MyApp *)io.user();
		while(io()){
			self->phase += 0.001;
			float s0 = rng.uniformS() * sin(self->phase);
			float s1 = sin(self->phase * 100.);
			io.out(0) = s0;
			io.out(1) = s1;
		}
	}
void audioCB(AudioIOData& io){

	while(io()){

		float s = osc();
		io.out(0) = io.out(1) = s * 0.2f;
		
		osc.phaseAdd(s*0.01*mod.hann());
		//osc.freq((s*0.5+0.5)*mod.hann()*800 + 400);
	}
}
Пример #17
0
void audioCB(AudioIOData& io){

	while(io()){

		oscM.freq(modFreq.hann() * 110 + 1);	// change modulator frequency

		float s = oscC() * (oscM() * 0.5 + 0.5) * 0.2;
		
		io.out(0) = io.out(1) = s;
	}
}
Пример #18
0
void audioCB(AudioIOData& io){

	while(io()){
	
		int nh = mod.triU() * 64;
		buzz.harmonics(nh);
	
		float s = buzz();

		io.out(0) = io.out(1) = s*0.2;
	}
}
void audioCB(AudioIOData& io){

	while(io()){

		oscM.freq(modFreq.hann() * 110 + 1);	// change modulator frequency
		oscC.freq(ff + oscM()*100);				// modulate frequency of carrier

		float s = oscC() * 0.2;
		
		io.out(0) = io.out(1) = s;
	}
}
Пример #20
0
void audioCB(AudioIOData& io){

	while(io()){
	
		if(tmr()){
			env.value(0.2);		// reset amplitude of envelope
		}

		float s = src() * env();

		io.out(0) = io.out(1) = s;
	}
}
Пример #21
0
void audioCB(AudioIOData& io){

	while(io()){
		
		float cutoff = scl::pow3(mod.triU()) * 10000;
		
		filt.freq(cutoff);
		
		float s = filt(src());
			
		io.out(0) = io.out(1) = s * 0.2f;
	}
}
Пример #22
0
void audioCB(AudioIOData& io){

	while(io()){
	
		float s = 0;
	
		if(tmr()){
			tmr.period(rnd::pick(0.4, 0.2));
			s = 0.2;
		}
		
		io.out(0) = io.out(1) = s;
	}
}
Пример #23
0
void audioCB(AudioIOData& io){

	while(io()){
	
		if(tmr()){
			env = fund*2 + rnd::uni(10.0);	// set new target value of envelope
		}
		
		osc2.freq(env());					// modulate frequency of 2nd harmonic
		float s = (osc1() + osc2()) * 0.1;

		io.out(0) = io.out(1) = s;
	}
}
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			freq = pow(2, rnd::uniS(1.))*440;
		}
		
		src.freq(freq());
		
		float s = src();
			
		io.out(0) = io.out(1) = s * 0.2f;
	}
}
// Our main audio callback
void audioCB(AudioIOData& io){

	UserData& user = *(UserData *)io.user();
	float ampL = user.ampL;
	float ampR = user.ampR;

	// loop through the number of samples in the block
	while(io()){

		float s = io.in(0);		// get the line-in or microphone sample

		io.out(0) = s * ampL;	// set left and right output channel samples
		io.out(1) = s * ampR;
	}
}
Пример #26
0
// create a callback for generating a block of samples
void audioCB(AudioIOData& io){

	UserData& user = *(UserData *)io.user();
	float ampL = user.ampL;
	float ampR = user.ampR;

	// loop through the number of samples in the block
	for(int i=0; i<io.framesPerBuffer(); ++i){
		
		float s = io.in(0,i);		// get the line-in or microphone sample
		
		io.out(0,i) = s * ampL;	// set left and right output channel samples
		io.out(1,i) = s * ampR;
	}
}
Пример #27
0
void audioCB(AudioIOData& io){
	while(io()){
		float s = osc() * 0.2;
		io.out(0) = s;
		io.out(1) = s;
	}
}
Пример #28
0
void audioCB(AudioIOData& io){

	while(io()){

		float s = src();

		// Input next sample for analysis
		// When this returns true, then we have a new spectral frame
		if(stft(s)){
		
			float frac = scl::pow3( edge.triU() );
			int N = stft.numBins();
			
			for(int k=0; k<N; ++k){
				int indKnee = frac * N;
				stft.bin(k) *= k < indKnee ? 1:0;
			}
		}
		
		// Get next resynthesized sample
		s = stft() * 0.2;
		
		io.out(0) = s;
		io.out(1) = s;
	}
}
Пример #29
0
	void onAudio(AudioIOData& io){
		while(io()){

			float s = src();

			if(stft(s)){
		
				// Define the band edges, in Hz
				float freqLo =  400;
				float freqHi = 1800;

				for(unsigned k=0; k<stft.numBins(); ++k){
				
					// Compute the frequency, in Hz, of this bin
					float freq = k*stft.binFreq();

					// If the bin frequency is outside of our band, then zero
					// the bin.
					if(freq < freqLo || freq > freqHi){
						stft.bin(k) = 0;
					}
				}
			}

			s = stft();
		
			io.out(0) = s;
			io.out(1) = s;
		}
	}
Пример #30
0
void audioCB(AudioIOData& io){

	while(io()){
		
		if(tmr()){
			if(rnd::prob(0.1/1)) pluck1.reset();
			if(rnd::prob(0.1/2)) pluck2.reset();
			if(rnd::prob(0.1/3)) pluck3.reset();
			if(rnd::prob(0.1/4)) pluck4.reset();
		}
		
		float s = pluck1() + pluck2() + pluck3() + pluck4();
			
		io.out(0) = io.out(1) = s * 0.2f;
	}
}