vol steps 0..256

This commit is contained in:
e2002
2022-02-07 10:46:29 +03:00
parent d75544e5f4
commit 4824d651d2
3 changed files with 23 additions and 15 deletions

View File

@@ -8,8 +8,8 @@
#include "network.h" #include "network.h"
//#define DSP_DUMMY //#define DSP_DUMMY
#define DSP_ST7735 //#define DSP_ST7735
//#define DSP_SSD1306 #define DSP_SSD1306
#ifdef DSP_DUMMY #ifdef DSP_DUMMY
#include "src/displays/displayDummy.h" #include "src/displays/displayDummy.h"

View File

@@ -1,7 +1,7 @@
#ifndef options_h #ifndef options_h
#define options_h #define options_h
#define VERSION "0.4.177" #define VERSION "0.4.180"
/* /*
* TFT DISPLAY * TFT DISPLAY
@@ -27,21 +27,27 @@
/* /*
* I2S DAC * I2S DAC
*/ */
/*
#define I2S_DOUT 27 // DIN connection #define I2S_DOUT 27 // DIN connection
#define I2S_BCLK 26 // BCLK Bit clock #define I2S_BCLK 26 // BCLK Bit clock
#define I2S_LRC 25 // WSEL Left Right Clock #define I2S_LRC 25 // WSEL Left Right Clock
/*/
#define I2S_DOUT 22 // DIN connection
#define I2S_BCLK 26 // BCLK Bit clock
#define I2S_LRC 25 // WSEL Left Right Clock
//*/
/* /*
* ENCODER * ENCODER
*/ */
#define ENC_BTNL 13 #define ENC_BTNL 13
#define ENC_BTNB 12 #define ENC_BTNB 13
#define ENC_BTNR 14 #define ENC_BTNR 14
/* /*
* BUTTONS * BUTTONS
*/ */
#define BTN_LEFT 32 #define BTN_LEFT 32
#define BTN_CENTER 31 #define BTN_CENTER 14
#define BTN_RIGHT 33 #define BTN_RIGHT 33
/* /*
* ESP DEVBOARD * ESP DEVBOARD

View File

@@ -550,7 +550,7 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
} }
const uint32_t TIMEOUT_MS_SSL{3700}; const uint32_t TIMEOUT_MS_SSL{3700};
if(m_f_ssl == true) { if(m_f_ssl == true) {
uint32_t t = millis(); uint32_t t = millis();
if(clientsecure.connect(hostwoext, port, TIMEOUT_MS_SSL)) { if(clientsecure.connect(hostwoext, port, TIMEOUT_MS_SSL)) {
@@ -4244,37 +4244,39 @@ void Audio::setBalance(int8_t bal){ // bal -16...16
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void Audio::setVolume(uint8_t vol) { // vol 22 steps, 0...21 void Audio::setVolume(uint8_t vol) { // vol 22 steps, 0...21
//if(vol > 21) vol = 21; if(vol > 256) vol = 256;
//volume = map(eeprom_config.volume, 0, 21, 0, 255); //volume = map(eeprom_config.volume, 0, 21, 0, 255);
m_vol = map(vol, 0, 254, 0, 64); //m_vol = map(vol, 0, 254, 0, 64);
m_vol = vol;
//m_vol = volumetable[vol]; //m_vol = volumetable[vol];
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
uint8_t Audio::getVolume() { uint8_t Audio::getVolume() {
return map(m_vol, 0, 64, 0, 254); return m_vol;
/*return map(m_vol, 0, 64, 0, 254);
for(uint8_t i = 0; i < 22; i++) { for(uint8_t i = 0; i < 22; i++) {
if(volumetable[i] == m_vol) return i; if(volumetable[i] == m_vol) return i;
} }
m_vol = 12; // if m_vol not found in table m_vol = 12; // if m_vol not found in table
return m_vol; return m_vol;*/
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int32_t Audio::Gain(int16_t s[2]) { int32_t Audio::Gain(int16_t s[2]) {
int32_t v[2]; int32_t v[2];
float step = (float)m_vol /64; float step = (float)m_vol /254;
uint8_t l = 0, r = 0; uint8_t l = 0, r = 0;
if(m_balance < 0){ if(m_balance < 0){
step = step * (float)(abs(m_balance) * 4); step = step * (float)(abs(m_balance) * 16);
l = (uint8_t)(step); l = (uint8_t)(step);
} }
if(m_balance > 0){ if(m_balance > 0){
step = step * m_balance * 4; step = step * m_balance * 16;
r = (uint8_t)(step); r = (uint8_t)(step);
} }
v[LEFTCHANNEL] = (s[LEFTCHANNEL] * (m_vol - l)) >> 6; v[LEFTCHANNEL] = (s[LEFTCHANNEL] * (m_vol - l)) >> 8;
v[RIGHTCHANNEL]= (s[RIGHTCHANNEL] * (m_vol - r)) >> 6; v[RIGHTCHANNEL]= (s[RIGHTCHANNEL] * (m_vol - r)) >> 8;
return (v[RIGHTCHANNEL] << 16) | (v[LEFTCHANNEL] & 0xffff); return (v[RIGHTCHANNEL] << 16) | (v[LEFTCHANNEL] & 0xffff);
} }