This commit is contained in:
Tom-on64 2026-04-25 03:05:25 +02:00
parent 0daca6f46b
commit 09b1a6707a
4 changed files with 16 additions and 8 deletions

14
main.c
View File

@ -3,7 +3,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include "hardware/gpio.h" #include "hardware/gpio.h"
#include "hardware/pwm.h" #include "hardware/pwm.h"
@ -23,6 +22,9 @@ state_t state;
void init_all() { void init_all() {
stdio_init_all(); stdio_init_all();
sleep_ms(2000);
puts("Starting PIN initialization"); puts("Starting PIN initialization");
const uint8_t out_gpio[] = {MUX_S0,MUX_S1,MUX_S2, STATUS_LED}; 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 in_gpio[] = {VCO_BUTTON,QUANT_BUTTON,AMEN_BUTTON};
@ -43,6 +45,9 @@ void init_all() {
adc_select_input(i); adc_select_input(i);
} }
// Synth
synth_init();
// PWM bullshit // PWM bullshit
gpio_set_function(AUDIO_OUT, GPIO_FUNC_PWM); gpio_set_function(AUDIO_OUT, GPIO_FUNC_PWM);
@ -55,6 +60,7 @@ void init_all() {
pwm_set_irq_enabled(slice, true); pwm_set_irq_enabled(slice, true);
irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_isr); irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_isr);
irq_set_enabled(PWM_IRQ_WRAP, true); irq_set_enabled(PWM_IRQ_WRAP, true);
} }
__attribute__((noreturn)) __attribute__((noreturn))
@ -62,8 +68,8 @@ void core1_main(void) {
while (1) { while (1) {
update_buttons(); update_buttons();
update_inputs(); update_inputs();
printf("vco_mode: %d, quant_enabled: %d amen_enabled: %d\n", state.vco_mode,state.quant_enabled,state.amen_enabled); //printf("vco_mode: %d, quant_enabled: %d amen_enabled: %d\n", state.vco_mode,state.quant_enabled,state.amen_enabled);
printf("clock_bpm: %f\n",state.clock_bpm); //printf("clock_bpm: %f\n",state.clock_bpm);
sleep_ms(1); sleep_ms(1);
} }
} }
@ -71,9 +77,7 @@ void core1_main(void) {
__attribute__((noreturn)) __attribute__((noreturn))
int main() { int main() {
init_all(); init_all();
multicore_launch_core1(core1_main); multicore_launch_core1(core1_main);
while (1) {} while (1) {}
} }

3
pwm.c
View File

@ -1,5 +1,6 @@
#include <hardware/pwm.h> #include <hardware/pwm.h>
#include <pico/types.h> #include <pico/types.h>
#include <stdio.h>
#include "const.h" #include "const.h"
#include "synth.h" #include "synth.h"
@ -13,8 +14,8 @@ void pwm_isr(void) {
pwm_clear_irq(slice); pwm_clear_irq(slice);
// TODO:
float sample = get_sample(); float sample = get_sample();
printf("sample: %f\n", sample);
uint16_t level = (uint16_t)((sample + 1.0f) * 0.5f * 3400.0f); uint16_t level = (uint16_t)((sample + 1.0f) * 0.5f * 3400.0f);
pwm_set_chan_level(slice, chan, level); pwm_set_chan_level(slice, chan, level);

View File

@ -72,6 +72,10 @@ void synth_init(void) {
} }
float get_sample(void) { float get_sample(void) {
return osc.Process();
}
float _get_sample(void) {
float bps = state.clock_bpm / 60.0f; float bps = state.clock_bpm / 60.0f;
float clock_inc = bps / SAMPLE_RATE; float clock_inc = bps / SAMPLE_RATE;
clock_phase += clock_inc; clock_phase += clock_inc;
@ -118,7 +122,5 @@ float get_sample(void) {
mix = fclamp(mix, -1.0f, 1.0f); mix = fclamp(mix, -1.0f, 1.0f);
return mix; return mix;
return 0;
} }

View File

@ -4,6 +4,7 @@
extern "C" { extern "C" {
#endif #endif
void synth_init(void);
float get_sample(void); float get_sample(void);
#ifdef __cplusplus #ifdef __cplusplus