void ZenAutoTrimAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
	if (isEnabled())
	{
		aPlayHead = getPlayHead();
		AudioPlayHead::CurrentPositionInfo posInfo;
		aPlayHead->getCurrentPosition(posInfo);
		
		//float* leftData = buffer.getWritePointer(0); //leftData references left channel now
		//float* rightData = buffer.getWritePointer(1); //right data references right channel now
		//unsigned int numSamples = buffer.getNumSamples();

		if (prevSampleRate != this->getSampleRate())
		{
			prevSampleRate = this->getSampleRate();
			levelAnalysisManager.sampleRateChanged(prevSampleRate);
		}

		//don't process if all samples are 0 or if autogain button is off
		if (buffer.getMagnitude(0, buffer.getNumSamples()) > 0.0f && autoGainEnableParam->isOn())
			levelAnalysisManager.processSamples(&buffer, posInfo);

		
			// Calibrate gain param based on which value is target
			double peakToHit;
			int targetType = targetTypeParam->getValueAsInt();
			if (targetType == Peak)
			{
				peakToHit = levelAnalysisManager.getMaxChannelPeak();
			}
			else if (targetType == MaxRMS)
			{
				peakToHit = levelAnalysisManager.getMaxChannelRMS();
			}
			else if (targetType == AverageRMS)
			{
				peakToHit = levelAnalysisManager.getMaxCurrentRunningRMS();
			}
			else
			{
				peakToHit = levelAnalysisManager.getMaxChannelPeak();
				jassertfalse;
			}

			//double targParamGain = params->getDecibelParameter(targetGainParamID)->getValueInGain();
			

			//division in log equiv to subtract in base
			double gainValueToAdd = targetGainParam->getValueInGain() / peakToHit;

			if (!almostEqual(gainValueToAdd, gainParam->getValueInGain())) // gain value changed
			{
				gainParam->setValueFromGain(gainValueToAdd);
				//gainParam->setNeedsUIUpdate(true); // removed because done in setValueFromGain
			}

			//in gain, multiply in log equivalent to add in base
			buffer.applyGain(gainParam->getValueInGain());		
	}
}
Example #2
0
void IAAEffectProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
{
    const float gain = *parameters.getRawParameterValue ("gain");

    const int totalNumInputChannels  = getTotalNumInputChannels();
    const int totalNumOutputChannels = getTotalNumOutputChannels();

    const int numSamples = buffer.getNumSamples();

    for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
        buffer.clear (i, 0, buffer.getNumSamples());

    // Apply the gain to the samples using a ramp to avoid discontinuities in
    // the audio between processed buffers.
    for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        buffer.applyGainRamp (channel, 0, numSamples, previousGain, gain);

        meterListeners.call (&IAAEffectProcessor::MeterListener::handleNewMeterValue,
                             channel,
                             buffer.getMagnitude (channel, 0, numSamples));
    }

    previousGain = gain;

    // Now ask the host for the current time so we can store it to be displayed later.
    updateCurrentTimeInfoFromHost (lastPosInfo);
}
Example #3
0
void RouteEffect::renderWholeBuffer(AudioSampleBuffer &b)
{
	

	const int numSamples = b.getNumSamples();

	if (getMatrix().isEditorShown())
	{
		float gainValues[NUM_MAX_CHANNELS];

		jassert(getMatrix().getNumSourceChannels() == b.getNumChannels());

		for (int i = 0; i < b.getNumChannels(); i++)
		{
			gainValues[i] = b.getMagnitude(i, 0, b.getNumSamples());
		}

		getMatrix().setGainValues(gainValues, true);
	}

	for (int i = 0; i < b.getNumChannels(); i++)
	{
		const int j = getMatrix().getSendForSourceChannel(i);

		if (j != -1)
		{
			FloatVectorOperations::add(b.getWritePointer(j), b.getReadPointer(i), numSamples);
		}
	}

	if (getMatrix().isEditorShown())
	{
		float gainValues[NUM_MAX_CHANNELS];

		jassert(getMatrix().getNumDestinationChannels() == b.getNumChannels());

		for (int i = 0; i < b.getNumChannels(); i++)
		{
			gainValues[i] = b.getMagnitude(i, 0, b.getNumSamples());
		}

		getMatrix().setGainValues(gainValues, false);
	}
	

}
Example #4
0
void GateTrigger::processBlock (AudioSampleBuffer& buffer, 
                                MidiBuffer& midiMessages)
{
    float threshold = library->getThreshold();
    int64 releaseTicks = library->getReleaseTicks();
    float velocityScale = library->getVelocityScale();
    
    int windowSize = buffer.getNumSamples();
    for (int i = 0; i < buffer.getNumSamples(); i += windowSize) {
        float rms = 0;
        for (int chan = 0; chan < buffer.getNumChannels(); chan++) {
            rms += buffer.getMagnitude (chan, i, jmin(windowSize, buffer.getNumSamples() - i)); 
        }
        rms = rms / buffer.getNumChannels() * 100;
        if (rms - lastRms > threshold) {
            if (Time::getHighResolutionTicks() - lastTriggerTick > releaseTicks) {
                Pattern* pattern = sequencer->getPattern();
                Instrument* instrument = pattern->getActiveInstrument();
                // play note
                float velocity = (rms - lastRms) / velocityScale;
                DBG("RMS: " + String(rms) + " lastRMS: " + String(lastRms) + " velocity: " + String(velocity));
                int noteNumber = instrument->getNoteNumber();
                MidiMessage m = MidiMessage::noteOn (1, noteNumber, velocity);
                midiMessages.addEvent (m, i);
                // insert into sequencer pattern
                int step = round(sequencer->getPreciseStep());
                step = step % pattern->getNumSteps();
                Cell* cell = pattern->getCellAt (0, step);
                delayedInserterThread->insertNote (cell, velocity, instrument);
                // Retrigger the reset timer
                resetTimer->retrigger();
                lastTriggerTick = Time::getHighResolutionTicks();
            }
        }
        lastRms = rms;
    }   
}