This commit is contained in:
e2002
2022-07-15 13:44:08 +03:00
parent f065d1505d
commit 1d02826166
14 changed files with 196 additions and 20 deletions

View File

@@ -331,6 +331,8 @@ void Audio::begin(){
write_register(SCI_AUDATA, 44100 + 1); // 44.1kHz + stereo
// The next clocksetting allows SPI clocking at 5 MHz, 4 MHz is safe then.
write_register(SCI_CLOCKF, 6 << 12); // Normal clock settings multiplyer 3.0=12.2 MHz
//set vu meter
setVUmeter();
//SPI Clock to 4 MHz. Now you can set high speed SPI clock.
VS1053_SPI=SPISettings(6700000, MSBFIRST, SPI_MODE0); // SPIDIV 12 -> 80/12=6.66 MHz
write_register(SCI_MODE, _BV (SM_SDINEW) | _BV(SM_LINE1));
@@ -353,6 +355,16 @@ size_t Audio::bufferFree(){
return InBuff.freeSpace();
}
//---------------------------------------------------------------------------------------------------------------------
uint32_t Audio::inBufferFilled() {
// current audio input buffer fillsize in bytes
return InBuff.bufferFilled();
}
//---------------------------------------------------------------------------------------------------------------------
uint32_t Audio::inBufferFree() {
// current audio input buffer free space in bytes
return InBuff.freeSpace();
}
//---------------------------------------------------------------------------------------------------------------------
void Audio::setVolume(uint8_t vol){
// Set volume. Both left and right.
@@ -1542,6 +1554,45 @@ void Audio::setDefaults(){
m_f_tts = false; // text to speech
m_f_localfile = false;
}
//------------------------------------------------------------------------------
/**
* \brief enable VSdsp VU Meter
*
* \param[in] enable when set will enable the VU meter
*
* Writes the SS_VU_ENABLE bit of the SCI_STATUS register to enable VU meter on
* board to the VSdsp.
*
* See data patches data sheet VU meter for details.
* \warning This feature is only available with patches that support VU meter.
* \n The VU meter takes about 0.2MHz of processing power with 48 kHz samplerate.
*/
void Audio::setVUmeter() {
if(!ENABLE_VU_METER) return;
uint16_t MP3Status = read_register(SCI_STATUS);
write_register(SCI_STATUS, MP3Status | _BV(9));
}
//------------------------------------------------------------------------------
/**
* \brief get current measured VU Meter
*
* Returns the calculated peak sample values from both channels in 3 dB
* increaments through. Where the high byte represent the left channel,
* and the low bytes the right channel.
*
* Values from 0 to 31 are valid for both channels.
*
* \warning This feature is only available with patches that support VU meter.
*/
void Audio::getVUlevel() {
if(!ENABLE_VU_METER) return;
int16_t reg = read_register(SCI_AICTRL3);
uint8_t rl = map((uint8_t)reg, 81, 92, 0, 255);
uint8_t rr = map((uint8_t)(reg >> 8), 81, 92, 0, 255);
if(rl>30 || !isRunning()) vuLeft = rl;
if(rr>30 || !isRunning()) vuRight = rr;
}
//---------------------------------------------------------------------------------------------------------------------
bool Audio::connecttohost(String host){
return connecttohost(host.c_str());

View File

@@ -241,7 +241,6 @@ protected:
void loadUserCode();
public:
// Constructor. Only sets pin values. Doesn't touch the chip. Be sure to call begin()!
Audio ( uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin, uint8_t spi = VSPI, uint8_t mosi = 23, uint8_t miso = 19, uint8_t sclk = 18);
@@ -269,11 +268,17 @@ public:
SemaphoreHandle_t mutex_pl=NULL;
size_t bufferFilled();
size_t bufferFree();
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer
bool isRunning() {/*Serial.printf("m_f_running=%d\n", m_f_running); */return m_f_running;}
void setBalance(int8_t bal = 0);
void setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass);
void setDefaults();
void forceMono(bool m) {} // TODO
/* VU METER */
void setVUmeter();
void getVUlevel();
uint8_t vuLeft, vuRight;
// implement several function with respect to the index of string
bool startsWith (const char* base, const char* str) { return (strstr(base, str) - base) == 0;}
bool endsWith (const char* base, const char* str) {