@ -21,15 +21,14 @@
Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
# include "config.h"
# include <Audio.h>
# include <Wire.h>
# include <SPI.h>
# include <MIDI.h>
# include <EEPROM.h>
# include "EEPROMAnything.h"
# include <limits.h>
# include "mdaEPiano.h"
# include "effect_modulated_delay.h"
# ifdef USE_XFADE_DATA
# include "mdaEPianoDataXfade.h"
# else
@ -37,6 +36,7 @@
# endif
# include "UI.hpp"
# include "midi_devices.hpp"
# include "config.h"
//*************************************************************************************************
//* GLOBAL VARIABLES
@ -53,31 +53,47 @@ AudioMixer4 mixer_r;
AudioMixer4 mixer_l ;
AudioAmplifier volume_r ;
AudioAmplifier volume_l ;
AudioAmplifier inverter ;
AudioEffectModulatedDelay modchorus_r ;
AudioEffectModulatedDelay modchorus_l ;
# if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT
AudioFilterBiquad modchorus_filter_r ;
AudioFilterBiquad modchorus_filter_l ;
# endif
AudioSynthWaveform modulator ;
AudioConnection patchCord0 ( queue_r , peak_r ) ;
AudioConnection patchCord1 ( queue_l , peak_l ) ;
AudioConnection patchCord4 ( queue_r , freeverb_r ) ;
AudioConnection patchCord5 ( queue_l , freeverb_l ) ;
AudioConnection patchCord6 ( queue_r , 0 , mixer_r , 0 ) ;
AudioConnection patchCord7 ( queue_l , 0 , mixer_l , 0 ) ;
AudioConnection patchCord8 ( freeverb_r , 0 , mixer_r , 1 ) ;
AudioConnection patchCord9 ( freeverb_l , 0 , mixer_l , 1 ) ;
AudioConnection patchCord10 ( mixer_r , volume_r ) ;
AudioConnection patchCord11 ( mixer_l , volume_l ) ;
# if defined(TEENSY_AUDIO_BOARD)
AudioOutputI2S i2s1 ;
AudioConnection patchCord12 ( volume_r , 0 , i2s1 , 0 ) ;
AudioConnection patchCord13 ( volume_l , 0 , i2s1 , 1 ) ;
AudioControlSGTL5000 sgtl5000_1 ;
# elif defined(TGA_AUDIO_BOARD)
AudioOutputI2S i2s1 ;
AudioConnection patchCord12 ( volume_r , 0 , i2s1 , 1 ) ;
AudioConnection patchCord13 ( volume_l , 0 , i2s1 , 0 ) ;
AudioControlWM8731master wm8731_1 ;
AudioConnection patchCord2 ( queue_r , freeverb_r ) ;
AudioConnection patchCord3 ( queue_l , freeverb_l ) ;
AudioConnection patchCord4 ( queue_r , 0 , modchorus_r , 0 ) ;
AudioConnection patchCord5 ( queue_l , 0 , modchorus_l , 0 ) ;
AudioConnection patchCord6 ( modulator , 0 , modchorus_r , 1 ) ;
AudioConnection patchCord7 ( modulator , inverter ) ;
AudioConnection patchCord8 ( inverter , 0 , modchorus_l , 1 ) ;
AudioConnection patchCord9 ( queue_r , 0 , mixer_r , 0 ) ;
AudioConnection patchCord10 ( queue_l , 0 , mixer_l , 0 ) ;
# if MOD_FILTER_OUTPUT != MOD_NO_FILTER_OUTPUT
AudioConnection patchCord11 ( modchorus_r , modchorus_filter_r ) ;
AudioConnection patchCord12 ( modchorus_l , modchorus_filter_l ) ;
AudioConnection patchCord13 ( modchorus_filter_r , 0 , mixer_r , 2 ) ;
AudioConnection patchCord14 ( modchorus_filter_l , 0 , mixer_l , 2 ) ;
# else
AudioOutputPT8211 pt8211_1 ;
AudioConnection patchCord12 ( volume_r , 0 , pt8211_1 , 1 ) ;
AudioConnection patchCord13 ( volume_l , 0 , pt8211_1 , 0 ) ;
AudioConnection patchCord11 ( modchorus_r , mixer_r ) ;
AudioConnection patchCord12 ( modchorus_l , mixer_l ) ;
# endif
AudioConnection patchCord15 ( freeverb_r , 0 , mixer_r , 1 ) ;
AudioConnection patchCord16 ( freeverb_l , 0 , mixer_l , 1 ) ;
AudioConnection patchCord17 ( mixer_r , volume_r ) ;
AudioConnection patchCord18 ( mixer_l , volume_l ) ;
# ifdef USB_AUDIO
AudioOutputUSB usb1 ;
AudioConnection patchCord19 ( volume_r , 0 , usb1 , 0 ) ;
AudioConnection patchCord20 ( volume_l , 0 , usb1 , 1 ) ;
# endif
AudioOutputI2S i2s1 ;
AudioConnection patchCord21 ( volume_r , 0 , i2s1 , 0 ) ;
AudioConnection patchCord22 ( volume_l , 0 , i2s1 , 1 ) ;
AudioControlSGTL5000 sgtl5000_1 ;
// Objects
mdaEPiano * ep ;
@ -119,7 +135,8 @@ config_t configuration = {
ENC_REVERB_DAMPING_DEFAULT , // reverb_damping
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_WAVEFORM_DEFAULT , // chorus_waveform
ENC_CHORUS_LEVEL_DEFAULT , // chorus_level
ENC_BASS_LR_LEVEL_DEFAULT , // bass_lr_level
ENC_BASS_MONO_LEVEL_DEFAULT , // bass_mono_level
@ -129,10 +146,10 @@ 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_MONO_DEFAULT , // mono
ENC_MASTER_PAN_DEFAULT // pan
} ;
float _loudness = mapfloat ( float ( ENC_LOUDNESS_DEFAULT ) , ENC_LOUDNESS_MIN , ENC_LOUDNESS_MAX , 0.0 , 1.0 ) ;
uint8_t master_volume = ENC_MASTER_VOLUME_DEFAULT ;
int8_t pan = ENC_MASTER_PAN_DEFAULT ;
uint8_t eeprom_config_update_flag = 0 ;
@ -143,6 +160,15 @@ elapsedMillis eeprom_master_volume_update_timer;
elapsedMillis cpu_mem_millis ;
# endif
# ifdef DEBUG_AUDIO
elapsedMillis debug_audio_timer ;
# endif
// Allocate the delay lines for left and right channels
short l_delayline [ MOD_DELAY_SAMPLE_BUFFER ] ;
short r_delayline [ MOD_DELAY_SAMPLE_BUFFER ] ;
enum { VOL_MAIN , VOL_REVERB , VOL_CHORUS } ;
//*************************************************************************************************
//* SETUP FUNCTION
//*************************************************************************************************
@ -169,8 +195,8 @@ void setup()
// create EPiano object
ep = new mdaEPiano ( ) ;
// set initial init configuration
set_complete_configuration ( ) ;
initial_values_from_eeprom ( ) ;
setup_midi_devices ( ) ;
@ -178,7 +204,6 @@ void setup()
AudioNoInterrupts ( ) ;
AudioMemory ( AUDIO_MEM ) ;
# ifdef TEENSY_AUDIO_BOARD
sgtl5000_1 . enable ( ) ;
sgtl5000_1 . dacVolumeRamp ( ) ;
sgtl5000_1 . dacVolume ( 1.0 ) ;
@ -191,33 +216,87 @@ void setup()
sgtl5000_1 . autoVolumeEnable ( ) ;
sgtl5000_1 . enhanceBassEnable ( ) ;
Serial . println ( F ( " Teensy-Audio-Board enabled. " ) ) ;
# elif defined(TGA_AUDIO_BOARD)
wm8731_1 . enable ( ) ;
wm8731_1 . volume ( 1.0 ) ;
Serial . println ( F ( " TGA board enabled. " ) ) ;
# else
Serial . println ( F ( " PT8211 enabled. " ) ) ;
# endif
set_master_volume ( master_volume ) ;
# if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
# if defined (SHOW_DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
// Initialize processor and memory measurements
AudioProcessorUsageMaxReset ( ) ;
AudioMemoryUsageMaxReset ( ) ;
# endif
AudioInterrupts ( ) ;
Serial . print ( F ( " AUDIO_BLOCK_SAMPLES= " ) ) ;
Serial . print ( AUDIO_BLOCK_SAMPLES ) ;
Serial . print ( F ( " (Time per block= " ) ) ;
Serial . print ( audio_block_time_us ) ;
Serial . println ( F ( " m s)" ) ) ;
Serial . println ( F ( " u s)" ) ) ;
AudioInterrupts ( ) ;
if ( ! modchorus_r . begin ( r_delayline , MOD_DELAY_SAMPLE_BUFFER ) ) {
Serial . println ( F ( " AudioEffectModulatedDelay - right channel begin failed " ) ) ;
while ( 1 ) ;
}
if ( ! modchorus_l . begin ( l_delayline , MOD_DELAY_SAMPLE_BUFFER ) ) {
Serial . println ( F ( " AudioEffectModulatedDelay - left channel begin failed " ) ) ;
while ( 1 ) ;
}
# ifdef DEBUG
Serial . print ( F ( " MOD_DELAY_SAMPLE_BUFFER= " ) ) ;
Serial . print ( MOD_DELAY_SAMPLE_BUFFER , DEC ) ;
Serial . println ( F ( " samples " ) ) ;
# endif
// chorus modulation fixed
modulator . begin ( MOD_WAVEFORM ) ;
modulator . phase ( 0 ) ;
modulator . amplitude ( 0.5 ) ;
modulator . offset ( 0.0 ) ;
# if MOD_FILTER_OUTPUT == MOD_BUTTERWORTH_FILTER_OUTPUT
// Butterworth filter, 12 db/octave
modchorus_filter_r . setLowpass ( 0 , MOD_FILTER_CUTOFF_HZ , 0.707 ) ;
modchorus_filter_l . setLowpass ( 0 , MOD_FILTER_CUTOFF_HZ , 0.707 ) ;
# elif MOD_FILTER_OUTPUT == MOD_LINKWITZ_RILEY_FILTER_OUTPUT
// Linkwitz-Riley filter, 48 dB/octave
modchorus_filter_r . setLowpass ( 0 , MOD_FILTER_CUTOFF_HZ , 0.54 ) ;
modchorus_filter_r . setLowpass ( 1 , MOD_FILTER_CUTOFF_HZ , 1.3 ) ;
modchorus_filter_r . setLowpass ( 2 , MOD_FILTER_CUTOFF_HZ , 0.54 ) ;
modchorus_filter_r . setLowpass ( 3 , MOD_FILTER_CUTOFF_HZ , 1.3 ) ;
modchorus_filter_l . setLowpass ( 0 , MOD_FILTER_CUTOFF_HZ , 0.54 ) ;
modchorus_filter_l . setLowpass ( 1 , MOD_FILTER_CUTOFF_HZ , 1.3 ) ;
modchorus_filter_l . setLowpass ( 2 , MOD_FILTER_CUTOFF_HZ , 0.54 ) ;
modchorus_filter_l . setLowpass ( 3 , MOD_FILTER_CUTOFF_HZ , 1.3 ) ;
# endif
// internal mixing of original signal(0), reverb(1) and chorus(2)
mixer_r . gain ( VOL_MAIN , 0.5 ) ;
mixer_l . gain ( VOL_MAIN , 0.5 ) ;
mixer_r . gain ( VOL_REVERB , 0.2 ) ;
mixer_l . gain ( VOL_REVERB , 0.2 ) ;
mixer_r . gain ( VOL_CHORUS , 0.2 ) ;
mixer_l . gain ( VOL_CHORUS , 0.2 ) ;
// Stereo/Mono initial setup
if ( configuration . mono = = 0 )
{
inverter . gain ( - 1.0 ) ; // change phase for second modulated delay (faked stereo mode)
}
else
{
inverter . gain ( 1.0 ) ;
configuration . pan = ENC_MASTER_PAN_DEFAULT ;
}
// set master volume
set_master_volume ( master_volume ) ;
// load last configuration used
initial_values_from_eeprom ( ) ;
// init random generator
srand ( analogRead ( A0 ) ) ;
Serial . println ( F ( " <setup end> " ) ) ;
# if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
# if defined (SHOW_ DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
Serial . println ( ) ;
show_cpu_and_mem_usage ( ) ;
cpu_mem_millis = 0 ;
@ -238,7 +317,7 @@ void loop()
{
fill_audio_buffer = 0 ;
# if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
# if defined (SHOW_ DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
if ( cpu_mem_millis > SHOW_CPU_LOAD_MSEC )
{
show_cpu_and_mem_usage ( ) ;
@ -290,9 +369,17 @@ void loop()
if ( eeprom_config_update_flag > 0 & & ep - > getActiveVoices ( ) = = 0 ) // write only to eeprom when no voice is active
eeprom_config_update ( ) ;
if ( eeprom_master_volume_update_flag = = true & & eeprom_master_volume_update_timer > STORE_MASTER_VOLUME_MS )
if ( eeprom_master_volume_update_flag = = true & & eeprom_master_volume_update_timer > STORE_MASTER_VOLUME_MS & & ep - > getActiveVoices ( ) = = 0 )
eeprom_master_volume_update ( ) ;
}
# ifdef DEBUG_AUDIO
if ( debug_audio_timer > DEBUG_AUDIO )
{
ep - > noteOn ( 60 + rand ( ) % 108 , rand ( ) % 128 ) ;
debug_audio_timer = 0 ;
}
# endif
}
//*************************************************************************************************
@ -318,7 +405,107 @@ void handleControlChange(byte inChannel, byte inData1, byte inData2)
{
if ( checkMidiChannel ( inChannel ) )
{
switch ( inData1 )
{
// Standard MIDI-CC
case MIDI_CC_PANORAMA : // Panorama
configuration . pan = map ( inData2 , 0 , 127 , ENC_MASTER_PAN_MIN , ENC_MASTER_PAN_MAX ) ;
break ;
case MIDI_CC_REVERB_SEND : // Reverb level
set_reverb_level ( map ( inData2 , 0 , 127 , ENC_REVERB_LEVEL_MIN , ENC_REVERB_LEVEL_MAX ) ) ;
break ;
case MIDI_CC_TREMOLO_DEPTH : // Tremolo level (same as modwheel)
inData1 = 1 ; // now it's modwheel and can be processd by ep->processMidiController :-)
break ;
case MIDI_CC_CHORUS_SEND : // Chorus level
set_chorus_level ( map ( inData2 , 0 , 127 , ENC_CHORUS_LEVEL_MIN , ENC_CHORUS_LEVEL_MAX ) ) ;
break ;
case MIDI_CC_DETUNE_DEPTH : // Detune level
ep - > setDetune ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
// Own MIDI-CC mapping
case MIDI_CC_EP_DECAY :
ep - > setDecay ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_RELEASE :
ep - > setRelease ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_HARDNESS :
ep - > setHardness ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_TREBLE :
ep - > setTreble ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_STEREO :
ep - > setStereo ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_TUNE :
ep - > setTune ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_VELOCITY_SENSE :
ep - > setVelocitySense ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_TREM_FRQ :
ep - > setPanLFO ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_EP_OVERDRIVE :
ep - > setOverdrive ( mapfloat ( float ( inData2 ) , 0 , 127 , 0.0 , 1.0 ) ) ;
break ;
case MIDI_CC_COMP_GAIN :
set_comp_gain ( map ( inData2 , 0 , 127 , ENC_COMP_GAIN_MIN , ENC_COMP_GAIN_MAX ) ) ;
break ;
case MIDI_CC_COMP_REPOSNE :
set_comp_response ( map ( inData2 , 0 , 127 , ENC_COMP_RESPONSE_MIN , ENC_COMP_RESPONSE_MAX ) ) ;
break ;
case MIDI_CC_COMP_LIMIT :
set_comp_limit ( map ( inData2 , 0 , 127 , ENC_COMP_LIMIT_MIN , ENC_COMP_LIMIT_MAX ) ) ;
break ;
case MIDI_CC_COMP_THRESHOLD :
set_comp_threshold ( map ( inData2 , 0 , 127 , ENC_COMP_THRESHOLD_MIN , ENC_COMP_THRESHOLD_MAX ) ) ;
break ;
case MIDI_CC_COMP_ATTACK :
set_comp_attack ( map ( inData2 , 0 , 127 , ENC_COMP_ATTACK_MIN , ENC_COMP_ATTACK_MAX ) ) ;
break ;
case MIDI_CC_COMP_DECAY :
set_comp_decay ( map ( inData2 , 0 , 127 , ENC_COMP_DECAY_MIN , ENC_COMP_DECAY_MAX ) ) ;
break ;
case MIDI_CC_REVERB_ROOMSIZE :
set_reverb_roomsize ( map ( inData2 , 0 , 127 , ENC_REVERB_ROOMSIZE_MIN , ENC_REVERB_ROOMSIZE_MAX ) ) ;
break ;
case MIDI_CC_REVERB_DAMPING :
set_reverb_damping ( map ( inData2 , 0 , 127 , ENC_REVERB_DAMPING_MIN , ENC_REVERB_DAMPING_MAX ) ) ;
break ;
case MIDI_CC_CHORUS_FREQUENCY :
set_chorus_frequency ( map ( inData2 , 0 , 127 , ENC_CHORUS_FREQUENCY_MIN , ENC_CHORUS_FREQUENCY_MAX ) ) ;
break ;
case MIDI_CC_CHORUS_INTENSITY :
set_chorus_intensity ( map ( inData2 , 0 , 127 , ENC_CHORUS_INTENSITY_MIN , ENC_CHORUS_INTENSITY_MAX ) ) ;
break ;
case MIDI_CC_CHORUS_WAVEFORM :
set_chorus_waveform ( map ( inData2 , 0 , 127 , ENC_CHORUS_WAVEFORM_MIN , ENC_CHORUS_WAVEFORM_MAX ) ) ;
break ;
case MIDI_CC_BASS_LR_LEVEL :
set_bass_lr_level ( map ( inData2 , 0 , 127 , ENC_BASS_LR_LEVEL_MIN , ENC_BASS_LR_LEVEL_MAX ) ) ;
break ;
case MIDI_CC_BASS_MONO_LEVEL :
set_bass_mono_level ( map ( inData2 , 0 , 127 , ENC_BASS_MONO_LEVEL_MIN , ENC_BASS_MONO_LEVEL_MAX ) ) ;
break ;
case MIDI_CC_EQ_BASS :
set_eq_bass ( map ( inData2 , 0 , 127 , ENC_EQ_BASS_MIN , ENC_EQ_BASS_MAX ) ) ;
break ;
case MIDI_CC_EQ_TREBLE :
set_eq_treble ( map ( inData2 , 0 , 127 , ENC_EQ_TREBLE_MIN , ENC_EQ_TREBLE_MAX ) ) ;
break ;
case MIDI_CC_MIDI_SOFT_THRU :
set_midi_soft_thru ( map ( inData2 , 0 , 127 , ENC_MIDI_SOFT_THRU_MIN , ENC_MIDI_SOFT_THRU_MAX ) ) ;
break ;
case MIDI_CC_MONO :
set_mono ( map ( inData2 , 0 , 127 , ENC_MONO_MIN , ENC_MONO_MAX ) ) ;
break ;
default :
ep - > processMidiController ( inData1 , inData2 ) ;
break ;
}
}
}
@ -334,15 +521,21 @@ void handlePitchBend(byte inChannel, int inPitch)
void handleProgramChange ( byte inChannel , byte inProgram )
{
;
if ( checkMidiChannel ( inChannel ) )
{
sound = inProgram ;
load_sound ( ) ;
if ( menu_system . get_currentScreen ( ) = = & load_sound_screen )
menu_system . update ( ) ;
}
}
void handleSystemExclusive ( byte * data , uint len )
void handleSystemExclusive ( byte * data , uint len )
{
;
}
void handleSystemExclusiveChunk ( const byte * data , uint16_t len , bool last )
void handleSystemExclusiveChunk ( const byte * data , uint16_t len , bool last )
{
;
}
@ -411,7 +604,7 @@ bool checkMidiChannel(byte inChannel)
}
else if ( inChannel ! = configuration . midi_channel )
{
# ifdef DEBUG
# ifdef SHOW_ DEBUG
Serial . print ( F ( " Ignoring MIDI data on channel " ) ) ;
Serial . print ( inChannel ) ;
Serial . print ( F ( " (listening on " ) ) ;
@ -425,11 +618,11 @@ bool checkMidiChannel(byte inChannel)
void set_master_volume ( uint8_t value )
{
configuration . pan = 0 ; // BAD HACK!
//configuration.pan = 0; // BAD HACK!
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 tmp3 = ( float ) ( tmp * ( tmp + 2 ) ) / ( float ) ( 1 < < 20 ) ;
# ifdef DEBUG
# ifdef SHOW_ DEBUG
Serial . print ( F ( " Setting volume: VOL= " ) ) ;
Serial . print ( value , DEC ) ;
Serial . print ( F ( " [ " ) ) ;
@ -446,11 +639,18 @@ void set_master_volume(uint8_t value)
// float v = (float)(a * (a + 2))/(float)(1 << 20); // (pseudo-) logarithmic curve for volume control
// http://files.csound-tutorial.net/floss_manual/Release03/Cs_FM_03_ScrapBook/b-panning-and-spatialization.html
mixer_r . gain ( 0 , tmp3 * sinf ( tmp2 * PI / 2 ) ) ;
mixer_l . gain ( 0 , tmp3 * cosf ( tmp2 * PI / 2 ) ) ;
volume_r . gain ( tmp3 * sinf ( tmp2 * PI / 2 ) ) ;
volume_l . gain ( tmp3 * cosf ( tmp2 * PI / 2 ) ) ;
if ( configuration . mono = = 2 )
volume_l . gain ( 0.0 ) ;
else if ( configuration . mono = = 3 )
volume_r . gain ( 0.0 ) ;
eeprom_master_volume_update_flag = true ;
eeprom_master_volume_update_timer = 0 ;
if ( menu_system . get_currentScreen ( ) = = & master_volume_screen )
menu_system . update ( ) ;
}
/******************************************************************************
@ -465,8 +665,12 @@ void config_from_eeprom(void)
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 " ) ) ;
# ifdef SHOW_DEBUG
Serial . print ( F ( " Reading sound " ) ) ;
Serial . print ( sound , DEC ) ;
Serial . print ( F ( " from 0x " ) ) ;
Serial . print ( EEPROM_CONFIGURATIONS + sizeof ( config_t ) * ( sound - 1 ) , HEX ) ;
Serial . print ( F ( " EEPROM checksum: 0x " ) ) ;
Serial . print ( tmp_conf . checksum , HEX ) ;
Serial . print ( F ( " / 0x " ) ) ;
Serial . print ( checksum , HEX ) ;
@ -475,57 +679,29 @@ 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 ( sound , DEC ) ;
# ifdef SHOW_DEBUG
Serial . println ( F ( " - OK " ) ) ;
# endif
}
else
# ifdef DEBUG
{
Serial . println ( F ( " - mismatch (or force) -> nothing done! " ) ) ;
# ifdef SHOW_DEBUG
Serial . println ( F ( " - mismatch -> loading initial configuration. " ) ) ;
# endif
EEPROM . update ( EEPROM_SOUND , sound ) ;
}
set_complete_configuration ( ) ;
# ifdef SHOW_DEBUG
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
sound = EEPROM . read ( EEPROM_SOUND ) ;
load_sound ( ) ;
}
void eeprom_config_write ( uint8_t value )
@ -536,12 +712,15 @@ void eeprom_config_write(uint8_t value)
void eeprom_config_update ( void )
{
configuration . checksum = crc32 ( ( byte * ) & configuration + 4 , sizeof ( configuration ) - 4 ) ;
EEPROM_writeAnything ( EEPROM_CONFIGURATIONS + sizeof ( config_t ) * ( eeprom_config_update_flag - 1 ) , configuration ) ;
Serial . print ( F ( " Updating EEPROM configuration for sound " ) ) ;
Serial . print ( eeprom_config_update_flag , DEC ) ;
Serial . print ( F ( " with checksum 0x " ) ) ;
Serial . print ( configuration . checksum , HEX ) ;
Serial . print ( F ( " at 0x " ) ) ;
Serial . println ( EEPROM_CONFIGURATIONS + sizeof ( config_t ) * ( eeprom_config_update_flag - 1 ) , HEX ) ;
EEPROM_writeAnything ( EEPROM_CONFIGURATIONS + sizeof ( config_t ) * ( eeprom_config_update_flag - 1 ) , configuration ) ;
eeprom_config_update_flag = 0 ;
EEPROM . update ( EEPROM_SOUND , sound ) ;
}
void eeprom_master_volume_write ( void )
@ -581,7 +760,7 @@ uint32_t crc32(byte * calc_start, uint16_t calc_bytes) // base code from https:/
//* DEBUG FUNCTIONS
//*************************************************************************************************
# if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
# if defined (SHOW_ DEBUG) && defined (SHOW_CPU_LOAD_MSEC)
void show_cpu_and_mem_usage ( void )
{
Serial . print ( F ( " CPU: " ) ) ;
@ -610,6 +789,7 @@ void show_cpu_and_mem_usage(void)
void show_sound ( void )
{
Serial . println ( F ( " ======SHOW=SOUND=CONFIGURATION====== " ) ) ;
Serial . print ( F ( " Master Volume: " ) ) ;
Serial . println ( master_volume , DEC ) ;
Serial . print ( F ( " Sound: " ) ) ;
@ -658,10 +838,12 @@ void show_sound(void)
Serial . println ( configuration . reverb_damping , DEC ) ;
Serial . print ( F ( " Reverb Level: " ) ) ;
Serial . println ( configuration . reverb_level , DEC ) ;
Serial . print ( F ( " CH orus Frequency: " ) ) ;
Serial . print ( F ( " Ch orus Frequency: " ) ) ;
Serial . println ( configuration . chorus_frequency , DEC ) ;
Serial . print ( F ( " Chorus Delay: " ) ) ;
Serial . println ( configuration . chorus_delay , DEC ) ;
Serial . print ( F ( " Chorus Intensity: " ) ) ;
Serial . println ( configuration . chorus_intensity , DEC ) ;
Serial . print ( F ( " Chorus Waveform: " ) ) ;
Serial . println ( configuration . chorus_waveform , DEC ) ;
Serial . print ( F ( " Chorus Level: " ) ) ;
Serial . println ( configuration . chorus_level , DEC ) ;
Serial . print ( F ( " Bass L/R Level: " ) ) ;
@ -680,7 +862,10 @@ void show_sound(void)
Serial . println ( configuration . midi_soft_thru , DEC ) ;
Serial . print ( F ( " Maximum Polyphony: " ) ) ;
Serial . println ( configuration . max_poly , DEC ) ;
Serial . print ( F ( " Audio-Mono: " ) ) ;
Serial . println ( configuration . mono , DEC ) ;
Serial . print ( F ( " Panorama: " ) ) ;
Serial . println ( configuration . pan , DEC ) ;
Serial . println ( F ( " ======END=OF=SOUND=CONFIGURATION======= " ) ) ;
}
# endif