Compare commits
3 Commits
774980200c
...
787bf50957
| Author | SHA1 | Date | |
|---|---|---|---|
| 787bf50957 | |||
| 1fd0a56064 | |||
| 8a55e8e60c |
@ -27,7 +27,7 @@ pico_sdk_init()
|
||||
|
||||
file(GLOB_RECURSE DAISYSP_SOURCES "${CMAKE_CURRENT_LIST_DIR}/daisysp/**/*.cpp")
|
||||
|
||||
add_executable(sint-gauntlet ${DAISYSP_SOURCES} main.c buttons.c mux.c pwm.c synth.cc)
|
||||
add_executable(sint-gauntlet ${DAISYSP_SOURCES} main.c input.c state.c pwm.c synth.cc)
|
||||
|
||||
pico_set_program_name(sint-gauntlet "sint-gauntlet")
|
||||
pico_set_program_version(sint-gauntlet "0.1")
|
||||
|
||||
12
build.sh
Executable file
12
build.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
DISK_ID=usb-RPI_RP2350_6F361FE334DD320F-0
|
||||
TARGET=sint-gauntlet.uf2
|
||||
|
||||
cd ./build
|
||||
cmake ..
|
||||
make -j
|
||||
sudo mount "/dev/disk/by-id/$DISK_ID:0-part1" /mnt
|
||||
sudo cp $TARGET /mnt
|
||||
sync
|
||||
|
||||
24
buttons.c
24
buttons.c
@ -1,24 +0,0 @@
|
||||
#include "const.h"
|
||||
#include "state.h"
|
||||
#include "vco.h"
|
||||
#include <pico/types.h>
|
||||
#include "hardware/gpio.h"
|
||||
|
||||
void check_button_change(uint pin, bool* btn_state) {
|
||||
static bool btn_prev[32] = { false };
|
||||
bool btn_now = gpio_get(pin);
|
||||
if (btn_now && !btn_prev[pin]) *btn_state = !*btn_state;
|
||||
btn_prev[pin] = btn_now;
|
||||
}
|
||||
|
||||
void update_buttons() {
|
||||
check_button_change(QUANT_BUTTON, &state.quant_enabled);
|
||||
check_button_change(AMEN_BUTTON, &state.amen_enabled);
|
||||
|
||||
bool vco_change;
|
||||
check_button_change(VCO_BUTTON, &vco_change);
|
||||
if (vco_change) {
|
||||
if (state.vco_mode == VCO_SAW) state.vco_mode = VCO_SINE;
|
||||
otherwise state.vco_mode++;
|
||||
}
|
||||
}
|
||||
11
const.h
11
const.h
@ -1,15 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#define MUX0 26
|
||||
#define MUX1 27
|
||||
|
||||
#define MUX_S0 2
|
||||
#define MUX_S1 3
|
||||
#define MUX_S2 4
|
||||
|
||||
#define MUX0 26
|
||||
#define MUX1 27
|
||||
|
||||
#define VCO_BUTTON 6
|
||||
#define QUANT_BUTTON 7
|
||||
#define AMEN_BUTTON 8
|
||||
#define BUTTON_BASE 6
|
||||
#define BUTTON_COUNT 4
|
||||
|
||||
#define AUDIO_OUT 0
|
||||
#define STATUS_LED 1
|
||||
|
||||
49
input.c
Normal file
49
input.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <hardware/adc.h>
|
||||
#include <hardware/gpio.h>
|
||||
#include <pico/stdlib.h>
|
||||
#include <pico/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
#include "input.h"
|
||||
|
||||
bool is_toggle[BUTTON_COUNT] = { false };
|
||||
bool btn_prev[BUTTON_COUNT] = { false };
|
||||
|
||||
void set_mux_addr(uint8_t addr) {
|
||||
gpio_put(MUX_S0, addr & 1);
|
||||
gpio_put(MUX_S1, (addr >> 1) & 1);
|
||||
gpio_put(MUX_S2, (addr >> 2) & 1);
|
||||
}
|
||||
|
||||
void update_inputs(input_t* input) {
|
||||
// Pots
|
||||
for (uint8_t j = 0; j < 2; j++) {
|
||||
adc_select_input(j);
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
set_mux_addr(i);
|
||||
sleep_us(50); // Let multiplexers multiplex
|
||||
float old_val = input->buttons[i + j * 8];
|
||||
float new_val = (float)adc_read() / 4096.0f;
|
||||
if (fabs(new_val - old_val) >= 0.01f) input->pots[i + j * 8] = new_val;
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons
|
||||
for (uint8_t i = 0; i < BUTTON_COUNT; i++) {
|
||||
bool btn_curr = gpio_get(BUTTON_BASE + i);
|
||||
|
||||
if (btn_curr == true && btn_prev[i] == false) {
|
||||
if (is_toggle[i]) input->buttons[i] = !input->buttons[i];
|
||||
}
|
||||
|
||||
if (!is_toggle[i]) input->buttons[i] = btn_curr;
|
||||
|
||||
btn_prev[i] = btn_curr;
|
||||
sleep_ms(1); // Why don't you bounce on this dihh
|
||||
}
|
||||
}
|
||||
|
||||
14
input.h
Normal file
14
input.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct {
|
||||
float pots[16];
|
||||
bool buttons[4];
|
||||
} input_t;
|
||||
|
||||
extern bool is_toggle[4];
|
||||
static inline void set_toggle_button(uint8_t index, bool toggle) { is_toggle[index] = toggle; }
|
||||
|
||||
void update_inputs(input_t* input);
|
||||
|
||||
99
main.c
99
main.c
@ -1,5 +1,7 @@
|
||||
#include <hardware/irq.h>
|
||||
#include <pico/stdio.h>
|
||||
#include <pico/time.h>
|
||||
#include <stdnoreturn.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@ -10,44 +12,17 @@
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "buttons.h"
|
||||
#include "synth.h"
|
||||
#include "const.h"
|
||||
#include "macro.h"
|
||||
#include "input.h"
|
||||
#include "state.h"
|
||||
#include "synth.h"
|
||||
#include "pwm.h"
|
||||
#include "mux.h"
|
||||
|
||||
input_t input;
|
||||
state_t state;
|
||||
|
||||
void init_all() {
|
||||
stdio_init_all();
|
||||
|
||||
sleep_ms(2000);
|
||||
|
||||
puts("Starting PIN initialization");
|
||||
const uint8_t out_gpio[] = {MUX_S0,MUX_S1,MUX_S2, STATUS_LED};
|
||||
const uint8_t in_gpio[] = {VCO_BUTTON,QUANT_BUTTON,AMEN_BUTTON};
|
||||
const uint8_t adc_gpio[] = {MUX0,MUX1};
|
||||
|
||||
for (uint8_t i=0; i < ARRAY_LENGTH(out_gpio); i++) {
|
||||
gpio_init(out_gpio[i]);
|
||||
gpio_set_dir(out_gpio[i], true);
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i < ARRAY_LENGTH(in_gpio); i++) {
|
||||
gpio_init(in_gpio[i]);
|
||||
gpio_set_dir(in_gpio[i], false);
|
||||
}
|
||||
adc_init();
|
||||
for (uint8_t i=0; i < ARRAY_LENGTH(adc_gpio); i++) {
|
||||
adc_gpio_init(adc_gpio[i]);
|
||||
adc_select_input(i);
|
||||
}
|
||||
|
||||
// Synth
|
||||
synth_init();
|
||||
|
||||
void core0_init(void) {
|
||||
// PWM bullshit
|
||||
gpio_set_function(AUDIO_OUT, GPIO_FUNC_PWM);
|
||||
|
||||
@ -61,22 +36,64 @@ void init_all() {
|
||||
irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_isr);
|
||||
irq_set_enabled(PWM_IRQ_WRAP, true);
|
||||
|
||||
puts("PWM Initialized.");
|
||||
|
||||
// Synth
|
||||
synth_init(&state);
|
||||
puts("Synth Initialized.");
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
void core1_main(void) {
|
||||
void core1_init(void) {
|
||||
// GPIO
|
||||
const uint8_t out_gpio[] = { MUX_S0, MUX_S1, MUX_S2, STATUS_LED };
|
||||
const uint8_t adc_gpio[] = {MUX0,MUX1};
|
||||
|
||||
for (uint8_t i = 0; i < ARRAY_LENGTH(out_gpio); i++) {
|
||||
gpio_init(out_gpio[i]);
|
||||
gpio_set_dir(out_gpio[i], true);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < BUTTON_COUNT; i++) {
|
||||
gpio_init(BUTTON_BASE + i);
|
||||
gpio_set_dir(BUTTON_BASE + 1, false);
|
||||
}
|
||||
|
||||
adc_init();
|
||||
adc_gpio_init(MUX0);
|
||||
adc_gpio_init(MUX1);
|
||||
|
||||
puts("GPIO Initialized.");
|
||||
|
||||
// Input
|
||||
set_toggle_button(0, true);
|
||||
set_toggle_button(1, false);
|
||||
set_toggle_button(2, true);
|
||||
}
|
||||
|
||||
noreturn void core1_loop(void) {
|
||||
while (1) {
|
||||
update_buttons();
|
||||
update_inputs();
|
||||
printf("Sample: %f\n", state.dbg_sample);
|
||||
update_inputs(&input);
|
||||
update_state(&state, &input);
|
||||
printf("%d %f\n", input.buttons[0], input.pots[0]);
|
||||
printf("%d\n", input.buttons[1]);
|
||||
printf("%d\n", input.buttons[2]);
|
||||
printf("%d\n", input.buttons[3]);
|
||||
sleep_ms(1);
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
int main() {
|
||||
init_all();
|
||||
multicore_launch_core1(core1_main);
|
||||
while (1);
|
||||
noreturn void core0_loop(void) {
|
||||
while (1) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
core0_init();
|
||||
core1_init();
|
||||
|
||||
multicore_launch_core1(core1_loop);
|
||||
core0_loop();
|
||||
}
|
||||
|
||||
|
||||
25
mux.c
25
mux.c
@ -1,25 +0,0 @@
|
||||
#include "const.h"
|
||||
#include "state.h"
|
||||
#include <hardware/adc.h>
|
||||
#include <pico/time.h>
|
||||
#include <stdint.h>
|
||||
#include <hardware/gpio.h>
|
||||
|
||||
void set_mux_addr(uint8_t addr) {
|
||||
gpio_put(MUX_S0, addr & 1);
|
||||
gpio_put(MUX_S1, (addr >> 1) & 1);
|
||||
gpio_put(MUX_S2, (addr >> 2) & 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void update_inputs() {
|
||||
for(uint8_t i = 0; i < 2; i++) {
|
||||
adc_select_input(i);
|
||||
for(uint8_t j = 0; j < 8;j++) {
|
||||
set_mux_addr(j);
|
||||
sleep_ms(1); // let multiplexor multiplex
|
||||
state.array[i*8 + j]= adc_read()/4096.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
mux.h
6
mux.h
@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
void set_mux_addr(uint8_t addr);
|
||||
void update_inputs();
|
||||
|
||||
2
pwm.c
2
pwm.c
@ -2,7 +2,6 @@
|
||||
#include <pico/types.h>
|
||||
|
||||
#include "const.h"
|
||||
#include "state.h"
|
||||
#include "synth.h"
|
||||
|
||||
#include "pwm.h"
|
||||
@ -15,7 +14,6 @@ void pwm_isr(void) {
|
||||
pwm_clear_irq(slice);
|
||||
|
||||
float sample = get_sample();
|
||||
state.dbg_sample = sample;
|
||||
|
||||
uint16_t level = (uint16_t)((sample + 1.0f) * 0.5f * 3400.0f);
|
||||
pwm_set_chan_level(slice, chan, level);
|
||||
|
||||
10
state.c
Normal file
10
state.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "input.h"
|
||||
|
||||
#include "state.h"
|
||||
|
||||
void update_state(state_t* state, input_t* input) {
|
||||
puts("AHHHHHH");
|
||||
}
|
||||
|
||||
34
state.h
34
state.h
@ -2,30 +2,28 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "input.h"
|
||||
#include "vco.h"
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
float clock_bpm;
|
||||
float vco_freq;
|
||||
float vco_volume;
|
||||
float filter_freq;
|
||||
float filter_resonance;
|
||||
float env1_attack;
|
||||
float env1_release;
|
||||
float env2_attack;
|
||||
float env2_release;
|
||||
float reverb_amount;
|
||||
};
|
||||
float array[16];
|
||||
};
|
||||
float clock_bpm;
|
||||
|
||||
float vco_freq;
|
||||
float vco_volume;
|
||||
vco_mode_t vco_mode;
|
||||
|
||||
float filter_freq;
|
||||
float filter_resonance;
|
||||
|
||||
float env1_attack;
|
||||
float env1_release;
|
||||
float env2_attack;
|
||||
float env2_release;
|
||||
|
||||
float reverb_amount;
|
||||
bool quant_enabled;
|
||||
bool amen_enabled;
|
||||
|
||||
float dbg_sample;
|
||||
} state_t;
|
||||
|
||||
extern state_t state;
|
||||
void update_state(state_t* state, input_t* input);
|
||||
|
||||
|
||||
45
synth.cc
45
synth.cc
@ -11,6 +11,8 @@
|
||||
|
||||
using namespace daisysp;
|
||||
|
||||
static state_t* state;
|
||||
|
||||
Oscillator osc;
|
||||
Svf filter;
|
||||
AdEnv vco_env;
|
||||
@ -97,11 +99,11 @@ float amenbreak(float beat_samples, float playback_rate) {
|
||||
return amen_out;
|
||||
}
|
||||
|
||||
void synth_init(void) {
|
||||
void synth_init(state_t* state) {
|
||||
osc.Init(SAMPLE_RATE);
|
||||
osc.SetWaveform(vco_mode_to_daisy(VCO_SAW));
|
||||
osc.SetFreq(440.0f);
|
||||
osc.SetAmp(2.0f);
|
||||
osc.SetAmp(1.0f);
|
||||
|
||||
filter.Init(SAMPLE_RATE);
|
||||
filter.SetFreq(2000.0f);
|
||||
@ -117,20 +119,20 @@ void synth_init(void) {
|
||||
filter_env.SetTime(ADENV_SEG_ATTACK, 0.01f);
|
||||
filter_env.SetTime(ADENV_SEG_DECAY, 0.5f);
|
||||
filter_env.SetMin(0.0f);
|
||||
filter_env.SetMax(1.0f);
|
||||
filter_env.SetMax(2000.0f);
|
||||
|
||||
state.clock_bpm = 0.2f;
|
||||
state->clock_bpm = 0.1f;
|
||||
|
||||
clock_phase = 0.0f;
|
||||
clock_trig = false;
|
||||
|
||||
amen_phase = 0.0f;
|
||||
state.amen_enabled = true;
|
||||
state.reverb_amount = 1.0;
|
||||
state->amen_enabled = true;
|
||||
state->reverb_amount = 1.0;
|
||||
}
|
||||
|
||||
float get_sample(void) {
|
||||
float bpm = BPM_MIN + state.clock_bpm * (BPM_MAX - BPM_MIN);
|
||||
float bpm = BPM_MIN + state->clock_bpm * (BPM_MAX - BPM_MIN);
|
||||
float beat_samples = SAMPLE_RATE * 60.0f / bpm;
|
||||
float playback_rate = bpm / AMEN_BPM;
|
||||
|
||||
@ -147,38 +149,39 @@ float get_sample(void) {
|
||||
filter_env.Trigger();
|
||||
}
|
||||
|
||||
vco_env.SetTime(ADENV_SEG_ATTACK, pot_to_time(state.env1_attack, ENV_ATTACK_MIN, ENV_ATTACK_MAX));
|
||||
vco_env.SetTime(ADENV_SEG_DECAY, pot_to_time(state.env1_release, ENV_RELEASE_MIN, ENV_RELEASE_MAX));
|
||||
filter_env.SetTime(ADENV_SEG_ATTACK, pot_to_time(state.env2_attack, ENV_ATTACK_MIN, ENV_ATTACK_MAX));
|
||||
filter_env.SetTime(ADENV_SEG_DECAY, pot_to_time(state.env2_release, ENV_RELEASE_MIN, ENV_RELEASE_MAX));
|
||||
vco_env.SetTime(ADENV_SEG_ATTACK, pot_to_time(state->env1_attack, ENV_ATTACK_MIN, ENV_ATTACK_MAX));
|
||||
vco_env.SetTime(ADENV_SEG_DECAY, pot_to_time(state->env1_release, ENV_RELEASE_MIN, ENV_RELEASE_MAX));
|
||||
filter_env.SetTime(ADENV_SEG_ATTACK, pot_to_time(state->env2_attack, ENV_ATTACK_MIN, ENV_ATTACK_MAX));
|
||||
filter_env.SetTime(ADENV_SEG_DECAY, pot_to_time(state->env2_release, ENV_RELEASE_MIN, ENV_RELEASE_MAX));
|
||||
|
||||
float vco_env_out = vco_env.Process();
|
||||
float filter_env_out = filter_env.Process();
|
||||
|
||||
float vco_freq = pot_to_freq(state.vco_freq, VCO_FREQ_MIN, VCO_FREQ_MAX);
|
||||
if (state.quant_enabled) vco_freq = quantize(vco_freq, 12.0f);
|
||||
float vco_freq = pot_to_freq(state->vco_freq, VCO_FREQ_MIN, VCO_FREQ_MAX);
|
||||
if (state->quant_enabled) vco_freq = quantize(vco_freq, 12.0f);
|
||||
|
||||
osc.SetFreq(vco_freq);
|
||||
osc.SetWaveform(vco_mode_to_daisy(state.vco_mode));
|
||||
osc.SetAmp(1.0f);
|
||||
//osc.SetFreq(vco_freq);
|
||||
static int n = VCO_SINE;
|
||||
osc.SetWaveform(vco_mode_to_daisy((vco_mode_t)(n++ % 4)));
|
||||
//osc.SetAmp(1.0f);
|
||||
|
||||
float vco_out = osc.Process();
|
||||
|
||||
float base_cutoff = pot_to_freq(state.filter_freq, FILTER_FREQ_MIN, FILTER_FREQ_MAX);
|
||||
float base_cutoff = pot_to_freq(state->filter_freq, FILTER_FREQ_MIN, FILTER_FREQ_MAX);
|
||||
float mod_cutoff = base_cutoff + filter_env_out * (FILTER_FREQ_MAX - FILTER_FREQ_MIN);
|
||||
mod_cutoff = fclamp(mod_cutoff, FILTER_FREQ_MIN, FILTER_FREQ_MAX);
|
||||
|
||||
filter.SetFreq(mod_cutoff);
|
||||
filter.SetRes(state.filter_resonance);
|
||||
//filter.SetFreq(mod_cutoff);
|
||||
//filter.SetRes(state.filter_resonance);
|
||||
filter.Process(vco_out);
|
||||
float filtered = filter.Low();
|
||||
|
||||
float vca_out = filtered * vco_env_out * state.vco_volume;
|
||||
float vca_out = filtered * vco_env_out;// * state.vco_volume;
|
||||
|
||||
float reverb_out = vca_out; //reverb(vca_out, state.reverb_amount);
|
||||
|
||||
float amen_out = 0.0f;
|
||||
if (state.amen_enabled) amen_out = amenbreak(beat_samples, playback_rate);
|
||||
if (state->amen_enabled) amen_out = amenbreak(beat_samples, playback_rate);
|
||||
|
||||
float mix = reverb_out + amen_out;
|
||||
mix = fclamp(mix, -1.0f, 1.0f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user