Tremolo Patch

Simple sine wave tremolo with adjustable frequency and gain!

#define m_SR 44100
class TremoloPatch : public SampleBasedPatch {
private:
  double omega;
public:
  TremoloPatch() : omega(0) {}
  void processAudio(AudioInputBuffer &input, AudioOutputBuffer &output){
    float phi, gain;
    getParameterValue(PARAMETER_A, phi);
    getParameterValue(PARAMETER_B, gain);
    int size = input.getSize();
    float buf[size];
    input.getSamples(0, size, buf);
    for(int i=0; i<size; ++i){
      omega += phi * 10 * 2*PI / m_SR;
      buf[i] = (float)(((1 + cos(omega))/2) * buf[i] * gain);
    }
    output.setSamples(0, size, buf);
  }
};

Been trying to get this patch working in VC++2012 but am having some problems with the buffer allocation

#ifndef __TremoloPatch_hpp__
#define __TremoloPatch_hpp__
#define _USE_MATH_DEFINES
#define m_SR 44100

#include &quot;StompBox.h&quot;
#include &lt;math.h&gt;

class TremoloPatch : public Patch {
private:
  double omega;
public:
  TremoloPatch() : omega(0) {}
  void processAudio(AudioInputBuffer &amp;input, AudioOutputBuffer &amp;output){
	float phi = getParameterValue(PARAMETER_A);
    float gain = getParameterValue(PARAMETER_B);
    int size = input.getSize();
    float buf[size];
    input.getSamples(0, size, buf);
    for(int i=0; i&lt;size; ++i){
      omega += phi * 10 * 2*M_PI / m_SR;
      buf[i] = (float)(((1 + cos(omega))/2) * buf[i] * gain);
    }
    output.setSamples(0, size, buf);
  }
};

#endif // __TremoloPatch_hpp__

I get the build error “error C2057: expected constant expression” in relation to float buf[size];

Any idea how to get around this?

Seb, try this:


int size = input.getSize();
float* buf = input.getSamples();

Got no errors in vc++2012.

Worked a dream. Here’s the patch for record```

#ifndef TremoloPatch_hpp
#define TremoloPatch_hpp
#define _USE_MATH_DEFINES
#define m_SR 44100

#include "StompBox.h"
#include <math.h>

class TremoloPatch : public Patch {
private:
double omega;
public:
TremoloPatch() : omega(0) {}
void processAudio(AudioInputBuffer &input, AudioOutputBuffer &output){
float phi = getParameterValue(PARAMETER_A);
float gain = getParameterValue(PARAMETER_B);
int size = input.getSize();
float* buf = input.getSamples();
input.getSamples(0, size, buf);
for(int i=0; i<size; ++i){
omega += phi * 10 * 2*M_PI / m_SR;
buf[i] = (float)(((1 + cos(omega))/2) * buf[i] * gain);
}
output.setSamples(0, size, buf);
}
};

#endif // __TremoloPatch_hpp__

Is there an audio sample of this patch at work? I’m excited to hear some of the sounds people are creating!

Gonna record some samples of this patch tomorrow.

Something like this. Nothing special, but intresting and simple. I think, I have to add depth control into this patch.