I’m new at this and just trying to get a simple dub siren patch working. dubsiren with an main oscillator set initially to 440 that has a button to select different waveforms and a button that triggers an amplitude envelope and a button that routes an lfo oscillator set to sine between modulating the main oscillator, the filter and a null to stop modulation. route the main oscillator into a low pass filter initially set to 800 hz with medium resonance, then into a feedback delay set to 220 milliseconds with medium feedback. Knobs control main osc, filter freq, lfo amount, del time and feedback. I’ve only gotten pieces of this working by cutting and pasting examples into the arduino ide. This seems simple in comparison to the daisy projects in the world. My results tend to be loads of distorted digital sound no matter what. Do I have a bad board?
My method is to use Gpt 4 to help with the coding. I copy paste the modules in the examples that I want to use and then tell it to sort it out in a code. Copy that into arduino ide, find some errors and have gpt correct until it compiles. Once it uploads on to the board the sound is not what is expected. Generally a bunch of aliasing and distortion and not what is represented in the code.
Here is one that compiled without errors but is silent.
#include "DaisyDuino.h"
// Hardware setup
DaisyHardware hw;
size_t num_channels;
// Audio objects
static Oscillator osc;
static Svf filt;
static AdEnv adenv;
static DelayLine<float, 24000> del_left, del_right;
// Hardware control variables
float pitchknob, filterknob, delayTimeKnob, delayFeedbackKnob;
float sample_rate;
// Button setup
const int buttonPin = 2; // Define the button pin
bool lastButtonState = LOW; // Previous state of the button
bool envelopeTriggered = false; // Whether the envelope is currently triggered
// Audio callback
void MyCallback(float **in, float **out, size_t size) {
for (size_t i = 0; i < size; i++) {
// Oscillator frequency and envelope
osc.SetFreq(mtof(pitchknob));
// Process envelope if triggered
float env_out = envelopeTriggered ? adenv.Process() : 0.0;
float sig = osc.Process() * env_out;
// Filter processing
filt.Process(sig);
// Delay processing with feedback
float wet_left = del_left.Read();
float wet_right = del_right.Read();
float feedback_left = wet_left * delayFeedbackKnob;
float feedback_right = wet_right * delayFeedbackKnob;
del_left.Write((sig * 0.5) + feedback_left);
del_right.Write((sig * 0.5) + feedback_right);
// Output
out[0][i] = (filt.Low() * 0.707) + (wet_left * 0.707);
out[1][i] = (filt.High() * 0.707) + (wet_right * 0.707);
}
}
// Setup
void setup() {
// Initialize Daisy
hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
num_channels = hw.num_channels;
sample_rate = DAISY.get_samplerate();
// Initialize Oscillator
osc.Init(sample_rate);
osc.SetWaveform(osc.WAVE_TRI);
osc.SetFreq(440);
osc.SetAmp(0.5);
// Initialize Filter
filt.Init(sample_rate);
filt.SetFreq(800.0); // Default filter frequency
filt.SetRes(0.85);
filt.SetDrive(0.8);
// Initialize Envelope
adenv.Init(sample_rate);
adenv.SetTime(ADENV_SEG_ATTACK, 0.15);
adenv.SetTime(ADENV_SEG_DECAY, 0.35);
adenv.SetMin(0.0);
adenv.SetMax(0.25);
adenv.SetCurve(0); // linear
// Initialize Delay Lines
del_left.Init();
del_right.Init();
del_left.SetDelay(12000.0f); // Default delay time
del_right.SetDelay(8000.0f); // Default delay time
// Initialize button
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with pull-up resistor
// Start Audio
DAISY.begin(MyCallback);
}
// Main loop
void loop() {
// Read knob values
pitchknob = 24.0 + ((analogRead(A0) / 1023.0) * 60.0); // Oscillator pitch
filt.SetFreq(200.0 + ((analogRead(A1) / 1023.0) * 2000.0)); // Filter frequency
delayTimeKnob = 12000.0 * ((analogRead(A2) / 1023.0)); // Delay time
delayFeedbackKnob = 0.8 * ((analogRead(A3) / 1023.0)); // Delay feedback
// Update delay settings
del_left.SetDelay(delayTimeKnob);
del_right.SetDelay(delayTimeKnob);
// Button press detection
bool currentButtonState = digitalRead(buttonPin);
if (currentButtonState == LOW && lastButtonState == HIGH) {
// Button was pressed
adenv.Trigger();
envelopeTriggered = true;
} else if (currentButtonState == HIGH && lastButtonState == LOW) {
// Button was released
envelopeTriggered = false;
}
lastButtonState = currentButtonState;
}