Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added alternative volume scaling mode #462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/defaultprefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ wifi_00 = SSID1/PASSWD1
wifi_01 = SSID2/PASSWD2
#
volume = 72
volaltscale = 0
toneha = 0
tonehf = 0
tonela = 0
Expand Down Expand Up @@ -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"
)=====" ;
)=====" ;
78 changes: 50 additions & 28 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = <mp3 stream> // 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 = <mp3 stream> // Select new station (will not be saved) *
// station = <URL>.mp3 // Play standalone .mp3 file (not saved) *
// station = <URL>.m3u // Select playlist (will not be saved) *
// preset = 12 // Select start preset to connect to *
// preset_00 = <mp3 stream> // 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 = <mp3 stream> // Select new station (will not be saved) *
// station = <URL>.mp3 // Play standalone .mp3 file (not saved) *
// station = <URL>.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 = <nodeID> // 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 = <nodeID> // 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 )
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tools/Esp32_radio_init.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ;
Expand Down Expand Up @@ -94,4 +95,4 @@ void loop()
Serial.println ( "ESP32_radio_init completed..." ) ;
delay ( 10000 ) ;
}

13 changes: 7 additions & 6 deletions tools/Esp32_radio_init.ino.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ;
Expand Down Expand Up @@ -75,4 +76,4 @@ void loop()
Serial.println ( "ESP32_radio_init completed..." ) ;
delay ( 10000 ) ;
}