Hi,
I’m making a simple sequencer, using various examples while learning daisyduino. Things go wrong when i add more than 2 signals. For example: snaredrum plus osc is fine, but adding snare leads to a nasty distorted osc sound. Also, when this happens, the upload never completes, and serial doesn’t work, take out the snare, and the distortion is gone and serial works again. I’m using a breadboard with stiff cables (the sort you strip and bend, not jumper cables)
Code below. I’m a bit stuck where to debug. any tips appreciated!
#include "DaisyDuino.h"
DaisyHardware hw;
AnalogBassDrum bd;
AnalogSnareDrum sd;
HiHat<> hh;
Oscillator osc;
Metro tick;
int seq[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int step = 0;
int curstep = 0;
Switch button_bd;
Switch button_sd;
Switch button_hh;
Switch button_osc;
static AdEnv adenv;
float amp =0;
void AudioCallback(float **in, float **out, size_t size) {
float signal = 0;
button_bd.Debounce();
button_osc.Debounce();
button_sd.Debounce();
button_hh.Debounce();
if (button_bd.RisingEdge()) {
bd.Trig();
Serial.println("bd pressed");
seq[curstep] = 1;
}
if (button_sd.RisingEdge()) {
sd.Trig();
Serial.println("sd pressed");
}
if (button_hh.RisingEdge()) {
hh.Trig();
Serial.println("hh pressed");
}
if (button_osc.RisingEdge()) {
adenv.Trigger();
Serial.println("osc pressed");
}
for (size_t i = 0; i < size; i++) {
signal = 0;
bool t = tick.Process();
// on the metro beat
if (t) {
bd.SetTone(analogRead(A0) / 1024.0);
step++;
curstep = step % 8;
if (seq[curstep] == 1) {
bd.Trig();
}
}
amp = adenv.Process();
osc.SetAmp(0.1f * amp);
signal += bd.Process();
signal += sd.Process();
signal += hh.Process();
signal += osc.Process();
out[0][i] = out[1][i] = signal;
}
}
void setup() {
Serial.begin(9600);
//potmeter
pinMode(A0, INPUT);
//switches
button_bd.Init(1000, true, 14, INPUT_PULLUP);
button_sd.Init(1000, true, 12, INPUT_PULLUP);
button_hh.Init(1000, true, 13, INPUT_PULLUP);
button_osc.Init(1000, true, 10, INPUT_PULLUP);
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
float sample_rate = DAISY.get_samplerate();
//drumkit
bd.Init(sample_rate);
bd.SetFreq(50.f);
sd.Init(sample_rate);
hh.Init(sample_rate);
//synth
osc.Init(sample_rate);
osc.SetWaveform(osc.WAVE_SIN);
osc.SetFreq(440);
osc.SetAmp(0.2f);
//synth env
adenv.Init(sample_rate);
adenv.SetTime(ADENV_SEG_ATTACK,0.2);
adenv.SetTime(ADENV_SEG_DECAY,1.0);
adenv.SetMin(0);
adenv.SetMax(1.0);
adenv.SetCurve(0);
tick.Init(2.f, sample_rate);
DAISY.begin(AudioCallback);
}
void loop() {
}