Hi everyone.
I’m going to start off by saying that I’m a VERY amateur programmer and brand new into DSP. After building a bunch of analog guitar effects over the years, I caught wind of the Daisy Seed and thought that it would be fun to tinker around with. However, there are very few resources on learning how to program it. The mods on this forum seem to be active and very helpful, but I believe they’re putting most of their resources into improving the Daisy.
I’m still learning C++ and I have some Arduino experience, so I figured I’d start out with that. If you have limited programming experience (like myself) and opened up an example, you’ll see that very few of them have comments and can be confusing. I may not be the best or most capable, but I believe that contributing something, however basic, is better than not contributing at all. To build a better and lasting community, we need to help out the newbies.
My goal is to help newer people to read and understand the code, and also to be able to pick apart and dissect examples to create their own stuff.
I’m assuming that you were able to configure Arduino and are able to upload a program to the Seed. I know I had several frustrating hours to get it to work only to find a post in the forum about not installing an updated version of stm32duino.
Getting Started:
When I first hooked up my Daisy Seed to a breadboard and some 1/4" guitar jacks, it was very noisy, low volume, and muddy. This is because the guitar output signal is very low compared to what the Seed can handle. We can fix these problems by making an input and output buffer. The buffer will amplify the signal a bit and block out the noise. There is another post on this forum about buffers, but to make it easy, I just picked up the Terrarium PCB from pedalpcb.com. It works great (however, I don’t have any pots or switches hooked up to it yet!). If you’re brand new to programming, I would highly recommend watching some YouTube videos on basic Arduino or C programming. I’m currently watching this 10 hour video on C++. The young dude is a fantastic intructor and would highly recommend watching it. https://youtu.be/_bYFu9mBnr4
The Code:
Many of the examples use left and right channels. Since we’re here just making single channel guitar effects, we can ignore a lot of the example code. For the first few examples, I’m also going to leave out any potentiometers and switches. We’ll just hard code everything for simplicity. I wrote a very simple input to output straight-through program just to get a ‘boiler plate’ program working. Copy this code into Arduino and upload it to your Seed.
#include <DaisyDuino.h>
DaisyHardware hw;
static void AudioCallback(float *in, float *out, size_t size)
{
for(size_t i = 0; i < size; i++)
{
out[i] = in[i];
}
}
void setup() {
hw = DAISY.init(DAISY_PETAL, AUDIO_SR_48K);
DAISY.begin(AudioCallback);
}
void loop() {
// put your main code here, to run repeatedly:
}
Great! You should hear your guitar going through the Seed and out into your amp. Now what’s going on? Let’s take it step by step.
#include <DaisyDuino.h>
This statement allows Arduino to access the DaisyDuino header and libraries. The header contains all the necessary stuff to interface and compile the program from Arduino to our Seed.
DaisyHardware hw;
Here, we’re creating an object, hw, of the DaisyHardware Class which is built into the DaisyDuino library. It makes it easier for us to access the class without cumbersome code. We’re going to skip the next section for now and jump to the void setup
void setup() {
hw = DAISY.init(DAISY_PETAL, AUDIO_SR_48K);
DAISY.begin(AudioCallback);
}
void loop() {
// put your main code here, to run repeatedly:
}
So what’s going on here? When an Arduino program runs, the very first thing it does is run through the code in the ‘void setup’ function. It only runs this code once. The next line in this function ‘hw = DAISY.init(DAISY_PETAL, AUDIO_SR_48K);’ is how we’re going to initialize our Seed. It’s going to assign all the input/output pins to be that of a Daisy Pedal (which I don’t have, but the Terrarium is indentical for our purposes) and have a sample rate of 48k.
After that, we need to start processing audio with ‘DAISY.begin(AudioCallback);’ This is going to call the AudioCallback function and run on effectively a loop. Because of this, we don’t need anything in the void loop(){} function, but Arduino requires that loop function to compile.
static void AudioCallback(float *in, float *out, size_t size)
{
for(size_t i = 0; i < size; i++)
{
out[i] = in[i];
}
}
To be completely honest, this is magic to me. I’ve looked around and there are virtually no references on what really goes on inside the DaisyDuino. I’m sure if you dig deep enough you can find a better explanation, but for now, realize that you need this code to make any program to work.
As far as I can tell, when you call the AudioCallback function using DAISY.begin, it defines in and out as floats. The * points to a location, which I assume is defined in the header as the input and output pins. The program runs this function whenever it has audio to process. I haven’t figured out what the ‘size_t size’ does yet, but you need it for the subsequent ‘for’ loop. Inside that ‘for’ loop is what actually processes our code. In this instance, we’re just making the output to be equal to the input by doing ‘out[i] = in[i];’
So we walked through our first, simple program, but I’m not too happy with it. Fidelity is pretty good, latency is not noticable at all, but I found the output volume a bit too low. Let’s fix that with a quick adjustment.
out[i] = in[i] * 2;
There we go. The volume on the amp is about the same if I have my guitar plugged in through the Seed or not. Next, let’s make a simple distortion effect!