Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//Fill the mAudioToResample array with 100 cycles of a 441hz sine wave
double recip = 1. / 44100.;
double phase = 0.;
for (int i = 0; i< 44100; i++)
{
mAudioToResampleL[i] = sin( phase * 6.283185307179586);
mAudioToResampleR[i] = mAudioToResampleL[i] * -1.; // just for example
phase += recip * 441.;
if (phase > 1.) phase -= 1.;
}
mSampleIndxL = 0;
mSampleIndxR = 0;
mResamplerL.SetMode(true, 1, false, 0, 0);
mResamplerR.SetMode(true, 1, false, 0, 0);
mResamplerL.SetFilterParms();
mResamplerR.SetFilterParms();
mResamplerL.SetFeedMode(false);
mResamplerR.SetFeedMode(false);
mResamplerL.SetRates(44100., GetSampleRate());
mResamplerR.SetRates(44100., GetSampleRate());
class IPlugGenTwoInputs : public IPlug
{
public:
IPlugGenTwoInputs(IPlugInstanceInfo instanceInfo);
~IPlugGenTwoInputs();
void Reset();
void OnParamChange(int paramIdx);
void ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames);
private:
int mSampleIndxL, mSampleIndxR;
WDL_Resampler mResamplerL, mResamplerR;
WDL_ResampleSample mAudioToResampleL[44100];
WDL_ResampleSample mAudioToResampleR[44100];
double mGain;
CommonState *gen;
};
void IPlugGenTwoInputs::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
// Mutex is already locked for us.
double* inL = inputs[0];
double* inR = inputs[1];
// DO LEFT CHANNEL ---------------------------------------------------------
WDL_ResampleSample *resampledAudioL=NULL;
int numSamplesL = mResamplerL.ResamplePrepare(nFrames, 1, &resampledAudioL);
for (int s = 0; s < numSamplesL; s++)
{
if (mSampleIndxL >= 44100)
mSampleIndxL = 0;
resampledAudioL[s] = mAudioToResampleL[mSampleIndxL++] * mGain;
}
if (mResamplerL.ResampleOut(inL, numSamplesL, nFrames, 1) != nFrames)
{
//failed somehow
memset(inL, 0 , nFrames * sizeof(double));
}
// DO RIGHT CHANNEL ---------------------------------------------------------
WDL_ResampleSample *resampledAudioR=NULL;
int numSamplesR = mResamplerR.ResamplePrepare(nFrames, 1, &resampledAudioR);
for (int s = 0; s < numSamplesR; s++)
{
if (mSampleIndxR >= 44100)
mSampleIndxR = 0;
resampledAudioR[s] = mAudioToResampleR[resampledAudioR++] * mGain;
}
if (mResamplerR.ResampleOut(inR, numSamplesR, nFrames, 1) != nFrames)
{
//failed somehow
memset(inR, 0 , nFrames * sizeof(double));
}
//---------------------------------------------------------
//input buffers now contain the two resampled sound sources
perform(gen, inputs, num_inputs(), outputs, num_outputs(), nFrames);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.