diff --git a/MicroDexed.ino b/MicroDexed.ino index f2263f9..e78ca36 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -101,8 +101,7 @@ uint8_t bank = 0; uint8_t max_loaded_banks = 0; uint8_t voice = 0; float vol = VOLUME; -float vol_right = 1.0; -float vol_left = 1.0; +float pan = 0.5f; char bank_name[BANK_NAME_LEN]; char voice_name[VOICE_NAME_LEN]; char bank_names[MAX_BANKS][BANK_NAME_LEN]; @@ -156,9 +155,11 @@ void setup() delay(220); Serial.println(F("MicroDexed based on https://github.com/asb2m10/dexed")); - Serial.println(F("(c)2018 H. Wirtz ")); + Serial.println(F("(c)2018,2019 H. Wirtz ")); Serial.println(F("https://github.com/dcoredump/MicroDexed")); Serial.println(F("")); + + //init_eeprom(); initial_values_from_eeprom(); setup_midi_devices(); @@ -185,7 +186,7 @@ void setup() Serial.println(F("PT8211 enabled.")); #endif - set_volume(vol, vol_left, vol_right); + set_volume(vol, pan); // start SD card SPI.setMOSI(SDCARD_MOSI_PIN); @@ -366,6 +367,13 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) { if (checkMidiChannel(inChannel)) { +#ifdef DEBUG + Serial.print(F("CC#")); + Serial.print(inCtrl, DEC); + Serial.print(F(":")); + Serial.println(inValue, DEC); +#endif + switch (inCtrl) { case 0: if (inValue < MAX_BANKS) @@ -388,27 +396,11 @@ void handleControlChange(byte inChannel, byte inCtrl, byte inValue) break; case 7: // Volume vol = float(inValue) / 0x7f; - set_volume(vol, vol_left, vol_right); + set_volume(vol, pan); break; case 10: // Pan - if (inValue < 64) - { - vol_left = 1.0; - vol_right = float(inValue) / 0x40; - set_volume(vol, vol_left, vol_right); - } - else if (inValue > 64) - { - vol_left = float(0x7f - inValue) / 0x40; - vol_right = 1.0; - set_volume(vol, vol_left, vol_right); - } - else - { - vol_left = 1.0; - vol_right = 1.0; - set_volume(vol, vol_left, vol_right); - } + pan = float(inValue) / 128; + set_volume(vol, pan); break; case 32: // BankSelect LSB bank = inValue; @@ -507,6 +499,18 @@ void handleProgramChange(byte inChannel, byte inProgram) void handleSystemExclusive(byte *sysex, uint len) { +#ifdef DEBUG + Serial.print(F("SYSEX-Data[")); + Serial.print(len, DEC); + Serial.print(F("]")); + for (uint8_t i = 0; i < len; i++) + { + Serial.print(F(" ")); + Serial.print(sysex[i], DEC); + } + Serial.println(); +#endif + if (sysex[1] != 0x43) // check for Yamaha sysex { #ifdef DEBUG @@ -660,11 +664,10 @@ bool checkMidiChannel(byte inChannel) return (true); } -void set_volume(float v, float vr, float vl) +void set_volume(float v, float p) { vol = v; - vol_right = vr; - vol_left = vl; + pan = p; #ifdef DEBUG uint8_t tmp; @@ -675,33 +678,30 @@ void set_volume(float v, float vr, float vl) Serial.print(tmp, DEC); Serial.print(F("/")); Serial.print(float(tmp) / UCHAR_MAX, DEC); - Serial.print(F("] VOL_L=")); - Serial.print(vl, DEC); + Serial.print(F("] PAN=")); Serial.print(F("[")); - tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR); + tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_PAN_ADDR); Serial.print(tmp, DEC); Serial.print(F("/")); - Serial.print(float(tmp) / UCHAR_MAX, DEC); - Serial.print(F("] VOL_R=")); - Serial.print(vr, DEC); - Serial.print(F("[")); - tmp = EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR); - Serial.print(tmp, DEC); - Serial.print(F("/")); - Serial.print(float(tmp) / UCHAR_MAX, DEC); + Serial.print(float(tmp) / SCHAR_MAX, DEC); Serial.println(F("]")); #endif #ifdef TEENSY_AUDIO_BOARD - //sgtl5000_1.dacVolume(vol * vol_left, vol * vol_right); - sgtl5000_1.dacVolume(pow(vol * vol_left, 0.2), pow(vol * vol_right, 0.2)); + sgtl5000_1.dacVolume(v * sinf(p * PI / 2), v * cosf(p * PI / 2)); #else - volume_master.gain(pow(vol, 0.2)); - volume_r.gain(pow(vr, 0.2)); - volume_l.gain(pow(vl, 0.2)); + volume_master.gain(v); + volume_r.gain(sinf(p * PI / 2)); + volume_l.gain(cosf(p * PI / 2)); #endif } +// https://www.dr-lex.be/info-stuff/volumecontrols.html#table1 +inline float logvol(float x) +{ + return (0.001 * expf(6.908 * x)); +} + void initial_values_from_eeprom(void) { uint32_t crc_eeprom = read_eeprom_checksum(); @@ -718,16 +718,17 @@ void initial_values_from_eeprom(void) #ifdef DEBUG Serial.print(F(" - mismatch -> initializing EEPROM!")); #endif - eeprom_write(EEPROM_UPDATE_BANK & EEPROM_UPDATE_VOICE & EEPROM_UPDATE_VOL & EEPROM_UPDATE_VOL_R & EEPROM_UPDATE_VOL_L & EEPROM_UPDATE_MIDICHANNEL); + eeprom_write(EEPROM_UPDATE_BANK + EEPROM_UPDATE_VOICE + EEPROM_UPDATE_VOL + EEPROM_UPDATE_PAN + EEPROM_UPDATE_MIDICHANNEL); } else { bank = EEPROM.read(EEPROM_OFFSET + EEPROM_BANK_ADDR); voice = EEPROM.read(EEPROM_OFFSET + EEPROM_VOICE_ADDR); vol = float(EEPROM.read(EEPROM_OFFSET + EEPROM_MASTER_VOLUME_ADDR)) / UCHAR_MAX; - vol_right = float(EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR)) / UCHAR_MAX; - vol_left = float(EEPROM.read(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR)) / UCHAR_MAX; + pan = float(EEPROM.read(EEPROM_OFFSET + EEPROM_PAN_ADDR)) / SCHAR_MAX; midi_channel = EEPROM.read(EEPROM_OFFSET + EEPROM_MIDICHANNEL_ADDR); + if (midi_channel > 16) + midi_channel = MIDI_CHANNEL_OMNI; } #ifdef DEBUG Serial.println(); @@ -782,8 +783,8 @@ void eeprom_write(uint8_t status) if (eeprom_update_status != 0) autostore = 0; #ifdef DEBUG - Serial.print(F("Updating EEPROM to state to: ")); - Serial.println(eeprom_update_status); + Serial.print(F("Updating EEPROM state to: ")); + Serial.println(eeprom_update_status, DEC); #endif } @@ -815,21 +816,13 @@ void eeprom_update(void) #endif eeprom_update_status &= ~EEPROM_UPDATE_VOL; } - else if (eeprom_update_status & EEPROM_UPDATE_VOL_R) + else if (eeprom_update_status & EEPROM_UPDATE_PAN) { - EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_RIGHT_ADDR, uint8_t(vol_right * UCHAR_MAX)); + EEPROM.update(EEPROM_OFFSET + EEPROM_PAN_ADDR, uint8_t(pan * SCHAR_MAX)); #ifdef DEBUG - Serial.println(F("Volume right written to EEPROM")); + Serial.println(F("Panorama written to EEPROM")); #endif - eeprom_update_status &= ~EEPROM_UPDATE_VOL_R; - } - else if (eeprom_update_status & EEPROM_UPDATE_VOL_L) - { - EEPROM.update(EEPROM_OFFSET + EEPROM_VOLUME_LEFT_ADDR, uint8_t(vol_left * UCHAR_MAX)); -#ifdef DEBUG - Serial.println(F("Volume left written to EEPROM")); -#endif - eeprom_update_status &= ~EEPROM_UPDATE_VOL_L; + eeprom_update_status &= ~EEPROM_UPDATE_PAN; } else if (eeprom_update_status & EEPROM_UPDATE_MIDICHANNEL ) { @@ -855,6 +848,14 @@ void eeprom_update(void) eeprom_update_status |= EEPROM_UPDATE_CHECKSUM; } +void init_eeprom(void) +{ + for (uint8_t i = 0; i < EEPROM_DATA_LENGTH; i++) + { + EEPROM.update(EEPROM_OFFSET + i, 0); + } +} + #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) void show_cpu_and_mem_usage(void) { diff --git a/UI.cpp b/UI.cpp index 7fa8218..64cfaca 100644 --- a/UI.cpp +++ b/UI.cpp @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -217,7 +217,7 @@ void handle_ui(void) enc[i].write(0); else if (enc[i].read() >= ENC_VOL_STEPS) enc[i].write(ENC_VOL_STEPS); - set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, vol_left, vol_right); + set_volume(float(map(enc[i].read(), 0, ENC_VOL_STEPS, 0, 100)) / 100, pan); eeprom_write(EEPROM_UPDATE_VOL); ui_show_volume(); break; diff --git a/UI.h b/UI.h index 92af681..c77003f 100644 --- a/UI.h +++ b/UI.h @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,8 +37,7 @@ extern Encoder4 enc[2]; extern int32_t enc_val[2]; extern Bounce but[2]; extern float vol; -extern float vol_left; -extern float vol_right; +extern float pan; extern LiquidCrystalPlus_I2C lcd; extern uint8_t bank; extern uint8_t max_loaded_banks; @@ -49,7 +48,7 @@ extern uint8_t ui_state; extern uint8_t ui_main_state; extern uint8_t midi_channel; extern void eeprom_write(uint8_t status); -extern void set_volume(float v, float vr, float vl); +extern void set_volume(float v, float pan); extern elapsedMillis autostore; extern elapsedMillis long_button_pressed; extern uint8_t effect_filter_frq; diff --git a/config.h b/config.h index af0d773..4d40b17 100644 --- a/config.h +++ b/config.h @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -142,22 +142,20 @@ // EEPROM address #define EEPROM_OFFSET 0 -#define EEPROM_DATA_LENGTH 6 +#define EEPROM_DATA_LENGTH 5 -#define EEPROM_CRC32_ADDR EEPROM.length()-sizeof(uint32_t) +#define EEPROM_CRC32_ADDR EEPROM.length()-sizeof(uint32_t)-33 #define EEPROM_BANK_ADDR 0 #define EEPROM_VOICE_ADDR 1 #define EEPROM_MASTER_VOLUME_ADDR 2 -#define EEPROM_VOLUME_RIGHT_ADDR 3 -#define EEPROM_VOLUME_LEFT_ADDR 4 -#define EEPROM_MIDICHANNEL_ADDR 5 +#define EEPROM_PAN_ADDR 3 +#define EEPROM_MIDICHANNEL_ADDR 4 #define EEPROM_UPDATE_BANK (1<<0) #define EEPROM_UPDATE_VOICE (1<<1) #define EEPROM_UPDATE_VOL (1<<2) -#define EEPROM_UPDATE_VOL_R (1<<3) -#define EEPROM_UPDATE_VOL_L (1<<4) -#define EEPROM_UPDATE_MIDICHANNEL (1<<5) +#define EEPROM_UPDATE_PAN (1<<3) +#define EEPROM_UPDATE_MIDICHANNEL (1<<4) #define EEPROM_UPDATE_CHECKSUM (1<<7) #define MAX_BANKS 100 @@ -165,7 +163,6 @@ #define BANK_NAME_LEN 13 // FAT12 filenames (plus '\0') #define VOICE_NAME_LEN 11 // 10 (plus '\0') - //************************************************************************************************* //* DO NO CHANGE ANYTHING BEYOND IF YOU DON'T KNOW WHAT YOU ARE DOING !!! //************************************************************************************************* diff --git a/dexed.cpp b/dexed.cpp index 8164cb4..8a0a99e 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/dexed.h b/dexed.h index 4e581c8..02a7383 100644 --- a/dexed.h +++ b/dexed.h @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/dexed_sysex.cpp b/dexed_sysex.cpp index 7fa3396..e1ec493 100644 --- a/dexed_sysex.cpp +++ b/dexed_sysex.cpp @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/dexed_sysex.h b/dexed_sysex.h index d0d771f..e26bea1 100644 --- a/dexed_sysex.h +++ b/dexed_sysex.h @@ -5,7 +5,7 @@ (https://github.com/asb2m10/dexed) for the Teensy-3.5/3.6 with audio shield. Dexed ist heavily based on https://github.com/google/music-synthesizer-for-android - (c)2018 H. Wirtz + (c)2018,2019 H. Wirtz This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by