All my audio plugins make noise when first adding to Cubase


#1

I’m working and having fun with JUCE and C++, making some simple audio plugins, but all of them make horrible noise when launched the first time in Cubase and Studio One. And they don’t sound…
After some enabling and disabling the plugins start to work…
What could I’m wrong?


#2

Maybe some initial values that you don’t have set. Please check if all primitive types and arrays are initialized with zero. Also make sure you zero the data of all unused audio channel data arrays in the processing loop. Have a look at the demo plugin for this. Hope this helps.


#3

Maybe instead the configuration of the plugin?
I’ve noticed that in 32 bit universal (xcoce 8, OS X 10.11 ad Cubase 8 Le) the plugin starts and sound well (although there isa a terrible black window and black surrounds the GUI…).
But with 32/64 it make noise…
Can I use 64 bit intel?


#4

That’s probably just a random occurrence and you get lucky in that case, where that memory is already zero’d. As @patrickkunz says, it’s probably something you’re not explicitly initialising.


#5

Just in case you didn’t see it in the examples/generated plugin code, you should start always with something like this:

void AudioPlayerPlugin::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
{
    // clear buffer to avoid noise in case you are not filling them (all)
    for (int i = 0; i < buffer.getNumChannels(); ++i)
        buffer.clear(i, 0, buffer.getNumSamples());

    // your code
    ...

#6

…or just:

buffer.clear()

But it does sound like you’ve made some kind of horrendous memory corruption type mistake - I don’t think clearing the buffer will be enough to save you!


#7

Ok, I’ve used the STK modules (as I mentioned in earlier posts) and the value tree parameters.
I have followed the jucePluginDemo examples where in Processor declaration it passes the processBlock() to a process() function to add a new floatBuffer for the delay.
At this point I set the parameters of the STK constructors and methods in prepareToPlay() and only the methods in process().
In that method i clear the buffer and i call some other methods (applyDelay(); applyChorus(); applyGain() and so on) to apply a chain of STK effects to my plugin.
Here is some code:

void StkdemoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
    const float shiftVal = *parameters.getRawParameterValue("shiftVal");
    const float shifMix = *parameters.getRawParameterValue("shiftMix");

    const float chorusDepth = *parameters.getRawParameterValue("chorusDepth");
    const float chorusFreq = *parameters.getRawParameterValue("chorusFreq");
    const float chorusMix = *parameters.getRawParameterValue("chorusMix");

    const float delayTime = *parameters.getRawParameterValue("delayTime");
    const float delayGain = *parameters.getRawParameterValue("delayGain");

    const float reverbWidth = *parameters.getRawParameterValue("reverbWidth");
    const float reverbDamp = *parameters.getRawParameterValue("reverbDamp");
    const float reverbSize = *parameters.getRawParameterValue("reverbSize");
    const float reverbMix = *parameters.getRawParameterValue("reverbMix");

    pitchShift = stk::PitShift();
    pitchShift.setShift(shiftVal);
    pitchShift.setEffectMix(shifMix);
    
    chorus = stk::Chorus(1000);
    chorus.setModDepth(chorusDepth);
    chorus.setModFrequency(chorusFreq);
    chorus.setEffectMix(chorusMix);
    
    delay = stk::Delay();
    delay.setMaximumDelay(44100.0);
    delay.setDelay(delayTime);
    delay.setGain(delayGain);
    
    reverb = stk::FreeVerb();
    reverb.setMode(false);
    reverb.setWidth(reverbWidth);
    reverb.setDamping(reverbDamp);
    reverb.setRoomSize(reverbSize);
    reverb.setEffectMix(reverbMix);
    
    delayBufferFloat.setSize(2, 12000);
    delayBufferFloat.clear();
}

and:

