Fixing volume and distortion problems with buggy AudioAmplifier.

pull/32/head
Holger Wirtz 5 years ago
parent cc6c78896e
commit cd750c4b37
  1. 42
      MicroDexed.ino
  2. 24
      PluginFx.cpp
  3. 3
      UI.hpp
  4. 4
      config.h
  5. 4
      dexed.cpp

@ -36,15 +36,12 @@
#include "effect_modulated_delay.h"
#include "effect_stereo_mono.h"
#include "effect_mono_stereo.h"
#include "effect_dynamics.h"
#include "PluginFx.h"
#include "UI.hpp"
#include "source_microdexed.h"
// Audio engines
AudioSourceMicroDexed* MicroDexed[NUM_DEXED];
AudioEffectDynamics* dexed_dynamic[NUM_DEXED];
AudioAmplifier* dexed_level[NUM_DEXED];
#if defined(USE_FX)
AudioSynthWaveform* chorus_modulator[NUM_DEXED];
#if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT
@ -138,17 +135,15 @@ AudioConnection patchCord13(stereo2mono, 1, dacOut, 1);
//
uint16_t nDynamic = 0;
#if defined(USE_FX) && MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT
AudioConnection * dynamicConnections[NUM_DEXED * 18];
AudioConnection * dynamicConnections[NUM_DEXED * 14];
#elif defined(USE_FX) && MOD_FILTER_OUTPUT == MOD_NO_FILTER_OUTPUT
AudioConnection * dynamicConnections[NUM_DEXED * 17];
AudioConnection * dynamicConnections[NUM_DEXED * 13];
#else
AudioConnection * dynamicConnections[NUM_DEXED * 6];
AudioConnection * dynamicConnections[NUM_DEXED * 4];
#endif
void create_audio_engine_chain(uint8_t instance_id)
{
MicroDexed[instance_id] = new AudioSourceMicroDexed(SAMPLE_RATE);
dexed_dynamic[instance_id] = new AudioEffectDynamics();
dexed_level[instance_id] = new AudioAmplifier();
mono2stereo[instance_id] = new AudioEffectMonoStereo();
#if defined(USE_FX)
chorus_modulator[instance_id] = new AudioSynthWaveform();
@ -163,11 +158,9 @@ void create_audio_engine_chain(uint8_t instance_id)
#endif
dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, microdexed_peak_mixer, instance_id);
dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *dexed_dynamic[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*dexed_dynamic[instance_id], 0, *dexed_level[instance_id], 0);
#if defined(USE_FX)
dynamicConnections[nDynamic++] = new AudioConnection(*dexed_level[instance_id], 0, *chorus_mixer[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*dexed_level[instance_id], 0, *modchorus[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *chorus_mixer[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*MicroDexed[instance_id], 0, *modchorus[instance_id], 0);
#if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT
dynamicConnections[nDynamic++] = new AudioConnection(*chorus_modulator[instance_id], 0, *modchorus_filter[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*modchorus_filter[instance_id], 0, *modchorus[instance_id], 1);
@ -184,7 +177,7 @@ void create_audio_engine_chain(uint8_t instance_id)
dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, reverb_mixer_r, instance_id);
dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, reverb_mixer_l, instance_id);
#else
dynamicConnections[nDynamic++] = new AudioConnection(*dexed_level[instance_id], 0, *mono2stereo[instance_id], 0);
dynamicConnections[nDynamic++] = new AudioConnection(*MicoDexed[instance_id], 0, *mono2stereo[instance_id], 0);
#endif
dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 0, master_mixer_r, instance_id);
dynamicConnections[nDynamic++] = new AudioConnection(*mono2stereo[instance_id], 1, master_mixer_l, instance_id);
@ -450,22 +443,11 @@ void setup()
show_cpu_and_mem_usage();
#endif
for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++)
{
MicroDexed[instance_id]->fx.Gain = 1.0;
// init dynamics for dexed
dexed_dynamic[instance_id]->limit();
//dexed_dynamic[instance_id]->autoMakeupGain();
//dexed_dynamic[instance_id]->compression();
}
// init master_mixer
#if NUM_DEXED > 1
for (uint8_t instance_id = 0; instance_id < NUM_DEXED; instance_id++)
{
//master_mixer_r.gain(instance_id, pseudo_log_curve(0.5));
//master_mixer_l.gain(instance_id, pseudo_log_curve(0.5));
master_mixer_r.gain(instance_id, 1.0);
master_mixer_l.gain(instance_id, 1.0);
}
@ -709,9 +691,8 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue)
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(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); // That's not right... have to fix this!
dexed_level[instance_id]->gain(mapfloat(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX));
//dexed_level[instance_id]->gain(pseudo_log_curve(mapfloat(map(inValue, 0, 0x7f, 0, configuration.dexed[instance_id].sound_intensity), SOUND_INTENSITY_MIN, SOUND_INTENSITY_MAX, 0.0, SOUND_INTENSITY_AMP_MAX))); // That's not right... have to fix this!
MicroDexed[instance_id]->fx.Gain = mapfloat(map(inValue, 0, 0x7f, 0, 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))
{
@ -1774,7 +1755,6 @@ void set_fx_params(void)
reverb_mixer_l.gain(instance_id, pseudo_log_curve(mapfloat(configuration.fx.reverb_send[instance_id], REVERB_SEND_MIN, REVERB_SEND_MAX, 0.0, 1.0)));
// DEXED FILTER
//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);
MicroDexed[instance_id]->doRefreshVoice();
@ -1808,7 +1788,7 @@ void set_voiceconfig_params(uint8_t instance_id)
MicroDexed[instance_id]->setMonoMode(configuration.sys.mono);
// 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)));
MicroDexed[instance_id]->fx.Gain = 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));
@ -1844,14 +1824,16 @@ float pseudo_log_curve(float value)
#endif
*/
// return (mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0));
return (mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0));
/*
float g = mapfloat(_pseudo_log * arm_sin_f32(value), 0.0, _pseudo_log * arm_sin_f32(1.0), 0.0, 1.0);
if (g == 0.0)
return (0.001);
else
return (g);
*/
}
uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https://www.arduino.cc/en/Tutorial/EEPROMCrc

