Fix overrun bug, implement proper equal power panning

This commit is contained in:
Jan-Henrik 2020-04-28 22:51:36 +02:00
parent 48c256a2ef
commit 24bd791984
4 changed files with 2074 additions and 2061 deletions

View file

@ -32,7 +32,7 @@ FAMILY = f0xx
#APPLICATION = true
#BOOTLOADER = midi2cv_bootloader
OPTIMIZE = TRUE
OPTIMIZE_FLAG = 1
OPTIMIZE_FLAG = 2
# Preferred upload command
UPLOAD_COMMAND = upload_jtag

View file

@ -18,6 +18,8 @@ void Processor::Process(int16_t cvs[], uint16_t* outs)
int16_t pan_cv = cvs[0] >> (16 - 12);
int16_t vol_cv = cvs[1] >> (16 - 12);
int32_t pan = pan_pot + pan_cv;
// calculate value for ui
int32_t lin = volume_offset + (cvs[1] * 2);
CONSTRAIN(lin, 0, 65535);
lin *= !mute;
@ -27,18 +29,18 @@ void Processor::Process(int16_t cvs[], uint16_t* outs)
uint16_t vol_pot_log = 65535 - lut_linear_to_exp[LUT_LINEAR_TO_EXP_SIZE - 1 - vol_pot];
vol_pot = Mix(vol_pot_exp, vol_pot_log, log_exp_mix_pot);
vol_pot = vol_pot_exp;
int32_t vol = vol_pot;
uint16_t vol_cv_absu16 = abs(vol_cv) << 1;
uint16_t vol_cv_absu16 = abs(vol_cv);
uint16_t vol_cv_exp = lut_linear_to_exp[vol_cv_absu16];
uint16_t vol_cv_log = 65535 - lut_linear_to_exp[LUT_LINEAR_TO_EXP_SIZE - 1 - vol_cv_absu16];
uint16_t vol_cv_pre = Mix(vol_cv_exp, vol_cv_log, log_exp_mix_cv);
int32_t vol = vol_pot;
vol += vol_cv > 0 ? vol_cv_pre : -vol_cv_pre;
vol *= !mute;
CONSTRAIN(pan, 0, (1 << 16) - 1);
CONSTRAIN(vol, 0, (1 << 16) - 1);
CONSTRAIN(pan, 0, 4095);
CONSTRAIN(vol, 0, 65535);
previous_vol = vol;

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,7 @@ space = np.linspace(0, 1, num=ADC_RESOLUTION)
values = np.power(space, 2) * OUTPUT_RESOLUTION
lookup_tables_u16.append(('linear_to_exp', values))
print(values.size)
fig, ax = plt.subplots()
ax.plot(space, values)
@ -24,22 +25,32 @@ ax.plot(space, values / 2 + other_values / 2)
ax.set(xlabel='space', ylabel='values')
ax.grid()
#plt.show()
# plt.show()
# Left pan Lookup table
l_pan = np.linspace(0, 1, num=ADC_RESOLUTION)
r_pan = np.linspace(0, 1, num=ADC_RESOLUTION)
space = np.linspace(0, (np.pi / 2.0), num=ADC_RESOLUTION)
l_pan = np.sin(l_pan * (np.pi / 2.0))
r_pan = np.cos(r_pan * (np.pi / 2.0))
l_pan = np.sqrt(space * (2.0 / np.pi) * np.sin(space))
r_pan = np.sqrt(((np.pi / 2.0) - space) * (2.0 / np.pi) * np.cos(space))
l_pan = np.round(l_pan * OUTPUT_RESOLUTION)
r_pan = np.round(r_pan * OUTPUT_RESOLUTION)
l_pan = np.floor(l_pan * OUTPUT_RESOLUTION)
r_pan = np.floor(r_pan * OUTPUT_RESOLUTION)
fig, ax = plt.subplots()
ax.plot(space, l_pan)
ax.plot(space, r_pan)
ax.set(xlabel='space', ylabel='values')
ax.grid()
#plt.show()
lookup_tables_u16.append(('left_sin_pan', l_pan))
print(l_pan.size)
lookup_tables_u16.append(('right_cos_pan', r_pan))
print(r_pan.size)
# led gamma correction
gamma = 2.4