Audio IO (Seed)
Prerequisites¶
Learn how to wire up 3.5mm mono jacks and pass audio through the Daisy Seed! This tutorial requires additional components to complete.
To get started, you need a few things:
- Daisy Seed
- USB Micro Cable
- Computer
- Breadboard
- 3.5mm Mono Jacks x2
- Jumper Wires
- Audio Output Source (speaker, headphones, oscilloscope, etc.)
- Line Level Signal Device (synth, sampler, smartphone, etc)
Video Tutorial
USB Power Cables
Double check that your USB cable is not a power-only cable. Often, these cables are marked with a lightning bolt or have a tag on them. However, this is not always the case. If you need to purchase a cable, Electrosmith's micro USB cable will get you up and running in no time!
Hardware & Circuitry¶
The Daisy Seed has two separate audio out pins that we can connect audio jacks to. These are the same pins that are used for Daisy boards like the Pod and Field, so if you’re using those, head over to the appropriate audio IO tutorial for each breakout board.
Placing Components On The Breadboard¶
First, let’s insert the Daisy Seed into a breadboard. This will allow us to connect components, such as an audio jack, to the Daisy with ease.
Our recommended installation has Pin 1 inserted in row G, with the Seed in the right most position possible on the breadboard.
See the image below for a reference of our recommended installation:
Next, let’s insert the audio jack to the breadboard in the below orientation:
Connecting Components¶
Now that our main components are on the breadboard, let's connect them!
Breadboard Fundamentals: Connecting Columns
A breadboard is a collection of isolated columns used for solderlessly connecting electrical components. If two components are inserted into the same column, they will be electrically connected. Upper and lower columns are isolated from one another, which helps prevent short circuiting larger boards such as Daisy.
If a schematic needs to bridge two columns on a breadboard, like what is needed in this tutorial, a jumper wire will connect one column's components to another column.
In order to configure the mono jack (see figure) as an audio output, the tip header on the jack must be connected to one of the two audio out pin headers on Daisy. For example purposes, let's connect the jack's tip header (3) using a jumper wire to Daisy pin 18: Audio Out 1.
Next, we will want to connect the jack sleeve header (1) to ground on the Seed. To keep the wires clean, connect the Seeds DGND (pin 20) to the breadboard's ground rail. Then, connect the jack's sleeve header to the same ground rail.
The jack is now properly wired to the Seed! Your breadboard should look like the below reference at this point:
Adding An Audio Input Jack¶
Now that we've run through placing and connecting the components, let's add a second jack for the Daisy Seed's audio input! Follow the same steps for placing and connecting the audio output jack, but connect the tip header for the new jack to the Seed's Audio Input 1 (pin 16). Your breadboard should now look like this:
We are now ready to send audio in and out of the Seed using code!
Firmware¶
Outputting a Sine Wave¶
Let's make Daisy sing! Let's pull an oscillator example from Daisyduino, and tailor it to our new hardware.
You can copy and paste the example code below into the Arduino IDE or download the Arduino file here:
#include "DaisyDuino.h"
DaisyHardware hw;
static Oscillator osc;
size_t num_channels;
void MyCallback(float **in, float **out, size_t size) {
float sine_signal;
for (size_t i = 0; i < size; i++) {
sine_signal = osc.Process();
out[0][i] = sine_signal;
}
}
void setup() {
// Initialize seed at 48kHz
float sample_rate;
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
num_channels = hw.num_channels;
sample_rate = DAISY.get_samplerate();
osc.Init(sample_rate);
// Set the parameters for oscillator
osc.SetWaveform(osc.WAVE_SIN);
osc.SetFreq(440);
osc.SetAmp(0.5);
// start callback
DAISY.begin(MyCallback);
}
void loop() {}
With the code now in Arduino, we can flash it to the Seed, and output a Sine Wave at 440Hz!
If you haven't already, we recommend stepping through the Daisyduino Blink tutorial to understand the appropriate board settings needed for flashing code to the Seed.
Make sure to place your Daisy Seed in Bootloader mode by holding down the BOOT button and pressing the RESET button:
Now that the Seed is in Bootloader mode, press the Upload button in the top left of the Arduino IDE. Your oscillator code will now flash to your Seed!
Give your program a listen! It should sound like the example below:
Experiment
Even with a simple sine wave outputting from Daisy, we can already begin changing parameters in the code to yield new results!
In the parameter section of the code, try adjusting the oscillator pitch by changing the osc.SetFreq
value from 440 to 880. The sine wave will now be one octave higher when reflashed!
Or, change the osc.SetWaveform
to another option available in the DaisySP Oscillator class!
Try out osc.WAVE_SAW
, osc.WAVE_SQUARE
, or others!
Audio Input and Output¶
Next, we are going to utilize both jacks on our bread board, and pass audio from an external source (line level) through the Daisy Seed.
To alter our existing code to be pass through instead of outputting an oscillator only, we will need to make a couple changes.
In the void MyCallback
section of the code, comment out the sine_signal;
from out[0][i]
, and add in[0][i]
instead. Your code should now look like the below reference. You can also download the Arduino file here to compare.
#include "DaisyDuino.h"
DaisyHardware hw;
static Oscillator osc;
size_t num_channels;
void MyCallback(float **in, float **out, size_t size) {
float sine_signal;
for (size_t i = 0; i < size; i++) {
sine_signal = osc.Process();
out[0][i] = in[0][i]; //sine_signal; //<-the line we changed
}
}
void setup() {
// Initialize seed at 48kHz
float sample_rate;
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
num_channels = hw.num_channels;
sample_rate = DAISY.get_samplerate();
osc.Init(sample_rate);
// Set the parameters for oscillator
osc.SetWaveform(osc.WAVE_SIN);
osc.SetFreq(440);
osc.SetAmp(0.5);
// start callback
DAISY.begin(MyCallback);
}
void loop() {}
With the code ready for flashing, place the Daisy Seed in bootloader mode by holding the BOOT button and pressing the RESET button.
Now upload the new code, and test the audio input and output jacks with a line level audio device.
This can be a synthesizer, sampler, or smartphone to name a few examples!
Our First DSP Effect: Ringmod¶
Now that we can pass audio through Daisy, we can apply effects to the audio! Let's combined what we've learned in this tutorial to create a ring modulation effect.
Let's change up our code. In the void MyCallback
section, re-include the sine_signal
variable and add a multiplication signal bewteen in[0][i]
and sine_signal
. Let's also change our oscillator frequency to 100
. Your code should now look like the below reference. You can also download the Arduino file here to compare.
#include "DaisyDuino.h"
DaisyHardware hw;
static Oscillator osc;
size_t num_channels;
void MyCallback(float **in, float **out, size_t size) {
float sine_signal;
for (size_t i = 0; i < size; i++) {
sine_signal = osc.Process();
out[0][i] = in[0][i] * sine_signal;
}
}
void setup() {
// Initialize seed at 48kHz
float sample_rate;
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
num_channels = hw.num_channels;
sample_rate = DAISY.get_samplerate();
osc.Init(sample_rate);
// Set the parameters for oscillator
osc.SetWaveform(osc.WAVE_SIN);
osc.SetFreq(100);
osc.SetAmp(0.5);
// start callback
DAISY.begin(MyCallback);
}
void loop() {}
With the code ready for flashing, place the Daisy Seed in bootloader mode by holding the BOOT button and pressing the RESET button.
Now let's listen to our line level instrument through the Seed.
Sounds funky right? It’s more metallic and dissonant. By multiplying the synth signal with the 100Hz sine signal, we implemented a type of amplitude modulation known as ring modulation. Even with very little code, we were able to do some interesting stuff!
What's Next?¶
Now that we can play sounds out of our Daisy, what’s next? While we were able to change the pitch of an oscillator by altering the frequency parameter, it was kind of tedious having to flash every time.
What if we could twist a knob to change the pitch in real-time? Well, we’ll be doing exactly that in the next tutorial!