Example #1
0
void Synthesis::ProcessDoubleReplacing(
    double** inputs,
    double** outputs,
    int nFrames)
{
    // Mutex is already locked for us.

    double *leftOutput = outputs[0];
    double *rightOutput = outputs[1];

	processVirtualKeyboard();
    
	for (int i = 0; i < nFrames; ++i) {
        mMIDIReceiver.advance();
        int velocity = mMIDIReceiver.getLastVelocity();
        if (velocity > 0) {
            mOscillator.setFrequency(mMIDIReceiver.getLastFrequency());
            mOscillator.setMuted(false);
        } else {
            mOscillator.setMuted(true);
        }
        leftOutput[i] = rightOutput[i] = mOscillator.nextSample() * velocity / 127.0;
    }

    mMIDIReceiver.flush(nFrames);
}
Example #2
0
void Vega::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  // Mutex is already locked for us.

  double *leftOutput = outputs[0];
  double *rightOutput = outputs[1];

  processVirtualKeyboard();
  
  // Copy left buffer into right buffer:
  for (int i = 0; i < nFrames; ++i) {
    mMIDIReceiver.advance();
    leftOutput[i] = rightOutput[i] = mVoiceEngine.nextSample();
  }
  mMIDIReceiver.Flush(nFrames);
}
Example #3
0
void Synthesis::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
  // Mutex is already locked for us.
  
  double *leftOutput = outputs[0];
  double *rightOutput = outputs[1];
  VoiceManager& voiceManager = VoiceManager::getInstance();
  processVirtualKeyboard();
  
  
  
  
  //std::cout << "\nBlock size = " << GetBlockSize();

  
//  blockOfSamples = voiceManager.getBlockOfSamples();
//  for (int i = 0; i < BLOCK_SIZE; i++) {
//    leftOutput[i] = blockOfSamples[i*NUM_CHANNELS];
//    rightOutput[i] = blockOfSamples[i*NUM_CHANNELS + 1];
////    if (i < 512) {
////      printf("\ni = %d, left = %f, right = %f", i, leftOutput[i], rightOutput[i]);
////    }
//    //printf("\nleftOutput index = %d, rightOutput index = %d", i*NUM_CHANNELS, i*NUM_CHANNELS+1);
//    mOscilloscope->updateLastSample(leftOutput[i], rightOutput[i]);
//    mMIDIReceiver.advance();
//  }
  
  //std::thread voiceEnergyUpdater(&Synthesis::voiceEnergyUpdaterManager, this);
  
  
  /// this allows for BLOCK_SIZE to be different (smaller) than actual VST host blockSize, to reduce latency
  int numBlocks = nFrames/BLOCK_SIZE;
  
  
  for (int j = 0; j < numBlocks; j++) {
    
    blockOfSamples = voiceManager.getBlockOfSamples();
    for (int i = 0; i < BLOCK_SIZE; i++) {
      
      leftOutput[i + j*BLOCK_SIZE] = clip(blockOfSamples[i*NUM_CHANNELS]);
      rightOutput[i + j*BLOCK_SIZE] = clip(blockOfSamples[i*NUM_CHANNELS + 1]);
      
      // add in bandlimited noise
//      leftOutput[i + j*BLOCK_SIZE] += 0.003f * (static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/2.0f)) - 1.0f) * blockOfSamples[i*NUM_CHANNELS];
//      rightOutput[i + j*BLOCK_SIZE] += 0.003f * (static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/2.0f)) - 1.0f) * blockOfSamples[i*NUM_CHANNELS + 1];
      
      
//      mOscilloscope->updateLastSample(leftOutput[i], rightOutput[i]);
      mMIDIReceiver.advance();
      voiceManager.updateVoiceDampingAndEnergy(i);
    }
    mMIDIReceiver.Flush(nFrames/numBlocks);
    voiceManager.setFreeInaudibleVoices();
  }
  
  
  
  
//  for (int i = 0; i < nFrames/BLOCK_SIZE; i++) {
//    blockOfSamples = voiceManager.getBlockOfSamples();
//    for (int j = 0; j < BLOCK_SIZE; j++) {
//      leftOutput[i*BLOCK_SIZE + j] = blockOfSamples[i*NUM_CHANNELS];
//      rightOutput[i*BLOCK_SIZE + j] = blockOfSamples[i*NUM_CHANNELS + 1];
//      mOscilloscope->updateLastSample(leftOutput[i], rightOutput[i]);
//      mMIDIReceiver.advance();
//    }
//  }
  
  //mMIDIReceiver.Flush(nFrames);
}