mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Fix onepole filter bug in processor resulting in wrong CV values
This commit is contained in:
parent
76175accf3
commit
0de4e549d5
2 changed files with 17 additions and 19 deletions
|
@ -13,8 +13,8 @@ void Processor::Process(int16_t cvs[], uint16_t* outs)
|
||||||
uint32_t value_r;
|
uint32_t value_r;
|
||||||
|
|
||||||
// dirty low pass
|
// dirty low pass
|
||||||
this->cv_input_pan = ((cvs[0] - this->cv_input_pan) >> 3);
|
this->cv_input_pan += ((cvs[0] - this->cv_input_pan) >> 4);
|
||||||
this->cv_input_vol = ((cvs[1] - this->cv_input_vol) >> 3);
|
this->cv_input_vol += ((cvs[1] - this->cv_input_vol) >> 5);
|
||||||
|
|
||||||
uint16_t pan_pot = (pan_offset + 32767L);
|
uint16_t pan_pot = (pan_offset + 32767L);
|
||||||
uint16_t vol_pot = (vol_offset);
|
uint16_t vol_pot = (vol_offset);
|
||||||
|
@ -35,7 +35,7 @@ void Processor::Process(int16_t cvs[], uint16_t* outs)
|
||||||
uint16_t vol_cv_absu16 = abs(vol_cv) << 1;
|
uint16_t vol_cv_absu16 = abs(vol_cv) << 1;
|
||||||
uint16_t vol_cv_exp = Interpolate124(lut_linear_to_exp, vol_cv_absu16);
|
uint16_t vol_cv_exp = Interpolate124(lut_linear_to_exp, vol_cv_absu16);
|
||||||
uint16_t vol_cv_log = 65535 - InverseInterpolate124(lut_linear_to_exp, vol_cv_absu16);
|
uint16_t vol_cv_log = 65535 - InverseInterpolate124(lut_linear_to_exp, vol_cv_absu16);
|
||||||
uint32_t vol_cv_pre = (Mix(static_cast<uint16_t>(vol_cv_exp >> 1), vol_cv_log >> 1, log_exp_mix_cv) << 3) * 3;
|
uint32_t vol_cv_pre = (Mix(static_cast<uint16_t>(vol_cv_exp >> 1), vol_cv_log >> 1, log_exp_mix_cv) << 1) * 2;
|
||||||
vol += vol_cv > 0 ? vol_cv_pre : -vol_cv_pre;
|
vol += vol_cv > 0 ? vol_cv_pre : -vol_cv_pre;
|
||||||
vol *= !mute;
|
vol *= !mute;
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ void Processor::Process(int16_t cvs[], uint16_t* outs)
|
||||||
|
|
||||||
this->previous_vol = vol;
|
this->previous_vol = vol;
|
||||||
|
|
||||||
int32_t pan_cv = (cv_input_pan * static_cast<int32_t>(pan_att)) >> 15; // full attenuate gives 3x amplification :)
|
int32_t pan_cv = (cv_input_pan * static_cast<int32_t>(pan_att)) >> 15; // full attenuate gives 2x amplification :)
|
||||||
pan_cv = Clip16(pan_cv);
|
pan_cv = Clip16(pan_cv);
|
||||||
int32_t pan = pan_pot + ((pan_cv << 3) * 4);
|
int32_t pan = pan_pot + ((pan_cv) * 2);
|
||||||
pan = ClipU16(pan);
|
pan = ClipU16(pan);
|
||||||
|
|
||||||
value_l = (lut_left_sin_pan[pan >> 4] * vol) >> 16;
|
value_l = (lut_left_sin_pan[pan >> 4] * vol) >> 16;
|
||||||
|
|
|
@ -110,11 +110,11 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
|
||||||
{
|
{
|
||||||
if (htim == &htim3) {
|
if (htim == &htim3) {
|
||||||
leds.Write();
|
leds.Write(); // 53571 Hz
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (htim == &htim6) {
|
if (htim == &htim6) {
|
||||||
WriteOutputs();
|
WriteOutputs(); // 4076 Hz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ void Init(void)
|
||||||
|
|
||||||
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
|
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
|
||||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||||
htim3.Init.Prescaler = 10;
|
htim3.Init.Prescaler = 8;
|
||||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim3.Init.Period = 128;
|
htim3.Init.Period = 128;
|
||||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
@ -143,9 +143,9 @@ void Init(void)
|
||||||
|
|
||||||
HAL_NVIC_SetPriority(TIM6_IRQn, 1, 0);
|
HAL_NVIC_SetPriority(TIM6_IRQn, 1, 0);
|
||||||
HAL_NVIC_EnableIRQ(TIM6_IRQn);
|
HAL_NVIC_EnableIRQ(TIM6_IRQn);
|
||||||
htim6.Init.Prescaler = 64;
|
htim6.Init.Prescaler = 47;
|
||||||
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
htim6.Init.Period = 96; // 512 without optimize
|
htim6.Init.Period = 256; // 96 without optimize
|
||||||
htim6.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim6.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim6.Init.RepetitionCounter = 0;
|
htim6.Init.RepetitionCounter = 0;
|
||||||
HAL_TIM_Base_Init(&htim6);
|
HAL_TIM_Base_Init(&htim6);
|
||||||
|
@ -154,23 +154,20 @@ void Init(void)
|
||||||
system_clock.Init();
|
system_clock.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t out[kNumChannels][2];
|
||||||
|
|
||||||
void WriteOutputs(void)
|
void WriteOutputs(void)
|
||||||
{
|
{
|
||||||
uint16_t out[kNumChannels][2];
|
for (int i = 0; i < kNumChannels; i++) {
|
||||||
DEBUG_ON
|
dacs.Write16(i, 0, out[i][0]);
|
||||||
|
dacs.Write16(i, 1, out[i][1]);
|
||||||
|
}
|
||||||
for (int i = 0; i < kNumChannels; i++) {
|
for (int i = 0; i < kNumChannels; i++) {
|
||||||
int16_t cvs[2];
|
int16_t cvs[2];
|
||||||
cvs[0] = 65535 - adc.cv_value(AdcChannel(ADC_CHANNEL_PAN_1 + i));
|
cvs[0] = 65535 - adc.cv_value(AdcChannel(ADC_CHANNEL_PAN_1 + i));
|
||||||
cvs[1] = adc.cv_value(AdcChannel(ADC_CHANNEL_VOL_1 + i));
|
cvs[1] = adc.cv_value(AdcChannel(ADC_CHANNEL_VOL_1 + i));
|
||||||
processors[i].Process(cvs, out[i]);
|
processors[i].Process(cvs, out[i]);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < kNumChannels; i++) {
|
|
||||||
dacs.Write16(i, 0, out[i][0]);
|
|
||||||
//dacs.Write16(0, out[i][0]);
|
|
||||||
dacs.Write16(i, 1, out[i][1]);
|
|
||||||
//dacs[i + 4].Write16(1, out[i][1]);
|
|
||||||
}
|
|
||||||
DEBUG_OFF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -179,6 +176,7 @@ int main(void)
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
|
ui.Init();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ui.DoEvents();
|
ui.DoEvents();
|
||||||
|
|
Loading…
Reference in a new issue