Trying to fix interpolation problems...

master
Holger Wirtz 5 years ago
parent a48f996232
commit 369b135c8f
  1. 61
      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_CHORUS_FREQUENCY_DEFAULT, // chorus_frequency
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_BASS_LR_LEVEL_DEFAULT, // bass_lr_level
ENC_BASS_MONO_LEVEL_DEFAULT, // bass_mono_level
@ -140,7 +140,7 @@ config_t configuration = {
ENC_MIDI_CHANNEL_DEFAULT, // midi_channel
ENC_MIDI_SOFT_THRU_DEFAULT, // midi_soft_thru
ENC_MAX_POLY_DEFAULT, // max_poly
0 // pan
ENC_MASTER_PAN_DEFAULT // pan
};
uint8_t master_volume = ENC_MASTER_VOLUME_DEFAULT;
@ -183,7 +183,7 @@ void setup()
// create EPiano object
ep = new mdaEPiano();
set_complete_configuration();
//set_complete_configuration();
initial_values_from_eeprom();
setup_midi_devices();
@ -215,11 +215,11 @@ void setup()
// set master volume
set_master_volume(master_volume);
// internal mixing of original signal(0), reverb(1) and chorus(2)
mixer_r.gain(0, 1.0);
mixer_l.gain(0, 1.0);
#if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
// Initialize processor and memory measurements
AudioProcessorUsageMaxReset();
@ -543,57 +543,24 @@ void config_from_eeprom(void)
if (checksum == tmp_conf.checksum)
{
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);
}
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();
#endif
}
void initial_values_from_eeprom(void)
{
uint32_t checksum;
config_t tmp_conf;
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
master_volume = EEPROM.read(EEPROM_MASTER_VOLUME);
sound = EEPROM.read(EEPROM_SOUND);
load_sound();
}
void eeprom_config_write(uint8_t value)
@ -726,7 +693,7 @@ void show_sound(void)
Serial.println(configuration.reverb_damping, DEC);
Serial.print(F("Reverb Level: "));
Serial.println(configuration.reverb_level, DEC);
Serial.print(F("CHorus Frequency: "));
Serial.print(F("Chorus Frequency: "));
Serial.println(configuration.chorus_frequency, DEC);
Serial.print(F("Chorus Delay: "));
Serial.println(configuration.chorus_delay, DEC);

@ -36,7 +36,7 @@
const uint8_t MAX_SCREENS = 14; ///< @note Default: 14
/// 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)};
elapsedMillis back_to_main;
#define NUM_MENUS 41
#define NUM_MENUS 42
#define MAIN 0
/*************************************/

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

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

Loading…
Cancel
Save