Global _loadness as float.

Added function for resetting piano voices.
Using max_poly for maximum voices.
dev
Holger Wirtz 6 years ago
parent cd560fb59a
commit a0874087a0
  1. 9
      MicroMDAEPiano.ino
  2. 8
      UI.hpp
  3. 9
      config.h
  4. 21
      mdaEPiano.cpp
  5. 1
      mdaEPiano.h

@ -127,10 +127,13 @@ config_t configuration = {
ENC_EQ_TREBLE_DEFAULT, // eq_treble ENC_EQ_TREBLE_DEFAULT, // eq_treble
ENC_LOUDNESS_DEFAULT, // loudness ENC_LOUDNESS_DEFAULT, // loudness
ENC_MIDI_CHANNEL_DEFAULT, // midi_channel ENC_MIDI_CHANNEL_DEFAULT, // midi_channel
ENC_MIDI_CHANNEL_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
}; };
float _loudness=mapfloat(float(ENC_LOUDNESS_DEFAULT), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0);
bool eeprom_update_flag = false; bool eeprom_update_flag = false;
#ifdef SHOW_CPU_LOAD_MSEC #ifdef SHOW_CPU_LOAD_MSEC
elapsedMillis cpu_mem_millis; elapsedMillis cpu_mem_millis;
@ -450,11 +453,11 @@ bool checkMidiChannel(byte inChannel)
void set_master_volume(uint8_t value) void set_master_volume(uint8_t value)
{ {
configuration.pan=0; // BAD HACK!
uint16_t tmp = map(value, ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX, 0, 0x3ff); uint16_t tmp = map(value, ENC_MASTER_VOLUME_MIN, ENC_MASTER_VOLUME_MAX, 0, 0x3ff);
float tmp2 = mapfloat(configuration.pan, ENC_MASTER_PAN_MIN, ENC_MASTER_PAN_MAX, 0.0, 1.0); float tmp2 = mapfloat(configuration.pan, ENC_MASTER_PAN_MIN, ENC_MASTER_PAN_MAX, 0.0, 1.0);
float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20); float tmp3 = (float)(tmp * (tmp + 2)) / (float)(1 << 20);
#ifdef DEBUG #ifdef DEBUG
Serial.print(tmp, DEC);
Serial.print(F("Setting volume: VOL=")); Serial.print(F("Setting volume: VOL="));
Serial.print(value, DEC); Serial.print(value, DEC);
Serial.print(F("[")); Serial.print(F("["));

@ -101,6 +101,7 @@ extern AudioMixer4 mixer_r;
extern AudioMixer4 mixer_l; extern AudioMixer4 mixer_l;
extern AudioAmplifier volume_r; extern AudioAmplifier volume_r;
extern AudioAmplifier volume_l; extern AudioAmplifier volume_l;
extern float _loudness;
/****************************************** /******************************************
TEXT GETTER FUCTIONS TEXT GETTER FUCTIONS
@ -158,10 +159,10 @@ char* get_comp_limit_value_text(void)
{ {
switch (configuration.comp_limit) switch (configuration.comp_limit)
{ {
case 0: case false:
return (comp_limit_value_text1); return (comp_limit_value_text1);
break; break;
case 1: case true:
return (comp_limit_value_text2); return (comp_limit_value_text2);
break; break;
} }
@ -1937,7 +1938,7 @@ void set_loudness(uint8_t value)
Serial.print(F("Set LOUDNESS ")); Serial.print(F("Set LOUDNESS "));
Serial.println(value); Serial.println(value);
#endif #endif
configuration._loudness = mapfloat(float(value), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0); _loudness = mapfloat(float(value), ENC_LOUDNESS_MIN, ENC_LOUDNESS_MAX, 0.0, 1.0);
//volume_r.gain(tmp); //volume_r.gain(tmp);
//volume_l.gain(tmp); //volume_l.gain(tmp);
configuration.loudness = value; configuration.loudness = value;
@ -1968,6 +1969,7 @@ void set_max_poly(uint8_t value)
Serial.println(value); Serial.println(value);
#endif #endif
configuration.max_poly = value; configuration.max_poly = value;
ep->reset_voices();
} }
void set_complete_configuration(void) void set_complete_configuration(void)

@ -261,8 +261,8 @@
#define ENC_MIDI_SOFT_THRU_DEFAULT 1 #define ENC_MIDI_SOFT_THRU_DEFAULT 1
// //
#define ENC_MAX_POLY_MIN 1 #define ENC_MAX_POLY_MIN 1
#define ENC_MAX_POLY_MAX 32 #define ENC_MAX_POLY_MAX NVOICES
#define ENC_MAX_POLY_DEFAULT 32 #define ENC_MAX_POLY_DEFAULT NVOICES
// //
#define ENC_MASTER_VOLUME_MIN 0 #define ENC_MASTER_VOLUME_MIN 0
#define ENC_MASTER_VOLUME_MAX 99 #define ENC_MASTER_VOLUME_MAX 99
@ -323,7 +323,7 @@ struct config_t {
uint8_t overdrive; uint8_t overdrive;
uint8_t comp_gain; uint8_t comp_gain;
uint8_t comp_response; uint8_t comp_response;
uint8_t comp_limit; bool comp_limit;
uint8_t comp_threshold; uint8_t comp_threshold;
uint8_t comp_attack; uint8_t comp_attack;
uint8_t comp_decay; uint8_t comp_decay;
@ -338,9 +338,8 @@ struct config_t {
uint8_t eq_bass; uint8_t eq_bass;
uint8_t eq_treble; uint8_t eq_treble;
uint8_t loudness; uint8_t loudness;
float _loudness;
uint8_t midi_channel; uint8_t midi_channel;
uint8_t midi_soft_thru; bool midi_soft_thru;
uint8_t max_poly; uint8_t max_poly;
int8_t pan; int8_t pan;
}; };

@ -29,6 +29,8 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
extern float _loudness;
mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS) mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster) : AudioEffectX(audioMaster, NPROGS, NPARAMS)
{ {
Fs = SAMPLE_RATE; iFs = 1.0f / Fs; //just in case... Fs = SAMPLE_RATE; iFs = 1.0f / Fs; //just in case...
@ -98,6 +100,12 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster)
kgrp[31].pos = 406046; kgrp[31].end = 414486; kgrp[31].loop = 2306; //ghost kgrp[31].pos = 406046; kgrp[31].end = 414486; kgrp[31].loop = 2306; //ghost
kgrp[32].pos = 414487; kgrp[32].end = 422408; kgrp[32].loop = 2169; kgrp[32].pos = 414487; kgrp[32].end = 422408; kgrp[32].loop = 2169;
//initialise...
reset_voices();
}
void mdaEPiano::reset_voices(void) // reset all voices
{
//initialise... //initialise...
for (int32_t v = 0; v < NVOICES; v++) for (int32_t v = 0; v < NVOICES; v++)
{ {
@ -116,7 +124,6 @@ mdaEPiano::mdaEPiano() // mdaEPiano::mdaEPiano(audioMasterCallback audioMaster)
update(); update();
// suspend(); // suspend();
} }
void mdaEPiano::update() //parameter change void mdaEPiano::update() //parameter change
{ {
float * param = programs[curProgram].param; float * param = programs[curProgram].param;
@ -240,8 +247,8 @@ void mdaEPiano::process(int16_t* outputs_r, int16_t* outputs_l)
l = 1.0; l = 1.0;
else if (l < -1.0) else if (l < -1.0)
l = -1.0; l = -1.0;
outputs_l[frame] = static_cast<int16_t>(l * configuration._loudness * 0x7fff) >> REDUCE_LOUDNESS; outputs_l[frame] = static_cast<int16_t>(l * _loudness * 0x7fff) >> REDUCE_LOUDNESS;
outputs_r[frame] = static_cast<int16_t>(r * configuration._loudness * 0x7fff) >> REDUCE_LOUDNESS; outputs_r[frame] = static_cast<int16_t>(r * _loudness * 0x7fff) >> REDUCE_LOUDNESS;
} }
if (fabs(tl) < 1.0e-10) tl = 0.0f; //anti-denormal if (fabs(tl) < 1.0e-10) tl = 0.0f; //anti-denormal
@ -260,7 +267,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity)
if (velocity > 0) if (velocity > 0)
{ {
if (activevoices < NVOICES) //add a note if (activevoices < configuration.max_poly) //add a note
{ {
vl = activevoices; vl = activevoices;
activevoices++; activevoices++;
@ -268,7 +275,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity)
} }
else //steal a note else //steal a note
{ {
for (v = 0; v < NVOICES; v++) //find quietest voice for (v = 0; v < configuration.max_poly; v++) //find quietest voice
{ {
if (voice[v].env < l) { if (voice[v].env < l) {
l = voice[v].env; l = voice[v].env;
@ -318,7 +325,7 @@ void mdaEPiano::noteOn(int32_t note, int32_t velocity)
} }
else //note off else //note off
{ {
for (v = 0; v < NVOICES; v++) if (voice[v].note == note) //any voices playing that note? for (v = 0; v < configuration.max_poly; v++) if (voice[v].note == note) //any voices playing that note?
{ {
if (sustain == 0) if (sustain == 0)
{ {
@ -360,7 +367,7 @@ bool mdaEPiano::processMidiController(uint8_t data1, uint8_t data2)
default: //all notes off default: //all notes off
if (data1 > 0x7A) if (data1 > 0x7A)
{ {
for (int32_t v = 0; v < NVOICES; v++) voice[v].dec = 0.99f; for (int32_t v = 0; v < configuration.max_poly; v++) voice[v].dec = 0.99f;
sustain = 0; sustain = 0;
muff = 160.0f; muff = 160.0f;
} }

@ -87,6 +87,7 @@ class mdaEPiano
virtual void setParameter(int32_t index, float value); virtual void setParameter(int32_t index, float value);
virtual float getParameter(int32_t index); virtual float getParameter(int32_t index);
virtual void resume(); virtual void resume();
void reset_voices(void);
int32_t guiUpdate; int32_t guiUpdate;
void guiGetDisplay(int32_t index, char *label); void guiGetDisplay(int32_t index, char *label);

Loading…
Cancel
Save