Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ChorusFlangerAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
- {
- ScopedNoDenormals noDenormals;
- auto totalNumInputChannels = getTotalNumInputChannels();
- auto totalNumOutputChannels = getTotalNumOutputChannels();
- // Clear any garbage data
- for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
- buffer.clear (i, 0, buffer.getNumSamples());
- // Obtain left and right audio data pointers
- float* leftChannel = buffer.getWritePointer(0);
- float* rightChannel = buffer.getWritePointer(1);
- // Iterate through all samples in buffer
- for (int i = 0; i < buffer.getNumSamples(); i++)
- {
- // Write data into circular buffer
- mCircularBufferLeft[mCircularBufferWriteHead] = leftChannel[i] + mFeedbackLeft;
- mCircularBufferRight[mCircularBufferWriteHead] = rightChannel[i] + mFeedbackRight;
- // Generate left channel LFO output
- float lfoOutLeft = sin(2 * double_Pi * mLFOPhase);
- // Calculate right channel LFO phase
- float lfoPhaseRight = mLFOPhase + *mPhaseOffsetParameter;
- // Perform bounds checking
- if (lfoPhaseRight >= 1)
- {
- lfoPhaseRight -= 1;
- }
- // Generate right channel LFO output
- float lfoOutRight = sin(2 * double_Pi * mLFOPhase);
- // Increase LFO phase
- mLFOPhase += *mRateParameter / getSampleRate();
- if (mLFOPhase >= 1)
- {
- mLFOPhase -= 1;
- }
- // Control LFO depth through parameter
- lfoOutLeft *= *mDepthParameter;
- lfoOutRight *= *mDepthParameter;
- // Map LFO outputs
- // Initialize mapped outputs
- float lfoOutMappedLeft = 0;
- float lfoOutMappedRight = 0;
- // chorus
- if (*mTypeParameter == 0)
- {
- lfoOutMappedLeft = jmap(lfoOutLeft, -1.f, 1.f, 0.005f, 0.03f);
- lfoOutMappedRight = jmap(lfoOutRight, -1.f, 1.f, 0.005f, 0.03f);
- }
- // flanger
- else
- {
- lfoOutMappedLeft = jmap(lfoOutLeft, -1.f, 1.f, 0.001f, 0.005f);
- lfoOutMappedRight = jmap(lfoOutRight, -1.f, 1.f, 0.001f, 0.005f);
- }
- // Calculate delay lengths in samples
- float delayTimeSamplesLeft = getSampleRate() * lfoOutMappedLeft;
- float delayTimeSamplesRight = getSampleRate() * lfoOutMappedRight;
- // Calculate read head positions
- float delayReadHeadLeft = mCircularBufferWriteHead - delayTimeSamplesLeft;
- float delayReadHeadRight = mCircularBufferWriteHead - delayTimeSamplesRight;
- // Perform bounds checking for left channel read head
- if (delayReadHeadLeft < 0)
- {
- delayReadHeadLeft += mCircularBufferLength;
- }
- // Perform bounds checking for right channel read head
- if (delayReadHeadRight < 0)
- {
- delayReadHeadRight += mCircularBufferLength;
- }
- // Calculate linear interpolation point for left channel
- int readHeadLeft_x = (int)delayReadHeadLeft;
- int readHeadLeft_x1 = readHeadLeft_x + 1;
- float readHeadFloatLeft = delayReadHeadLeft - readHeadLeft_x;
- // Perform bounds checking
- if (readHeadLeft_x1 >= mCircularBufferLength)
- {
- readHeadLeft_x1 -= mCircularBufferLength;
- }
- // Calculate linear interpolation point for right channel
- int readHeadRight_x = (int)delayReadHeadRight;
- int readHeadRight_x1 = readHeadRight_x + 1;
- float readHeadFloatRight = delayReadHeadRight - readHeadRight_x;
- // Perform bounds checking
- if (readHeadRight_x1 >= mCircularBufferLength)
- {
- readHeadRight_x1 -= mCircularBufferLength;
- }
- // Calculate interpolated samples
- float delay_sample_left = lin_interp(mCircularBufferLeft[readHeadLeft_x], mCircularBufferLeft[readHeadLeft_x1], readHeadFloatLeft);
- float delay_sample_right = lin_interp(mCircularBufferRight[readHeadRight_x], mCircularBufferRight[readHeadRight_x1], readHeadFloatRight);
- // Store delayed samples as feedback
- mFeedbackLeft = delay_sample_left * *mFeedbackParameter;
- mFeedbackRight = delay_sample_right * *mFeedbackParameter;
- // Increment write head
- mCircularBufferWriteHead++;
- // Perform bounds checking
- if (mCircularBufferWriteHead >= mCircularBufferLength)
- {
- mCircularBufferWriteHead = 0;
- }
- // Send Dry/Wet signal to audio buffer output
- buffer.setSample(0, i, buffer.getSample(0, i) * (1 - *mDryWetParameter) + delay_sample_left * (*mDryWetParameter));
- buffer.setSample(1, i, buffer.getSample(1, i) * (1 - *mDryWetParameter) + delay_sample_right * (*mDryWetParameter));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement