Trying to fix interpolation problems...

master
Holger Wirtz 6 years ago
parent a48f996232
commit 369b135c8f
  1. 57
      MicroMDAEPiano.ino
  2. 4
      UI.hpp
  3. 4
      config.h
  4. 64
      effect_modulated_chorus.cpp

@ -130,7 +130,7 @@ config_t configuration = {
ENC_REVERB_LEVEL_DEFAULT, // reverb_level ENC_REVERB_LEVEL_DEFAULT, // reverb_level
ENC_CHORUS_FREQUENCY_DEFAULT, // chorus_frequency ENC_CHORUS_FREQUENCY_DEFAULT, // chorus_frequency
ENC_CHORUS_DELAY_DEFAULT, // chorus_delay ENC_CHORUS_DELAY_DEFAULT, // chorus_delay
ENC_CHORUS_INTENSITY_DEFAULT, // chorus_intensity ENC_CHORUS_INTENSITY_DEFAULT, // chorus_intensity
ENC_CHORUS_LEVEL_DEFAULT, // chorus_level ENC_CHORUS_LEVEL_DEFAULT, // chorus_level
ENC_BASS_LR_LEVEL_DEFAULT, // bass_lr_level ENC_BASS_LR_LEVEL_DEFAULT, // bass_lr_level
ENC_BASS_MONO_LEVEL_DEFAULT, // bass_mono_level ENC_BASS_MONO_LEVEL_DEFAULT, // bass_mono_level
@ -140,7 +140,7 @@ config_t configuration = {
ENC_MIDI_CHANNEL_DEFAULT, // midi_channel ENC_MIDI_CHANNEL_DEFAULT, // midi_channel
ENC_MIDI_SOFT_THRU_DEFAULT, // midi_soft_thru ENC_MIDI_SOFT_THRU_DEFAULT, // midi_soft_thru
ENC_MAX_POLY_DEFAULT, // max_poly ENC_MAX_POLY_DEFAULT, // max_poly
0 // pan ENC_MASTER_PAN_DEFAULT // pan
}; };
uint8_t master_volume = ENC_MASTER_VOLUME_DEFAULT; uint8_t master_volume = ENC_MASTER_VOLUME_DEFAULT;
@ -183,7 +183,7 @@ void setup()
// create EPiano object // create EPiano object
ep = new mdaEPiano(); ep = new mdaEPiano();
set_complete_configuration(); //set_complete_configuration();
initial_values_from_eeprom(); initial_values_from_eeprom();
setup_midi_devices(); setup_midi_devices();
@ -543,57 +543,24 @@ void config_from_eeprom(void)
if (checksum == tmp_conf.checksum) if (checksum == tmp_conf.checksum)
{ {
EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), configuration); EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), configuration);
Serial.print(F(" - OK, loading config ")); Serial.print(F(" - OK -> loading sound."));
Serial.print(sound, DEC); Serial.print(sound, DEC);
} }
else else
#ifdef DEBUG
{ {
Serial.println(F(" - mismatch (or force) -> nothing done!")); #ifdef DEBUG
Serial.println(F(" - mismatch -> loading initial configuration."));
#endif
set_complete_configuration();
} }
show_sound(); show_sound();
#endif
} }
void initial_values_from_eeprom(void) void initial_values_from_eeprom(void)
{ {
uint32_t checksum; master_volume = EEPROM.read(EEPROM_MASTER_VOLUME);
config_t tmp_conf; sound = EEPROM.read(EEPROM_SOUND);
load_sound();
EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), tmp_conf);
checksum = crc32((byte*)&tmp_conf + 4, sizeof(tmp_conf) - 4);
#ifdef DEBUG
Serial.print(F("EEPROM checksum: 0x"));
Serial.print(tmp_conf.checksum, HEX);
Serial.print(F(" / 0x"));
Serial.print(checksum, HEX);
#endif
if (checksum != tmp_conf.checksum || (but[0].read() == LOW && but[1].read() == LOW))
{
#ifdef DEBUG
Serial.println(F(" - mismatch (or force) -> initializing EEPROM!"));
#endif
eeprom_config_update_flag = sound;
eeprom_config_update();
}
else
{
sound = EEPROM.read(EEPROM_SOUND);
master_volume = EEPROM.read(EEPROM_MASTER_VOLUME);
EEPROM_readAnything(EEPROM_CONFIGURATIONS + sizeof(config_t) * (sound - 1), configuration);
Serial.print(F(" - OK, loading"));
}
#ifdef DEBUG
Serial.print(F(" - Master volume: "));
Serial.print(master_volume, DEC);
Serial.print(F(" - Sound: "));
Serial.println(sound, DEC);
Serial.print(F("Max configs in EEPROM: "));
Serial.println(MAX_SOUNDS);
show_sound();
#endif
} }
void eeprom_config_write(uint8_t value) void eeprom_config_write(uint8_t value)
@ -726,7 +693,7 @@ void show_sound(void)
Serial.println(configuration.reverb_damping, DEC); Serial.println(configuration.reverb_damping, DEC);
Serial.print(F("Reverb Level: ")); Serial.print(F("Reverb Level: "));
Serial.println(configuration.reverb_level, DEC); Serial.println(configuration.reverb_level, DEC);
Serial.print(F("CHorus Frequency: ")); Serial.print(F("Chorus Frequency: "));
Serial.println(configuration.chorus_frequency, DEC); Serial.println(configuration.chorus_frequency, DEC);
Serial.print(F("Chorus Delay: ")); Serial.print(F("Chorus Delay: "));
Serial.println(configuration.chorus_delay, DEC); Serial.println(configuration.chorus_delay, DEC);

@ -36,7 +36,7 @@
const uint8_t MAX_SCREENS = 14; ///< @note Default: 14 const uint8_t MAX_SCREENS = 14; ///< @note Default: 14
/// Configures the number of available menus per menus system. /// Configures the number of available menus per menus system.
const uint8_t MAX_MENUS = 43; ///< @note Default: 8 const uint8_t MAX_MENUS = 44; ///< @note Default: 8
*/ */
@ -55,7 +55,7 @@ int32_t encoder_value[NUM_ENCODER];
Bounce but[NUM_ENCODER] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)}; Bounce but[NUM_ENCODER] = {Bounce(BUT_L_PIN, BUT_DEBOUNCE_MS), Bounce(BUT_R_PIN, BUT_DEBOUNCE_MS)};
elapsedMillis back_to_main; elapsedMillis back_to_main;
#define NUM_MENUS 41 #define NUM_MENUS 42
#define MAIN 0 #define MAIN 0
/*************************************/ /*************************************/

@ -62,8 +62,8 @@
#define USE_XFADE_DATA 1 #define USE_XFADE_DATA 1
// CHORUS parameters // CHORUS parameters
#define INTERPOLATION_WINDOW_SIZE 7 // For chorus, only odd numbers,please! #define INTERPOLATION_WINDOW_SIZE 7 // For chorus, only odd numbers,please!
#define INTERPOLATE CUBIC // LINEAR COSINE LAGRANGE QUADRATIC #define INTERPOLATE QUADRATIC // LINEAR COSINE QUADRATIC CUBIC LAGRANGE
#define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINEWAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE WAVEFORM_SQUARE WAVEFORM_TRIANGLE #define CHORUS_WAVEFORM WAVEFORM_TRIANGLE // WAVEFORM_SINE WAVEFORM_SAWTOOTH WAVEFORM_SAWTOOTH_REVERSE WAVEFORM_SQUARE WAVEFORM_TRIANGLE
#define CHORUS_DELAY_LENGTH (16*AUDIO_BLOCK_SAMPLES) #define CHORUS_DELAY_LENGTH (16*AUDIO_BLOCK_SAMPLES)
//************************************************************************************************* //*************************************************************************************************

@ -70,6 +70,11 @@ void AudioModulatedEffectChorus::update(void)
short *mp; short *mp;
float mod_idx; float mod_idx;
#ifdef INTERPOLATE
interpolation* modulation_interpolate;
modulation_interpolate = new interpolation;
#endif
if (l_delayline == NULL) if (l_delayline == NULL)
return; return;
@ -81,8 +86,11 @@ void AudioModulatedEffectChorus::update(void)
#ifdef INTERPOLATE #ifdef INTERPOLATE
uint8_t j; uint8_t j;
int16_t interpolation_idx; int16_t interpolation_idx;
interpolation modulation_interpolate; float x[INTERPOLATION_WINDOW_SIZE];
modulation_interpolate.valuelenXY(INTERPOLATION_WINDOW_SIZE); float y[INTERPOLATION_WINDOW_SIZE];
modulation_interpolate->valuelenXY(INTERPOLATION_WINDOW_SIZE);
modulation_interpolate->valueX(x);
modulation_interpolate->valueY(y);
#endif #endif
bp = block->data; bp = block->data;
@ -90,11 +98,6 @@ void AudioModulatedEffectChorus::update(void)
for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++) for (int i = 0; i < AUDIO_BLOCK_SAMPLES; i++)
{ {
#ifdef INTERPOLATE
float x[INTERPOLATION_WINDOW_SIZE];
float y[INTERPOLATION_WINDOW_SIZE];
#endif
// write data into circular buffer // write data into circular buffer
if (l_circ_idx >= delay_length) if (l_circ_idx >= delay_length)
l_circ_idx = 0; l_circ_idx = 0;
@ -102,45 +105,43 @@ void AudioModulatedEffectChorus::update(void)
// calculate modulation index // calculate modulation index
mod_idx = float(*mp) / SHRT_MAX * delay_length_half + l_circ_idx; // calculate index with modulation as a float mod_idx = float(*mp) / SHRT_MAX * delay_length_half + l_circ_idx; // calculate index with modulation as a float
if (mod_idx > delay_length) if (mod_idx > float(delay_length - 1))
mod_idx = mod_idx - delay_length; mod_idx = mod_idx - float(delay_length - 1);
else if (mod_idx < 0) else if (mod_idx < 0.0)
mod_idx = delay_length + mod_idx; mod_idx = float(delay_length - 1) + mod_idx;
#ifdef INTERPOLATE #ifdef INTERPOLATE
// get value with interpolation // get value with interpolation
for (j = 0; j < INTERPOLATION_WINDOW_SIZE; j++) interpolation_idx = int(mod_idx + 0.5) + (INTERPOLATION_WINDOW_SIZE / -2);
for (j = interpolation_idx; j < INTERPOLATION_WINDOW_SIZE; j++)
{ {
interpolation_idx = mod_idx + (INTERPOLATION_WINDOW_SIZE / -2) + j;
if (interpolation_idx > delay_length)
interpolation_idx = interpolation_idx - delay_length;
else if (interpolation_idx < 0)
interpolation_idx = delay_length + interpolation_idx;
x[j] = interpolation_idx; x[j] = interpolation_idx;
y[j] = l_delayline[interpolation_idx];
if (j >= delay_length)
y[j] = l_delayline[j - delay_length];
else if (j < 0)
y[j] = l_delayline[delay_length + j];
} }
modulation_interpolate.valueX(x);
modulation_interpolate.valueY(y); modulation_interpolate->valueI(mod_idx);
modulation_interpolate.valueI(mod_idx);
#if INTERPOLATE == CUBIC #if INTERPOLATE == CUBIC
*bp = int(modulation_interpolate.CubicInterpolate() + 0.5); *bp = int(modulation_interpolate->CubicInterpolate() + 0.5);
#elif INTERPOLATE == LINEAR #elif INTERPOLATE == LINEAR
*bp = int(modulation_interpolate.LinearInterpolate() + 0.5); *bp = int(modulation_interpolate->LinearInterpolate() + 0.5);
#elif INTERPOLATE == COSINE #elif INTERPOLATE == COSINE
*bp = int(modulation_interpolate.CosineInterpolate() + 0.5); *bp = int(modulation_interpolate->CosineInterpolate() + 0.5);
#elif INTERPOLATE == LAGRANGE #elif INTERPOLATE == LAGRANGE
*bp = int(modulation_interpolate.LagrangeInterpolate() + 0.5); *bp = int(modulation_interpolate->LagrangeInterpolate() + 0.5);
#elif INTERPOLATE == QUDRATIC #elif INTERPOLATE == QUDRATIC
*bp = int(modulation_interpolate.QuadraticInterpolate() + 0.5); *bp = int(modulation_interpolate->QuadraticInterpolate() + 0.5);
#else #else
// No interpolation - should sound really bad... // No interpolation - should sound really bad...
*bp = int(mod_idx + 0.5); *bp = l_delayline[int(mod_idx + 0.5)];
#endif #endif
#else #else
// No interpolation - should sound really bad... // No interpolation - should sound really bad...
*bp = int(mod_idx + 0.5); *bp = l_delayline[int(mod_idx + 0.5)];
#endif #endif
bp++; bp++;
@ -153,4 +154,9 @@ void AudioModulatedEffectChorus::update(void)
release(block); release(block);
release(modulation); release(modulation);
} }
#ifdef INTERPOLATION
if (modulation_interpolate)
delete(modulation_interpolate);
#endif
} }

Loading…
Cancel
Save