I’ve been working on a stereo enhancer plugin recently and ran into a small issue, my current code gets mid and side data from the L/R channels and then multiplies them my some amount.
However when i input a mono signal, there’s no side data to multiply and the signal stays mono no matter what (see snippet below)
I’ve been considering implementing a haas-effect like delay but ideally i would like to avoid any interference issues in mono. I’m not sure what other methods are usually used when making a mono sound “wide” and I would love some help finding some ways to go about this! thanks
code snippet:
float* leftChannel = buffer.getWritePointer(0);
float* rightChannel = buffer.getWritePointer(1);
float* dryLeft = buffer.getWritePointer(0);
float* dryRight = buffer.getWritePointer(1);
for (int i = 0; i < buffer.getNumSamples(); ++i)
{
// apply dB gain
float inGain = Decibels::decibelsToGain(inGainDb);
leftChannel[i] = leftChannel[i] * inGain;
rightChannel[i] = rightChannel[i] * inGain;
// apply the wideness-ness
// float widthVal = wide * 0.5;
float tmp = 1 / fmax(1 + wide, 2);
float coef_M = 1 * tmp;
float coef_S = wide * tmp;
float mid = (leftChannel[i] + rightChannel[i])*coef_M;
float sides = (rightChannel[i] - leftChannel[i])*coef_S;
// apply waveshaping to mid and side
// bentStepIG is a simple symmetric waveshaping function btw :3
mid = bentStepIG(mid, drive);
sides = bentStepIG(sides, drive);
float outGain = Decibels::decibelsToGain(outGainDb);
mid *= outGain;
sides *= outGain;
// set left and right outputs
float wetL = mid-sides;
float wetR = mid+sides;
// stereoise the left + right outputs
leftChannel[i] = (wetL * mix) + (dryLeft[i] * (1-mix));
rightChannel[i] = (wetR * mix) + (dryRight[i] * (1-mix));
}