void processBlock (AudioSampleBuffer& buffer, MidiBuffer&) override { AudioSampleBuffer mainInputOutput = getBusBuffer(buffer, true, 0); AudioSampleBuffer sideChainInput = getBusBuffer(buffer, true, 1); float alphaCopy = *alpha; float thresholdCopy = *threshold; for (int j = 0; j < buffer.getNumSamples(); ++j) { float mixedSamples = 0.0f; for (int i = 0; i < sideChainInput.getNumChannels(); ++i) mixedSamples += sideChainInput.getReadPointer (i) [j]; mixedSamples /= static_cast<float> (sideChainInput.getNumChannels()); lowPassCoeff = (alphaCopy * lowPassCoeff) + ((1.0f - alphaCopy) * mixedSamples); if (lowPassCoeff >= thresholdCopy) sampleCountDown = (int) getSampleRate(); // very in-effective way of doing this for (int i = 0; i < mainInputOutput.getNumChannels(); ++i) *mainInputOutput.getWritePointer (i, j) = sampleCountDown > 0 ? *mainInputOutput.getReadPointer (i, j) : 0.0f; if (sampleCountDown > 0) --sampleCountDown; } }
void PolyWavegeneratorProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiBuffer) { // clear all the midibuffers of the voices because they still contain the events from the last process Block for(int index = 0; index < voices.size(); index++) { voices[index]->clearMidiBuffer(); } // Midi and Voice Handler this is not correct yet i need to watch out for different note ons of the same note in one buffer and other stuff if(takesMidi && !midiBuffer.isEmpty()) { MidiMessage& message1 = *new MidiMessage(); ScopedPointer<MidiBuffer::Iterator> iterator = new MidiBuffer::Iterator(midiBuffer); int sampleInBuffer = 0; while(iterator->getNextEvent(message1, sampleInBuffer)) { if(message1.isNoteOn()) { // always take the first one and move it to the back => the oldest voice will be "overwritten" voices[0]->setIsOn(true); voices[0]->setMidiNote(message1.getNoteNumber()); voices[0]->addMidiEvent(message1, sampleInBuffer); voices.move(0, voices.size()-1); } else if(message1.isNoteOff()) { for(int index = 0; index < voices.size(); index++) { if(voices[index]->getMidiNote() == message1.getNoteNumber()) { ScopedPointer<Voice> tempVoice = voices[index]; tempVoice->setIsOn(false); tempVoice->addMidiEvent(message1, sampleInBuffer); tempVoice->setMidiNote(-1); // this should be removed but just in case for now break; } } } } } // Audio Handling of the voices AudioBuffer<float> outBuffer = getBusBuffer(buffer, false, 0); int numActive = 0; // eventually this could be a member variable for(int index = 0; index < voices.size(); index++) { if(voices[index]->getIsOn()) { numActive++; voices[index]->clearAudioBuffer(); voices[index]->fillBufferEnvelope(); voices[index]->fillBufferAudio(); outBuffer.addFrom(0, 0, voices[index]->getOutBuffer(), 0, 0, outBuffer.getNumSamples()); } } outBuffer.applyGain(1.0f/numActive); }