From 08eb9dd022ec0fc7b6e6aab9514d93f66fe3dcaa Mon Sep 17 00:00:00 2001 From: Jason Gaunt Date: Tue, 11 May 2021 02:36:24 +0100 Subject: [PATCH] Added alternative volume scaling mode Adds a user-configurable option to change the volume scaling - adds more volume linearity when listening with devices such as headphones --- README.md | 1 + src/defaultprefs.h | 3 +- src/main.cpp | 78 +++++++++++++++++++++++------------- tools/Esp32_radio_init.ino | 3 +- tools/Esp32_radio_init.ino.c | 13 +++--- 5 files changed, 62 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 986c8c3..0a7c9f8 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Features: See documentation in doc/pdf-file. Last changes: +- 11-may-2021, Added alternative volume scaling for use with headphones - 29-apr-2021, Fixed SSD1309 bug. - 25-apr-2021, Fixed SSD1309 bug, thanks to Juraj Liso. - 19-feb-2021, More Oled models. diff --git a/src/defaultprefs.h b/src/defaultprefs.h index c84d4e1..f97f7d4 100644 --- a/src/defaultprefs.h +++ b/src/defaultprefs.h @@ -22,6 +22,7 @@ wifi_00 = SSID1/PASSWD1 wifi_01 = SSID2/PASSWD2 # volume = 72 +volaltscale = 0 toneha = 0 tonehf = 0 tonela = 0 @@ -63,4 +64,4 @@ pin_sd_cs = 21 # GPIO Pin number for SD ca pin_vs_cs = 5 # GPIO Pin number for VS1053 "CS" pin_vs_dcs = 32 # GPIO Pin number for VS1053 "DCS" pin_vs_dreq = 4 # GPIO Pin number for VS1053 "DREQ" -)=====" ; +)=====" ; diff --git a/src/main.cpp b/src/main.cpp index 62e80f7..fe37857 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -163,6 +163,7 @@ // 19-02-2021, ES: More Oled models. // 25-04-2021, ES: Fixed playlist bug. // 29-04-2021, ES: Fixed SSD1309 bug, thanks to Juraj Liso. +// 11-05-2021, ES: Added alternative volume scaling, thanks to Jason Gaunt. // Define the version number, also used for webserver as Last-Modified header and to // check version for update. The format must be exactly as specified by the HTTP standard! @@ -302,6 +303,7 @@ struct ini_struct uint8_t reqvol ; // Requested volume uint8_t rtone[4] ; // Requested bass/treble settings int16_t newpreset ; // Requested preset + int8_t volaltscale ; // Alternative volume scaling mode String clk_server ; // Server to be used for time of day clock int8_t clk_offset ; // Offset in hours with respect to UTC int8_t clk_dst ; // Number of hours shift during DST @@ -998,7 +1000,13 @@ void VS1053::setVolume ( uint8_t vol ) if ( vol != curvol ) { curvol = vol ; // Save for later use - value = map ( vol, 0, 100, 0xF8, 0x00 ) ; // 0..100% to one channel + value = vol ; + if (( ini_block.volaltscale == 1 ) && ( vol > 0 ) ) + { + value = ( value / 2 ) + 50 ; + dbgprint ( "Volume scaling active, requested %d, scaling to %d", vol, value ) ; + } + value = map ( value, 0, 100, 0xF8, 0x00 ) ; // 0..100% to one channel value = ( value << 8 ) | value ; write_register ( SCI_VOL, value ) ; // Volume left and right if ( vol == 0 ) // Completely silence? @@ -3334,6 +3342,7 @@ void setup() ini_block.clk_dst = 1 ; // DST is +1 hour ini_block.bat0 = 0 ; // Battery ADC levels not yet defined ini_block.bat100 = 0 ; + ini_block.volaltscale = 0 ; // Default volume scaling is linear readIOprefs() ; // Read pins used for SPI, TFT, VS1053, IR, // Rotary encoder for ( i = 0 ; (pinnr = progpin[i].gpio) >= 0 ; i++ ) // Check programmable input pins @@ -4993,45 +5002,46 @@ const char* analyzeCmd ( const char* str ) //************************************************************************************************** -// A N A L Y Z E C M D * +// A N A L Y Z E C M D * //************************************************************************************************** // Handling of the various commands from remote webclient, serial or MQTT. * // par holds the parametername and val holds the value. * // "wifi_00" and "preset_00" may appear more than once, like wifi_01, wifi_02, etc. * // Examples with available parameters: * -// preset = 12 // Select start preset to connect to * -// preset_00 = // Specify station for a preset 00-max *) * -// volume = 95 // Percentage between 0 and 100 * -// upvolume = 2 // Add percentage to current volume * -// downvolume = 2 // Subtract percentage from current volume * -// toneha = <0..15> // Setting treble gain * -// tonehf = <0..15> // Setting treble frequency * -// tonela = <0..15> // Setting bass gain * -// tonelf = <0..15> // Setting treble frequency * -// station = // Select new station (will not be saved) * -// station = .mp3 // Play standalone .mp3 file (not saved) * -// station = .m3u // Select playlist (will not be saved) * +// preset = 12 // Select start preset to connect to * +// preset_00 = // Specify station for a preset 00-max *) * +// volume = 95 // Percentage between 0 and 100 * +// volaltscale = 0 // Alternative volume scaling, 0 = default, 1 = scaled * +// upvolume = 2 // Add percentage to current volume * +// downvolume = 2 // Subtract percentage from current volume * +// toneha = <0..15> // Setting treble gain * +// tonehf = <0..15> // Setting treble frequency * +// tonela = <0..15> // Setting bass gain * +// tonelf = <0..15> // Setting treble frequency * +// station = // Select new station (will not be saved) * +// station = .mp3 // Play standalone .mp3 file (not saved) * +// station = .m3u // Select playlist (will not be saved) * // stop // Stop playing * // resume // Resume playing * // mute // Mute/unmute the music (toggle) * -// wifi_00 = mySSID/mypassword // Set WiFi SSID and password *) * -// mqttbroker = mybroker.com // Set MQTT broker to use *) * -// mqttprefix = XP93g // Set MQTT broker to use * -// mqttport = 1883 // Set MQTT port to use, default 1883 *) * -// mqttuser = myuser // Set MQTT user for authentication *) * -// mqttpasswd = mypassword // Set MQTT password for authentication *) * -// clk_server = pool.ntp.org // Time server to be used *) * -// clk_offset = <-11..+14> // Offset with respect to UTC in hours *) * -// clk_dst = <1..2> // Offset during daylight saving time in hours *) * -// mp3track = // Play track from SD card, nodeID 0 = random * +// wifi_00 = mySSID/mypassword // Set WiFi SSID and password *) * +// mqttbroker = mybroker.com // Set MQTT broker to use *) * +// mqttprefix = XP93g // Set MQTT broker to use * +// mqttport = 1883 // Set MQTT port to use, default 1883 *) * +// mqttuser = myuser // Set MQTT user for authentication *) * +// mqttpasswd = mypassword // Set MQTT password for authentication *) * +// clk_server = pool.ntp.org // Time server to be used *) * +// clk_offset = <-11..+14> // Offset with respect to UTC in hours *) * +// clk_dst = <1..2> // Offset during daylight saving time in hours *) * +// mp3track = // Play track from SD card, nodeID 0 = random * // settings // Returns setting like presets and tone * // status // Show current URL to play * // test // For test purposes * -// debug = 0 or 1 // Switch debugging on or off * +// debug = 0 or 1 // Switch debugging on or off * // reset // Restart the ESP32 * -// bat0 = 2318 // ADC value for an empty battery * -// bat100 = 2916 // ADC value for a fully charged battery * -// fs = USB or SD // Select local filesystem for MP# player mode. * +// bat0 = 2318 // ADC value for an empty battery * +// bat100 = 2916 // ADC value for a fully charged battery * +// fs = USB or SD // Select local filesystem for MP# player mode. * // Commands marked with "*)" are sensible during initialization only * //************************************************************************************************** const char* analyzeCmd ( const char* par, const char* val ) @@ -5107,6 +5117,18 @@ const char* analyzeCmd ( const char* par, const char* val ) sprintf ( reply, "Volume is now %d", // Reply new volume ini_block.reqvol ) ; } + else if ( argument.indexOf ( "volaltscale" ) >= 0 ) // Alternative volume scaling request + { + ini_block.volaltscale = ivalue ; + if ( ini_block.volaltscale >= 1 ) + { + ini_block.volaltscale = 1 ; + } + else + { + ini_block.volaltscale = 0 ; + } + } else if ( argument == "mute" ) // Mute/unmute request { muteflag = !muteflag ; // Request volume to zero/normal diff --git a/tools/Esp32_radio_init.ino b/tools/Esp32_radio_init.ino index ba1f06b..d504bc4 100644 --- a/tools/Esp32_radio_init.ino +++ b/tools/Esp32_radio_init.ino @@ -41,6 +41,7 @@ void setup() preferences.putString ( "wifi_01", "SSID2/YYYYYY" ) ; // preferences.putString ( "volume", "72" ) ; + preferences.putString ( "volaltscale", "0" ) ; preferences.putString ( "toneha", "0" ) ; preferences.putString ( "tonehf", "0" ) ; preferences.putString ( "tonela", "0" ) ; @@ -94,4 +95,4 @@ void loop() Serial.println ( "ESP32_radio_init completed..." ) ; delay ( 10000 ) ; } - + diff --git a/tools/Esp32_radio_init.ino.c b/tools/Esp32_radio_init.ino.c index 0d790be..9f8d951 100644 --- a/tools/Esp32_radio_init.ino.c +++ b/tools/Esp32_radio_init.ino.c @@ -39,11 +39,12 @@ void setup() preferences.putString ( "wifi_00", "NETGEAR-11/DEADC0DE11" ) | preferences.putString ( "wifi_01", "ADSL-11/DEADC0DE11" ) | // - preferences.putString ( "volume", "72" ) | - preferences.putString ( "toneha", "0" ) | - preferences.putString ( "tonehf", "0" ) | - preferences.putString ( "tonela", "0" ) | - preferences.putString ( "tonelf", "0" ) | + preferences.putString ( "volume", "72" ) | + preferences.putString ( "volaltscale", "0" ) | + preferences.putString ( "toneha", "0" ) | + preferences.putString ( "tonehf", "0" ) | + preferences.putString ( "tonela", "0" ) | + preferences.putString ( "tonelf", "0" ) | // preferences.putString ( "preset", "6" ) | preferences.putString ( "preset_00", "109.206.96.34:8100 # 0 - NAXI LOVE RADIO, Belgrade, Serbia" ) ; @@ -75,4 +76,4 @@ void loop() Serial.println ( "ESP32_radio_init completed..." ) ; delay ( 10000 ) ; } - +