Fixing volume setting and a bug in UI for volume.

pull/7/head^2
Holger Wirtz 5 years ago
parent 69cdb158fd
commit df1ae1e1f8
  1. 22
      MicroDexed.ino
  2. 19
      SoftenValue.hpp
  3. 10
      UI.hpp

@ -363,8 +363,8 @@ void setup()
for (uint8_t i = 0; i < NUM_DEXED; i++) for (uint8_t i = 0; i < NUM_DEXED; i++)
{ {
soften_filter_res[i].init(1.0, 0.0, 1.0); soften_filter_res[i].init(1.0);
soften_filter_cut[i].init(1.0, 0.0, 1.0); soften_filter_cut[i].init(1.0);
MicroDexed[i]->fx.Gain = 1.0; MicroDexed[i]->fx.Gain = 1.0;
MicroDexed[i]->fx.Reso = 1.0; MicroDexed[i]->fx.Reso = 1.0;
MicroDexed[i]->fx.Cutoff = 1.0; MicroDexed[i]->fx.Cutoff = 1.0;
@ -372,7 +372,7 @@ void setup()
// set initial volume and pan (read from EEPROM) // set initial volume and pan (read from EEPROM)
set_volume(configuration.vol, configuration.pan, configuration.mono); set_volume(configuration.vol, configuration.pan, configuration.mono);
soften_volume.init(configuration.vol, VOLUME_MIN, VOLUME_MAX); soften_volume.init(configuration.vol);
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
// Initialize processor and memory measurements // Initialize processor and memory measurements
@ -997,11 +997,6 @@ void set_volume(uint8_t v, int8_t p, uint8_t m)
float tmp2 = mapfloat(configuration.pan, PANORAMA_MIN, PANORAMA_MAX, 0.0, 1.0); float tmp2 = mapfloat(configuration.pan, PANORAMA_MIN, PANORAMA_MAX, 0.0, 1.0);
float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20); float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20);
// float v = (float)(a * (a + 2))/(float)(1 << 20); // (pseudo-) logarithmic curve for volume control
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
volume_r.gain(tmp3 * sinf(tmp2 * PI / 2));
volume_l.gain(tmp3 * cosf(tmp2 * PI / 2));
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Setting volume: VOL=")); Serial.print(F("Setting volume: VOL="));
Serial.print(v, DEC); Serial.print(v, DEC);
@ -1017,26 +1012,25 @@ void set_volume(uint8_t v, int8_t p, uint8_t m)
Serial.println(tmp3 * cosf(tmp2 * PI / 2), 3); Serial.println(tmp3 * cosf(tmp2 * PI / 2), 3);
#endif #endif
// float v = (float)(a * (a + 2))/(float)(1 << 20); // (pseudo-) logarithmic curve for volume control
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
volume_r.gain(tmp3 * sinf(tmp2 * PI / 2));
volume_l.gain(tmp3 * cosf(tmp2 * PI / 2));
switch (m) switch (m)
{ {
case 0: case 0:
volume_r.gain(1.0);
volume_l.gain(1.0);
stereomono1.stereo(true); stereomono1.stereo(true);
break; break;
case 1: case 1:
volume_r.gain(1.0);
volume_l.gain(1.0);
stereomono1.stereo(false); stereomono1.stereo(false);
break; break;
case 2: case 2:
volume_r.gain(1.0);
volume_l.gain(0.0); volume_l.gain(0.0);
stereomono1.stereo(false); stereomono1.stereo(false);
break; break;
case 3: case 3:
volume_r.gain(0.0); volume_r.gain(0.0);
volume_l.gain(1.0);
stereomono1.stereo(false); stereomono1.stereo(false);
break; break;
} }

@ -30,14 +30,12 @@ template <class T>
class SoftenValue class SoftenValue
{ {
public: public:
void init(T value, T minimum, T maximum) void init(T value)
{ {
_from = value; _from = value;
_to = value; _to = value;
_steps = 0; _steps = 0;
_diff = 0.0; _diff = 0.0;
_min = minimum;
_max = maximum;
} }
void update(T to, uint16_t steps) void update(T to, uint16_t steps)
@ -97,10 +95,15 @@ class SoftenValue
if (_steps == 0) if (_steps == 0)
return (_to); return (_to);
if (_from < _min) if (_diff < 0.0)
_from = _min; {
else if (_from > _max) if (_from < _to)
_from = _max; _from = _to;
}
else
{ if (_from > _to)
_from = _to;
}
if (std::is_same<T, float>::value) if (std::is_same<T, float>::value)
return (_from); return (_from);
@ -113,8 +116,6 @@ class SoftenValue
float _to; float _to;
uint16_t _steps; uint16_t _steps;
float _diff; float _diff;
T _min;
T _max;
void _calculate(void) void _calculate(void)
{ {

@ -563,7 +563,7 @@ void encoder_left_up(void)
if (configuration.vol < VOLUME_MAX) if (configuration.vol < VOLUME_MAX)
soften_volume.update(soften_volume.value() + (VOLUME_MAX - VOLUME_MIN) / VOLUME_ENC_STEPS, SOFTEN_VALUE_CHANGE_STEPS); soften_volume.update(soften_volume.value() + (VOLUME_MAX - VOLUME_MIN) / VOLUME_ENC_STEPS, SOFTEN_VALUE_CHANGE_STEPS);
else else
soften_volume.update(VOLUME_MAX, SOFTEN_VALUE_CHANGE_STEPS); configuration.vol = VOLUME_MAX;
eeprom_write(); eeprom_write();
UI_func_volume(0); UI_func_volume(0);
} }
@ -573,10 +573,11 @@ void encoder_left_down(void)
#ifdef DEBUG #ifdef DEBUG
Serial.println(F("Volume -")); Serial.println(F("Volume -"));
#endif #endif
if (configuration.vol > VOLUME_MIN) int8_t tmp = soften_volume.value() - (VOLUME_MAX - VOLUME_MIN) / VOLUME_ENC_STEPS;
soften_volume.update(soften_volume.value() - (VOLUME_MAX - VOLUME_MIN) / VOLUME_ENC_STEPS, SOFTEN_VALUE_CHANGE_STEPS); if (tmp > VOLUME_MIN)
soften_volume.update(tmp, SOFTEN_VALUE_CHANGE_STEPS);
else else
soften_volume.update(VOLUME_MIN, SOFTEN_VALUE_CHANGE_STEPS); configuration.vol = VOLUME_MIN;
eeprom_write(); eeprom_write();
UI_func_volume(0); UI_func_volume(0);
} }
@ -1713,6 +1714,7 @@ void UI_func_volume(uint8_t param)
else else
lcd.print(F(" ")); lcd.print(F(" "));
} }
set_volume(configuration.vol, configuration.pan, configuration.mono);
lcd.show(1, 0, 1, "["); lcd.show(1, 0, 1, "[");
lcd.show(1, 15, 1, "]"); lcd.show(1, 15, 1, "]");
} }

Loading…
Cancel
Save