Friday, 23 August 2013

Simple mono synth with groovuino library

Here is a simple example on how to make a monophnic 1-osc synth with the groovuino lib.
I added a low-pass filter and a very light sequencer.

Here is the video :

You just need 4 potentiometers and an audio out as described in this post :

The potentiometers are plugged on analog inputs 3,4,5 and 6.

Analog 3 : octave of the arpeggio
Analog 4 : filter frequency
Analog 5 : bpm
Analog 6 : choice of the arpeggio

The code :

Incude your libraries. We just need the osc and low-pass filter.

#include <arduino.h>
#include <osc.h>
#include <filter.h>

We will use the Due timer library. I like it. You can download it here, and copy the repository in your arduino library folder.

#include <DueTimer.h>

Now instanciate your oscillator and filter :

Osc osc;
LowPassFilter LP;

Some data we will need for the arpeggiator :

int step = 0;
int numarp = 0;
int count = 0;

The arpeggio sequences (8 sequences of 16 notes). You can build your own sequences.
0 is is A 440 Hz. 2 = B, 3 = C, 12 = A octave...

int nArps[8][16] = {

Initialize everything :

void setup() 


The analog inputs :

  pinMode(A6, INPUT);
  pinMode(A5, INPUT);
  pinMode(A4, INPUT);
  pinMode(A3, INPUT);

Start the timers : one 44.1 kHz for audio generation, and on 100 Hz for sequencer :


Generate the wavetables. We'll only use Sine, Saw, and Square :


Initialize the DAC output.


Set cutoff and resonance to default values :


Set the oscillator to default values :

  osc.setVolOsc(0, 127);

Read the potentiometers.
analog 6 selects the arpeggio number (8 arrpeggios, so the number is 3 bits long)
analog 4 sets the cutoff frequency

void loop() 

  numarp = analogRead(6)>>7;

Generate the sound :
One osc with LP filter.

void loop1() 

  int32_t ulOutput=2048;;

  ulOutput +=;
  if(ulOutput>4095) ulOutput=4095;
  if(ulOutput<0) ulOutput=0;
  dacc_write_conversion_data(DACC_INTERFACE, ulOutput); 

The sequencer :
analog 5 fixes the tempo. If the value is high, the time between 2 notes will be long.
analog 3 sets the octave. (it adds an integer * 12 to the note).

void loop2()
    if(step>=15) step = 0;
    else step+=1;
    count = 0;
  else count++;


  1. I tried loading this on a board I'm using.
    I had to change LowPassFilter2.h to filter.h to get it to compile. Is LowPassFilter2.h a new library?
    I had to also change DAC1 to DAC0 since that is what I use.
    What does each POT do? I'm having difficulty reproducing sounds similar to your video.

  2. Ok are they:
    A3: key
    A4: filter cutoff
    A5: period
    A6: sequence select

    1. Hi,
      Yes you're right. I updated my post. The potentiometers act like this :
      Analog 3 : octave of the arpeggio
      Analog 4 : filter frequency
      Analog 5 : bpm
      Analog 6 : choice of the arpeggio

      I updated my library to add the new version of the filter. I updated too the osc.h file. In fact you can change the number of oscillator, or the glide mode in the file. In my library it was 3 oscillators by default, and glide on, so that's maybe why you got different sound than my video. Now I put 1 osc and glide off as default values, so it hould be ok now.
      Tell me if it works now.

      Thanks !

  3. the new osc.h has a bug:
    osc.h: In member function 'void Osc::setNote(uint32_t, int32_t)':
    osc.h:128: error: 'else' without a previous 'if'

    1. Do you get this message?
      Groovuino_test1.ino:7: warning: undefined reference to `LowPassFilter::LowPassFilter()`

    2. Yes, but it should work anyway.

  4. In osc.setNote does it take a MIDI note in or something else?

    1. Yes, it's a value between 0-128, 0 is A-2, like MIDI.

  5. Hey there Gaetan,

    Your library looks amazing! I'm having trouble to get this sketch to make any sound, though. I know my DACs are OK, because Duane B's DDS Sinwave example works fine on both DACs.

    Can you confirm that this sketch works with the latest version of the DueTimer library? I'm on version 1.4.1

    To minimize the chance that I've messed up the wiring for the pots, I've replaced the 4 calls to analogRead with a fixed value of 512, eg.
    numarp = analogRead(6)>>7;
    numarp = 512>>7;

    Still no luck.

    By the way, I also get
    warning: undefined reference to `LowPassFilter::LowPassFilter()

    But that should be OK, right?

    I'm wondering if you could post an even more minimal sketch for testing purposes - just something like a single oscillator producing a test tone.


  6. I got it going by commenting all the code relating to the filter, and replacing the line
    ulOutput +=;
    ulOutput = osc.output();