44.1Khz seams to work fine. But as soon as you go higher, say 88.2Khz or 192Khz. The sound becomes more and more, stuttery, grainy and noisy.
I’m sorry. I should have said that this is going to be open sourced. Please ignore my questions if you don’t feel like it.
It’s basically a port from VCVRack’s version of clouds. Here is the relevant processing part.
// Get input
if (!inputBuffer.full())
{
inputFrame.samples[0] = ppinl->in * kingain->value;
inputFrame.samples[1] = ppinr->num_cables ? ppinr->in * kingain->value : inputFrame.samples[0];
inputBuffer.push(inputFrame);
}
// Trigger
if (pptrig->in >= 1.0) triggered = true;
// Render frames
if (outputBuffer.empty())
{ clouds::ShortFrame input[32] = {};
dsp::Frame<2> inputFrames[32];
if (quality!=4)
{ // Convert input buffer
int inLen = inputBuffer.size();
int outLen = 32;
inputSrc.process(inputBuffer.startData(), &inLen, inputFrames, &outLen);
inputBuffer.startIncr(inLen);
// We might not fill all of the input buffer if there is a deficiency, but this cannot be avoided due to imprecisions between the input and output SRC.
for (int i = 0; i < outLen; i++) {
input[i].l = CLIP(inputFrames[i].samples[0] * 32767.0f, -32768.0f, 32767.0f);
input[i].r = CLIP(inputFrames[i].samples[1] * 32767.0f, -32768.0f, 32767.0f);
}
}
else
{ // No sample rate convertion
int blen = mmin(32,inputBuffer.size());
for (int i = 0; i < blen; i++)
{
input[i].l = CLIP(inputBuffer.startData()[i].samples[0] * 32767.0f, -32768.0f, 32767.0f);
input[i].r = CLIP(inputBuffer.startData()[i].samples[1] * 32767.0f, -32768.0f, 32767.0f);
}
inputBuffer.startIncr(blen);
}
UpdateProcessor();
clouds::Parameters* p = processor->mutable_parameters();
p->trigger = triggered;
p->gate = triggered;
p->freeze = freeze || (ppfreeze->in >= 1.0);
p->position = CLIP(kposition->value + ppposition->in, 0.0f, 1.0f);
p->size = CLIP(ksize->value + ppsize->in, 0.0f, 1.0f);
p->pitch = CLIP((SCALE(kpitch->value,-2.f,2.f) + pppitch->in*MIDI_TUNE_FACTOR) * 12.0f, -48.0f, 48.0f);
p->density = CLIP(kdensity->value + ppdensity->in, 0.0f, 1.0f);
p->texture = CLIP(ktexture->value + pptexture->in, 0.0f, 1.0f);
p->dry_wet = kblend->value;
p->stereo_spread = kspread->value;
p->feedback = kfeedback->value;
p->reverb = kreverb->value;
float blend = ppblend->in;
switch (blendMode)
{
case 0:
p->dry_wet += blend;
p->dry_wet = CLIP(p->dry_wet, 0.0f, 1.0f);
break;
case 1:
p->stereo_spread += blend;
p->stereo_spread = CLIP(p->stereo_spread, 0.0f, 1.0f);
break;
case 2:
p->feedback += blend;
p->feedback = CLIP(p->feedback, 0.0f, 1.0f);
break;
case 3:
p->reverb += blend;
p->reverb = CLIP(p->reverb, 0.0f, 1.0f);
break;
}
clouds::ShortFrame output[32];
processor->Process(input, output, 32);
if (quality != 4)
// Convert output buffer
{ dsp::Frame<2> outputFrames[32];
for (int i = 0; i < 32; i++) {
outputFrames[i].samples[0] = output[i].l / 32768.0;
outputFrames[i].samples[1] = output[i].r / 32768.0;
}
int inLen = 32;
int outLen = outputBuffer.capacity();
outputSrc.process(outputFrames, &inLen, outputBuffer.endData(), &outLen);
outputBuffer.endIncr(outLen);
}
else
{ // No sample rate convertion
for (int i = 0; i < 32; i++)
{ outputBuffer.endData()[i].samples[0] = output[i].l / 32768.0;
outputBuffer.endData()[i].samples[1] = output[i].r / 32768.0;
}
outputBuffer.endIncr(32);
}
triggered = false;
}
// Set output
outputFrame = outputBuffer.shift();
ppoutl->out = outputFrame.samples[0];
ppoutr->out = outputFrame.samples[1];