void StkdemoAudioProcessor::process (AudioBuffer<float>& buffer, AudioBuffer<float>& delayBuffer)
{
    const int numSamples = buffer.getNumSamples();
    
    const float shiftVal = *parameters.getRawParameterValue("shiftVal");
    const float shifMix = *parameters.getRawParameterValue("shiftMix");
    
    const float chorusDepth = *parameters.getRawParameterValue("chorusDepth");
    const float chorusFreq = *parameters.getRawParameterValue("chorusFreq");
    const float chorusMix = *parameters.getRawParameterValue("chorusMix");
    
    const float delayTime = *parameters.getRawParameterValue("delayTime");
    const float delayGain = *parameters.getRawParameterValue("delayGain");
    
    const float reverbWidth = *parameters.getRawParameterValue("reverbWidth");
    const float reverbDamp = *parameters.getRawParameterValue("reverbDamp");
    const float reverbSize = *parameters.getRawParameterValue("reverbSize");
    const float reverbMix = *parameters.getRawParameterValue("reverbMix");

    pitchShift.setShift(shiftVal);
    pitchShift.setEffectMix(shifMix);

    chorus.setModDepth(chorusDepth);
    chorus.setModFrequency(chorusFreq);
    chorus.setEffectMix(chorusMix);
    
    delay.setDelay(delayTime);
    delay.setGain(delayGain);
    
    reverb.setWidth(reverbWidth);
    reverb.setDamping(reverbDamp);
    reverb.setRoomSize(reverbSize);
    reverb.setEffectMix(reverbMix);
    
    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...

    //applyAttack(buffer);
    applyGain(buffer);
    applyPitch(buffer);
    applyChorus(buffer);
    applyDelay(buffer, delayBuffer);
    applyReverb(buffer);
    
    //if (normalizing)
    //    rmsLevel = buffer.getRMSLevel(0, 0, buffer.getNumSamples());
    
    //if (applying)
    //    applyNormal(buffer);
    
    // In case we have more outputs than inputs, we'll clear any output
    // channels that didn't contain input data, (because these aren't
    // guaranteed to be empty - they may contain garbage).
    for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
        buffer.clear (i, 0, numSamples);
}

Do have I set the STK constructors in the Processor constructor and leave only the methods in the prepareToPlay() method?


#8

Never used STK, but their docs help, the stk delay needs a clear as well:

https://ccrma.stanford.edu/software/stk/classstk_1_1Delay.html#a0cf4c8da14bd4105eef06e35caaf1532

void stk::Delay::setMaximumDelay ( unsigned long delay )
Set the maximum delay-line length.

This method should generally only be used during initial setup of the delay line. If it is used between calls to the tick() function, without a call to clear(), a signal discontinuity will likely occur. If the current maximum length is greater than the new length, no memory allocation change is made.

Also the parameter is number of samples, you are supplying a float value. Doesn’t hurt but makes no sense…


#9

In my plugins I use a maximumDelay of 44100.0f that is one second…
I don’t need to clear because I don’t change that parameter anymore…I change only setDelay and setGain…


#10

You create the delay in prepareToPlay with the default constructor. The STK docs say:

The default constructor creates a delay-line with maximum length of 4095 samples and zero delay.

In the next line you call:

delay = stk::Delay();
delay.setMaximumDelay(44100.0);

Which increases the STK’s delay buffer to 44100 samples, so 40005 samples are newly allocated. I don’t know, if the new samples are also zeroed, if you want to give it a try, call delay.clear(); in the next line, like the STK docs I quoted suggest…

Good luck

EDIT: Checked in the sources of STK: the delay buffer is a protected variable of Filter.h line 78:

StkFrames inputs_;

And it is cleared in Filter::clear line 82:

inline void Filter :: clear( void )
{
  unsigned int i;
  for ( i=0; i<inputs_.size(); i++ )
    inputs_[i] = 0.0;
  for ( i=0; i<outputs_.size(); i++ )
    outputs_[i] = 0.0;
  for ( i=0; i<lastFrame_.size(); i++ )
    lastFrame_[i] = 0.0;  
}

…while setMaximumDelay in Delay.cpp line 42 only resizes the buffer:

void Delay :: setMaximumDelay( unsigned long delay )
{
  if ( delay < inputs_.size() ) return;
  inputs_.resize( delay + 1 );
}

So calling clear() is definitely needed.


#11

Thank you all but…Change of project, change of plugin, same effects but no sound…
I’ve followed all your suggestions…
New code:

void StkdemoAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
    const float shiftVal = *parameters.getRawParameterValue("shiftVal");
    const float shifMix = *parameters.getRawParameterValue("shiftMix");

    const float chorusDepth = *parameters.getRawParameterValue("chorusDepth");
    const float chorusFreq = *parameters.getRawParameterValue("chorusFreq");
    const float chorusMix = *parameters.getRawParameterValue("chorusMix");

    const float delayTime = *parameters.getRawParameterValue("delayTime");
    const float delayGain = *parameters.getRawParameterValue("delayGain");

    const float reverbWidth = *parameters.getRawParameterValue("reverbWidth");
    const float reverbDamp = *parameters.getRawParameterValue("reverbDamp");
    const float reverbSize = *parameters.getRawParameterValue("reverbSize");
    const float reverbMix = *parameters.getRawParameterValue("reverbMix");

    pitchShift = stk::PitShift();
    pitchShift.setShift(shiftVal);
    pitchShift.setEffectMix(shifMix);
    
    chorus = stk::Chorus(1000);
    chorus.setModDepth(chorusDepth);
    chorus.setModFrequency(chorusFreq);
    chorus.setEffectMix(chorusMix);
    
    delay = stk::Delay();
    delay.setMaximumDelay(44100.0);
    delay.clear();
    delay.setDelay(delayTime);
    delay.setGain(delayGain);
    
    reverb = stk::FreeVerb();
    reverb.setMode(false);
    reverb.setWidth(reverbWidth);
    reverb.setDamping(reverbDamp);
    reverb.setRoomSize(reverbSize);
    reverb.setEffectMix(reverbMix);
    
    delayBufferFloat.setSize(2, 12000);
    delayBufferFloat.clear();
}

and:

void StkdemoAudioProcessor::process (AudioBuffer<float>& buffer, AudioBuffer<float>& delayBuffer)
{
    const float shiftVal = *parameters.getRawParameterValue("shiftVal");
    const float shifMix = *parameters.getRawParameterValue("shiftMix");
    
    const float chorusDepth = *parameters.getRawParameterValue("chorusDepth");
    const float chorusFreq = *parameters.getRawParameterValue("chorusFreq");
    const float chorusMix = *parameters.getRawParameterValue("chorusMix");
    
    const float delayTime = *parameters.getRawParameterValue("delayTime");
    const float delayGain = *parameters.getRawParameterValue("delayGain");
    
    const float reverbWidth = *parameters.getRawParameterValue("reverbWidth");
    const float reverbDamp = *parameters.getRawParameterValue("reverbDamp");
    const float reverbSize = *parameters.getRawParameterValue("reverbSize");
    const float reverbMix = *parameters.getRawParameterValue("reverbMix");

    pitchShift.setShift(shiftVal);
    pitchShift.setEffectMix(shifMix);

    chorus.setModDepth(chorusDepth);
    chorus.setModFrequency(chorusFreq);
    chorus.setEffectMix(chorusMix);

    delay.setDelay(delayTime);
    delay.setGain(delayGain);
    
    reverb.setWidth(reverbWidth);
    reverb.setDamping(reverbDamp);
    reverb.setRoomSize(reverbSize);
    reverb.setEffectMix(reverbMix);
    
    //applyAttack(buffer);
    applyGain(buffer, delayBuffer);
    applyPitch(buffer, delayBuffer);
    applyChorus(buffer, delayBuffer);
    applyDelay(buffer, delayBuffer);
    applyReverb(buffer, delayBuffer);
    
    for (int i = 0; i < buffer.getNumChannels(); ++i)
        buffer.clear(i, 0, buffer.getNumSamples());
}

This time I used ValueTree, I have a complete GUI with sliders in attach to vts…

I’ve tried also to initialize the parameters of STKs with numbers… but no sound…

EDIT: here is the code for the first effect in chain:

void StkdemoAudioProcessor::applyPitch(AudioBuffer<float>& buffer)
{
    for (int channel = 0; channel < getTotalNumInputChannels(); ++channel)
    {
        stk::StkFloat* channelData = buffer.getWritePointer (channel);
        
        for (int i = 0; i < buffer.getNumSamples(); ++i)
        {
            channelData[i] = pitchShift.tick(channelData[i]);
        }
    }
}

That in my previous VST worked well.


#12

Sorry, then I am out of ideas.
Good luck finding it, or maybe somebody else finds something worth trying…


#13

The fact is that yesterday it worked, not at the first strike, but it emitted sound…
I’ve only added some parameters and sliders…
It seems to be only luck, not good coding :confused:


#14

It seems you changed the clear loop from (probably working)

for (int i = getTotalNumInputChannels(); i < getTotalNumOutputChannels(); ++i)
        buffer.clear (i, 0, numSamples);

accidentally to non-working

for (int i = 0; i < getTotalNumOutputChannels(); ++i)
            buffer.clear (i, 0, numSamples);

So now you are clearing the entire buffer at the end of your process method!

Btw. you can also remove reading all parameters in prepareToPlay if you read them in every process call anyway.

But to help further, it might be necessary to post a complete consistent example somewhere.
In your code snippets we cannot see how you are calling your process method.
Also applyPitch(AudioBuffer<float>& buffer) does not match to the rest of the code where it has 2 parameters…