Hey guys I'm building a basic synth and i already have 2 osc, a filter controlled by a waveform osc to act as LFO. The 12 bit dac is used as audio output. I'm just starting to understand audio programming so everything is quite new to me.
On very specific values , like Freq : 19000 and Res 0.9 it makes a terrible sound (especially when i added the LFO), like white noise from a tv or sth.
Please let me know what i have been doing wrong.
Update: I'm also using 100K pots, can this be the issue?... connected to + and ground and to the analog pins
On very specific values , like Freq : 19000 and Res 0.9 it makes a terrible sound (especially when i added the LFO), like white noise from a tv or sth.
Please let me know what i have been doing wrong.
Update: I'm also using 100K pots, can this be the issue?... connected to + and ground and to the analog pins
Code:
#include <MIDI.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=190,258
AudioSynthWaveform waveform2; //xy=221,327
AudioSynthWaveform wave_lfo; //xy=357,444
AudioMixer4 mixer1; //xy=424,284
AudioMixer4 lfo_mixer_int; //xy=557,431
AudioEffectEnvelope envelope1; //xy=577,268
AudioFilterStateVariable filter1; //xy=756,285
AudioOutputAnalog dac1; //xy=936,272
AudioConnection patchCord1(waveform1, 0, mixer1, 0);
AudioConnection patchCord2(waveform2, 0, mixer1, 1);
AudioConnection patchCord3(wave_lfo, 0, lfo_mixer_int, 0);
AudioConnection patchCord4(mixer1, envelope1);
AudioConnection patchCord5(lfo_mixer_int, 0, filter1, 1);
AudioConnection patchCord6(envelope1, 0, filter1, 0);
AudioConnection patchCord7(filter1, 0, dac1, 0);
// GUItool: end automatically generated code
float freq;
float res;
float mixer_osc1_vol;
float mixer_osc2_vol;
float lfo_rate = 0.0;
float lfo_int = 0.0;
bool note_on ;
byte current_midi_note;
void setup() {
AudioMemory(12);
Serial.begin(57600);
//Envelopes
// VCA envelopes
envelope1.attack(1.5);
envelope1.hold(0.0); // not used
envelope1.decay(15);
envelope1.sustain(1.0);
envelope1.release(5.0);
//filtro
freq = 0.0;
res = 0.0;
//filter1.octaveControl(1.0);
//Lfo
lfo_rate = 0.0;
lfo_int = 0.0;
mixer1.gain(0,0.0); //Iniciar SAW
mixer1.gain(1,0.5); //Iniciar SQUARE
lfo_mixer_int.gain(0,0.0); //Iniciar Intensidad LFO Filtro
//MIDI STUFF
Serial.begin(57600);
Serial.println("MIDI Input Test");
// put your setup code here, to run once:
waveform1.begin(0.1,220,WAVEFORM_SAWTOOTH);
waveform2.begin(0.1,220,WAVEFORM_SQUARE);
wave_lfo.begin(0.1, 0, WAVEFORM_SINE);
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin();
}
void loop() {
int type, note, velocity, channel, d1, d2;
// put your main code here, to run repeatedly:
int knob1 = analogRead(A1);
int knob2 = analogRead(A0);
int knob3 = analogRead(A2);
int knob4 = analogRead(A3);
freq = map(knob1,0,1023,0,19000);
res = map(knob2,0,1023,90,500);
lfo_rate = map(knob3,0,1023,0,20);
lfo_int = map(knob4,0,1023,0,500);
res = float(res / 100);
lfo_int = float(lfo_int / 100);
wave_lfo.frequency(lfo_rate);
lfo_mixer_int.gain(0,lfo_int);
Serial.println(String("Cut: ") + freq + ", Res=" + res + ", LFO INT=" + lfo_int);
filter1.frequency(freq);
filter1.resonance(res);
MIDI.read();
}
void handleNoteOn(byte inChannel, byte inNote, byte inVelocity)
{
//Tocamos nota
current_midi_note = inNote;
note_on = true;
waveform1.frequency(mtof(inNote));
waveform2.frequency(mtof(inNote));
envelope1.noteOn(); //Tocar nota
if(inVelocity == 0 && inNote == current_midi_note)
{
envelope1.noteOff();
}
}
void handleNoteOff(byte inChannel, byte inNote, byte inVelocity)
{
if(inNote == current_midi_note){
envelope1.noteOff();
note_on = false;
}
}
float mtof(float midival)
{
// code from AF_precision_synthesis sketch, copyright 2009, Adrian Freed.
float f = 0.0;
if(midival) f = 8.1757989156 * pow(2.0, midival/12.0);
return f;
}
Last edited: