Maybe works?
This commit is contained in:
@@ -3,17 +3,24 @@
|
||||
|
||||
#include "state.h"
|
||||
|
||||
float quantize(float freq) {
|
||||
if (freq <= 0.0f) return 0.0f;
|
||||
float midi = 69.0f + 12.0f * log2f(freq / 440.0f);
|
||||
return 440.0f * powf(2.0f, (roundf(midi) - 69.0f) / 12.0f);
|
||||
}
|
||||
|
||||
|
||||
void update_state(state_t* state, input_t* input) {
|
||||
state->clock_bpm = map_linear(input->pots[0], BPM_MIN, BPM_MAX);
|
||||
state->vco_freq = map_exponential(input->pots[1], VCO_FREQ_MIN, VCO_FREQ_MAX);
|
||||
state->vco_volume = map_exponential(input->pots[2], VCO_VOLUME_MIN, VCO_VOLUME_MAX);
|
||||
state->filter_freq = map_exponential(input->pots[3], FILTER_FREQ_MIN, FILTER_FREQ_MAX);
|
||||
state->filter_resonance = map_linear(input->pots[4], FILTER_RES_MIN, FILTER_RES_MAX);
|
||||
state->env1_attack = map_linear(input->pots[5], ENV_ATTACK_MIN, ENV_ATTACK_MAX);
|
||||
state->env1_release = map_linear(input->pots[6], ENV_RELEASE_MIN, ENV_RELEASE_MAX);
|
||||
state->env2_attack = map_linear(input->pots[7], ENV_ATTACK_MIN, ENV_ATTACK_MAX);
|
||||
state->env2_release = map_linear(input->pots[8], ENV_RELEASE_MIN, ENV_RELEASE_MAX);
|
||||
state->reverb_amount = map_linear(input->pots[9], REVERB_AMOUNT_MIN, REVERB_AMOUNT_MAX);
|
||||
state->vco_freq = map_exponential(input->pots[0], VCO_FREQ_MIN, VCO_FREQ_MAX);
|
||||
state->vco_volume = map_exponential(input->pots[1], VCO_VOLUME_MIN, VCO_VOLUME_MAX);
|
||||
state->filter_freq = map_exponential(input->pots[2], FILTER_FREQ_MIN, FILTER_FREQ_MAX);
|
||||
state->filter_resonance = map_linear(input->pots[3], FILTER_RES_MIN, FILTER_RES_MAX);
|
||||
state->clock_bpm = map_linear(input->pots[4], BPM_MIN, BPM_MAX);
|
||||
state->env1_attack = map_linear(input->pots[5], ENV_ATTACK_MIN, ENV_ATTACK_MAX);
|
||||
state->env1_decay = map_linear(input->pots[6], ENV_RELEASE_MIN, ENV_RELEASE_MAX);
|
||||
state->env2_attack = map_linear(input->pots[7], ENV_ATTACK_MIN, ENV_ATTACK_MAX);
|
||||
state->env2_decay = map_linear(input->pots[8], ENV_RELEASE_MIN, ENV_RELEASE_MAX);
|
||||
state->reverb_amount = map_linear(input->pots[9], REVERB_AMOUNT_MIN, REVERB_AMOUNT_MAX);
|
||||
|
||||
static bool pressed = false;
|
||||
if (!pressed && input->buttons[0]) {
|
||||
@@ -21,7 +28,18 @@ void update_state(state_t* state, input_t* input) {
|
||||
pressed = true;
|
||||
} else pressed = false;
|
||||
|
||||
state->quant_enabled = input->buttons[1];
|
||||
state->amen_enabled = input->buttons[2];
|
||||
|
||||
if (input->buttons[1]) {
|
||||
if (state->vco_freq <= 0.0f) state->vco_freq = 0.0f;
|
||||
else state->vco_freq = quantize(state->vco_freq);
|
||||
}
|
||||
|
||||
// state->amen_enabled = input->buttons[2];
|
||||
state->amen_enabled = true;
|
||||
|
||||
state->beat_samples = SAMPLE_RATE * 60.0f / state->clock_bpm;
|
||||
state->playback_rate = state->clock_bpm / AMEN_BPM;
|
||||
state->clock_inc = state->clock_bpm / 60.0f / SAMPLE_RATE;
|
||||
state->amen_inc_fp = (uint32_t)(state->playback_rate * 65536.0f);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user