From 90f6af6a04bc33001edfcc297fed68a0187a939e Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Mon, 18 May 2020 13:24:00 +0200 Subject: [PATCH] Pseudo-logarithmic volumes. --- MicroDexed.ino | 62 +++++++++++++++++++++++++++----------------------- UI.hpp | 18 +++++++-------- config.h | 4 ++-- 3 files changed, 44 insertions(+), 40 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 0c539b8..d43768a 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -425,8 +425,8 @@ void setup() master_mixer_r.gain(instance_id, 1.0); master_mixer_l.gain(instance_id, 1.0); } - master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100, true)); - master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100, true)); + master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100)); + master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100)); set_sys_params(); @@ -714,7 +714,7 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) #ifdef USE_FX MicroDexed[instance_id]->fx.Gain = mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX); #else - dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX), true)); + dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); #endif if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_sound_intensity)) { @@ -797,7 +797,7 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) } case 106: // CC 106: delay feedback configuration.fx.delay_feedback[instance_id] = map(inValue, 0, 0x7f, DELAY_FEEDBACK_MIN , DELAY_FEEDBACK_MAX); - delay_fb_mixer[instance_id]->gain(1, mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0)); // amount of feedback + delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0))); // amount of feedback if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_delay_feedback)) { LCDML.OTHER_updateFunc(); @@ -806,7 +806,7 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) break; case 107: // CC 107: delay volume configuration.fx.delay_level[instance_id] = map(inValue, 0, 0x7f, DELAY_SEND_MIN, DELAY_SEND_MAX); - delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0), true)); + delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0))); if (LCDML.FUNC_getID() == LCDML.OTHER_getIDFromFunction(UI_func_delay_level)) { LCDML.OTHER_updateFunc(); @@ -1364,8 +1364,8 @@ void set_volume(uint8_t v, uint8_t m) Serial.println(v, DEC); #endif - volume_r.gain(v / 100.0); - volume_l.gain(v / 100.0); + volume_r.gain(pseudo_log_curve(v / 100.0)); + volume_l.gain(pseudo_log_curve(v / 100.0)); switch (m) { @@ -1448,25 +1448,25 @@ void initial_values_from_eeprom(bool init) MicroDexed[instance_id]->setMonoMode(configuration.sys.mono); #if defined(USE_FX) - //chorus_mixer[instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); - //chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); + //chorus_mixer[instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); + //chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); //chorus_mixer[instance_id]->gain(0, 1.0 - mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); - chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5), true)); + chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5))); delay_mixer[instance_id]->gain(0, 1.0); - delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0), true)); + delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0))); delay_fb_mixer[instance_id]->gain(0, 1.0); - delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0), true)); + delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0))); // MicroDexed[instance_id]->fx.Gain = configuration.dexed[instance_id].sound_intensity / 100.0; MicroDexed[instance_id]->fx.Gain = 1.0; MicroDexed[instance_id]->fx.Reso = mapfloat(configuration.dexed[instance_id].filter_resonance, FILTER_RESONANCE_MIN, FILTER_RESONANCE_MAX, 1.0, 0.0); MicroDexed[instance_id]->fx.Cutoff = mapfloat(configuration.dexed[instance_id].filter_cutoff, FILTER_CUTOFF_MIN, FILTER_CUTOFF_MAX, 1.0, 0.0); - reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0, true)); - reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0, true)); + reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); + reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); #endif - dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX), true)); + dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); set_voiceconfig_params(instance_id); } @@ -1757,8 +1757,8 @@ void set_fx_params(void) for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++) { // CHORUS - //chorus_mixer[instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); - //chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); + //chorus_mixer[instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); + //chorus_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); //chorus_mixer[instance_id]->gain(0, 1.0 - mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); chorus_mixer[instance_id]->gain(1, mapfloat(configuration.fx.chorus_level[instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); switch (configuration.fx.chorus_waveform[instance_id]) @@ -1789,14 +1789,14 @@ void set_fx_params(void) // DELAY delay_mixer[instance_id]->gain(0, 1.0); - delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0), true)); + delay_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0))); delay_fx[instance_id]->delay(0, constrain(configuration.fx.delay_time[instance_id] * 10, DELAY_TIME_MIN * 10, DELAY_TIME_MAX * 10)); delay_fb_mixer[instance_id]->gain(0, 1.0); - delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0), true)); + delay_fb_mixer[instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_feedback[instance_id], DELAY_FEEDBACK_MIN, DELAY_FEEDBACK_MAX, 0.0, 1.0))); // REVERB - reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0, true)); - reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0, true)); + reverb_mixer_r.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); + reverb_mixer_l.gain(instance_id, pseudo_log_curve(configuration.fx.reverb_send[instance_id] / 100.0)); } // REVERB @@ -1804,8 +1804,8 @@ void set_fx_params(void) freeverb_r.damping(mapfloat(configuration.fx.reverb_damping, REVERB_DAMPING_MIN, REVERB_DAMPING_MAX, 0.0, 1.0)); freeverb_l.roomsize(mapfloat(configuration.fx.reverb_roomsize, REVERB_ROOMSIZE_MIN, REVERB_ROOMSIZE_MAX, 0.0, 1.0)); freeverb_l.damping(mapfloat(configuration.fx.reverb_damping, REVERB_DAMPING_MIN, REVERB_DAMPING_MAX, 0.0, 1.0)); - master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0, true)); - master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0, true)); + master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0)); + master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0)); #endif } @@ -1819,7 +1819,7 @@ void set_voiceconfig_params(uint8_t instance_id) MicroDexed[instance_id]->doRefreshVoice(); // Dexed output level - dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX), true)); + dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); // PANORAMA mono2stereo[instance_id]->panorama(mapfloat(configuration.dexed[instance_id].pan, PANORAMA_MIN, PANORAMA_MAX, -1.0, 1.0)); @@ -1843,14 +1843,18 @@ void _softRestart(void) SCB_AIRCR = 0x05FA0004; //write value for restart } -float pseudo_log_curve(float value, bool type) +float pseudo_log_curve(float value) { const float _pseudo_log = 1048575 / (float)(1 << 20); - if (type == true) - return (_pseudo_log * arm_sin_f32(value)); - else - return (_pseudo_log * arm_cos_f32(value)); +#ifdef DEBUG + Serial.print(F("value in: ")); + Serial.print(value, 3); + Serial.print(F(" value out: ")); + Serial.println(mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0), 3); +#endif + + return (mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0)); } uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc diff --git a/UI.hpp b/UI.hpp index 74d611b..4c38525 100644 --- a/UI.hpp +++ b/UI.hpp @@ -56,7 +56,7 @@ extern void eeprom_update_sys(void); extern void eeprom_update_performance(void); extern void eeprom_update_fx(void); extern void eeprom_update_dexed(uint8_t instance_id); -extern float pseudo_log_curve(float value, bool type); +extern float pseudo_log_curve(float value); extern uint8_t selected_instance_id; #ifdef DISPLAY_LCD_SPI @@ -992,8 +992,8 @@ void UI_func_reverb_level(uint8_t param) lcd_display_bar_int("Reverb Level", configuration.fx.reverb_level, 1.0, REVERB_LEVEL_MIN, REVERB_LEVEL_MAX, 3, false, false, true); - master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0, true)); - master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0, true)); + master_mixer_r.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0)); + master_mixer_l.gain(3, pseudo_log_curve(configuration.fx.reverb_level / 100.0)); } if (LCDML.FUNC_close()) // ****** STABLE END ********* @@ -1211,8 +1211,8 @@ void UI_func_chorus_level(uint8_t param) lcd_display_bar_int("Chorus Lvl.", configuration.fx.chorus_level[selected_instance_id], 1.0, CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 3, false, false, false); - //chorus_mixer[selected_instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); - //chorus_mixer[selected_instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0), true)); + //chorus_mixer[selected_instance_id]->gain(0, 1.0 - pseudo_log_curve(mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); + //chorus_mixer[selected_instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 1.0))); //chorus_mixer[selected_instance_id]->gain(0, 1.0 - mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); chorus_mixer[selected_instance_id]->gain(1, mapfloat(configuration.fx.chorus_level[selected_instance_id], CHORUS_LEVEL_MIN, CHORUS_LEVEL_MAX, 0.0, 0.5)); } @@ -1373,7 +1373,7 @@ void UI_func_delay_level(uint8_t param) lcd_display_bar_int("Delay Lvl.", configuration.fx.delay_level[selected_instance_id], 1.0, DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 3, false, false, false); - delay_mixer[selected_instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[selected_instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0), true)); + delay_mixer[selected_instance_id]->gain(1, pseudo_log_curve(mapfloat(configuration.fx.delay_level[selected_instance_id], DELAY_LEVEL_MIN, DELAY_LEVEL_MAX, 0.0, 1.0))); } if (LCDML.FUNC_close()) // ****** STABLE END ********* @@ -1426,8 +1426,8 @@ void UI_func_reverb_send(uint8_t param) lcd_display_bar_int("Reverb Send", configuration.fx.reverb_send[selected_instance_id], 1.0, REVERB_SEND_MIN, REVERB_SEND_MAX, 3, false, false, false); - reverb_mixer_r.gain(selected_instance_id, pseudo_log_curve(configuration.fx.reverb_send[selected_instance_id] / 100.0, true)); - reverb_mixer_l.gain(selected_instance_id, pseudo_log_curve(configuration.fx.reverb_send[selected_instance_id] / 100.0, true)); + reverb_mixer_r.gain(selected_instance_id, pseudo_log_curve(configuration.fx.reverb_send[selected_instance_id] / 100.0)); + reverb_mixer_l.gain(selected_instance_id, pseudo_log_curve(configuration.fx.reverb_send[selected_instance_id] / 100.0)); } if (LCDML.FUNC_close()) // ****** STABLE END ********* @@ -1879,7 +1879,7 @@ void UI_func_sound_intensity(uint8_t param) } lcd_display_bar_int("Voice Level", configuration.dexed[selected_instance_id].sound_intensity, 1.0, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 3, false, false, false); - dexed_level[selected_instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[selected_instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX), true)); + dexed_level[selected_instance_id]->gain(pseudo_log_curve(mapfloat(configuration.dexed[selected_instance_id].sound_intensity, SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); } if (LCDML.FUNC_close()) // ****** STABLE END ********* diff --git a/config.h b/config.h index 8e8f338..50c4280 100644 --- a/config.h +++ b/config.h @@ -47,7 +47,7 @@ // amidi -p hw:2,0,0 -d -r /tmp/bkup1.syx // -#define VERSION "0.9.9g" +#define VERSION "0.9.9h" //************************************************************************************************* //* DEVICE SETTINGS @@ -84,7 +84,7 @@ //************************************************************************************************* //* DEBUG OUTPUT SETTINGS //************************************************************************************************* -//#define DEBUG 1 +#define DEBUG 1 #define SERIAL_SPEED 230400 #define SHOW_XRUN 1 #define SHOW_CPU_LOAD_MSEC 5000