@ -23,6 +23,7 @@
*/
#define _USE_MATH_DEFINES
#include "config.h"
#include <math.h>
#include "PluginFx.h"
#include "synth.h"
@ -53,9 +54,9 @@ static float logsc(float param, const float min, const float max, const float ro
}
PluginFx::PluginFx() {
Cutoff = 1;
Reso = 0;
Gain = 1;
Cutoff = 1.0;
Reso = 0.0;
Gain = 1.0;
}
void PluginFx::init(int sr) {
@ -113,17 +114,25 @@ void PluginFx::process(float *work, int sampleSize) {
t_fd = work[i];
work[i] = work[i] - dc_id + dc_r * work[i - 1];
dc_id = t_fd;
}
dc_od = work[sampleSize - 1];
if ( Gain != 1 ) {
// Gain
if (Gain == 0.0)
{
for (int i = 0; i < sampleSize; i++ )
work[i] = 0.0;
}
else if ( Gain != 1.0)
{
for (int i = 0; i < sampleSize; i++ )
work[i] *= Gain;
}
#ifdef USE_FX
// don't apply the LPF if the cutoff is to maximum
if ( Cutoff == 1 )
if ( Cutoff == 1.0 )
return;
if ( Cutoff != pCutoff || Reso != pReso ) {
@ -183,6 +192,7 @@ void PluginFx::process(float *work, int sampleSize) {
//half volume comp
work[i] = mc * (1 + R24 * 0.45);
}
#endif
}
/*
@ -222,5 +232,5 @@ void PluginFx::process(float *work, int sampleSize) {
float PluginFx::getGain(void)
{
return(Gain);
return (Gain);
}

@ -64,7 +64,6 @@ extern void change_disp_sd(bool d);
#endif
extern AudioSourceMicroDexed* MicroDexed[NUM_DEXED];
extern AudioAmplifier* dexed_level[NUM_DEXED];
#if defined(USE_FX)
extern AudioSynthWaveform* chorus_modulator[NUM_DEXED];
extern AudioEffectModulatedDelay* modchorus[NUM_DEXED];
@ -1888,7 +1887,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)));
MicroDexed[selected_instance_id]->fx.Gain = 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 *********

@ -47,7 +47,7 @@
// amidi -p hw:2,0,0 -d -r /tmp/bkup1.syx
//
#define VERSION "0.9.9i"
#define VERSION "0.9.9j"
//*************************************************************************************************
//* DEVICE SETTINGS
@ -95,7 +95,7 @@
#define DEXED_ENGINE DEXED_ENGINE_MODERN // DEXED_ENGINE_MARKI // DEXED_ENGINE_OPL
// Number of Dexed instances
#define NUM_DEXED 1 // 1 or 2 - nothing else!
#define NUM_DEXED 2 // 1 or 2 - nothing else!
// FX-CHAIN ENABLE/DISABLE
#define USE_FX 1
// CHORUS parameters

@ -156,9 +156,7 @@ void Dexed::getSamples(uint16_t n_samples, int16_t* buffer)
}
}
#ifdef USE_FX
fx.process(sumbuf, n_samples);
#endif
fx.process(sumbuf, n_samples); // Needed for fx.Gain()!!!
//arm_scale_f32(sumbuf, 0.00015, sumbuf, AUDIO_BLOCK_SAMPLES);
arm_float_to_q15(sumbuf, buffer, AUDIO_BLOCK_SAMPLES);

Loading…
Cancel
Save