示例#1
0
  void processAudio(AudioBuffer &buffer) {
    FloatArray left = buffer.getSamples(LEFT_CHANNEL);
    FloatArray right = buffer.getSamples(RIGHT_CHANNEL);
    for(int i = 0; i<buffer.getSize(); i++){
      if(abs(last-target) < 0.001){
	last = target;
	target = noise->getNextSample()*range;
      }
      left[i] = last;
      last += getIncrement();
      right[i] = hz.voltsToSample(quantize(hz.sampleToVolts(right[i])));
    }
  }
  float getNextSample(){
    float vca1 = sine->getNextSample();
    vca1 += chirp->getNextSample();
    vca1 *= env1->getNextSample();

    float vca2 = 0.0f;
    vca2 += impulse->getNextSample();
    // vca2 += filter->process(noise->getNextSample());
    // vca2 *= env2->getNextSample();
    vca2 += noise->getNextSample();
    vca2 = filter->process(vca2);
    vca2 *= env2->getNextSample();
    
    float sample = vca1*(1.0-balance) + vca2*balance;
    return sample;
  }
示例#3
0
//This function shows a part of how the modules work internally, based on a sample-by-sample model.
void modularSynthInternals(void) {
	//Here we create an Oscillator
	Oscillator osc;
	osc.frequency = 1; //We'll set the frequency to 1 Hz
	osc.setGeneratorFunction(Oscillator::sine); //Set the waveform to a sine wave.

	//We are going to manually tell the oscillator that the sample rate is 40 samples per second
	ModuleControlData_t controlData;
	controlData.sampleRate = 40;
	osc.setData(controlData);

	//If the frequency is 1 Hz (1 cycle per second) and there are 40 samples per second, if we take 40 samples,
	//we should expect to see a whole sine wave (0 to 1 to 0 to -1 and back to 0). So, we call getNextSample()
	//40 times to advance 40 samples through the process of generating the waveform and print the result.
	for (int i = 0; i < 40; i++) {
		cout << osc.getNextSample() << endl;
	}
}