Added state processing stage
This commit is contained in:
parent
1fd0a56064
commit
787bf50957
@ -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 input.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")
|
||||
|
||||
14
input.c
14
input.c
@ -2,8 +2,9 @@
|
||||
#include <hardware/gpio.h>
|
||||
#include <pico/stdlib.h>
|
||||
#include <pico/time.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
@ -20,13 +21,14 @@ void set_mux_addr(uint8_t addr) {
|
||||
|
||||
void update_inputs(input_t* input) {
|
||||
// Pots
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
set_mux_addr(i);
|
||||
for (uint8_t j = 0; j < 2; j++) {
|
||||
adc_select_input(j);
|
||||
sleep_us(20); // Let multiplexers multiplex
|
||||
uint16_t val = adc_read();
|
||||
if (val > 5) input->pots[i + j * 8] = (float)val;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
3
main.c
3
main.c
@ -39,7 +39,7 @@ void core0_init(void) {
|
||||
puts("PWM Initialized.");
|
||||
|
||||
// Synth
|
||||
synth_init();
|
||||
synth_init(&state);
|
||||
puts("Synth Initialized.");
|
||||
}
|
||||
|
||||
@ -73,6 +73,7 @@ void core1_init(void) {
|
||||
noreturn void core1_loop(void) {
|
||||
while (1) {
|
||||
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]);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
16
state.h
16
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;
|
||||
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;
|
||||
};
|
||||
float array[16];
|
||||
};
|
||||
vco_mode_t vco_mode;
|
||||
bool quant_enabled;
|
||||
bool amen_enabled;
|
||||
|
||||
float dbg_sample;
|
||||
} state_t;
|
||||
|
||||
extern state_t state;
|
||||
void update_state(state_t* state, input_t* input);
|
||||
|
||||
|
||||
28
synth.cc
28
synth.cc
@ -11,6 +11,8 @@
|
||||
|
||||
using namespace daisysp;
|
||||
|
||||
static state_t* state;
|
||||
|
||||
Oscillator osc;
|
||||
Svf filter;
|
||||
AdEnv vco_env;
|
||||
@ -97,7 +99,7 @@ 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);
|
||||
@ -119,18 +121,18 @@ void synth_init(void) {
|
||||
filter_env.SetMin(0.0f);
|
||||
filter_env.SetMax(2000.0f);
|
||||
|
||||
state.clock_bpm = 0.1f;
|
||||
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,16 +149,16 @@ 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);
|
||||
static int n = VCO_SINE;
|
||||
@ -165,7 +167,7 @@ float get_sample(void) {
|
||||
|
||||
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);
|
||||
|
||||
@ -179,7 +181,7 @@ float get_sample(void) {
|
||||
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