Skip to content

Commit 1d02826

Browse files
committed
v0.6.494
1 parent f065d15 commit 1d02826

File tree

14 files changed

+196
-20
lines changed

14 files changed

+196
-20
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,16 @@ Work is in progress...
295295

296296
---
297297
## Version history
298+
#### v0.6.494
299+
- adding VU meter for displays ST7735 160x128, ST7735 128x128, ILI9341 320x240, ST7789 320x240 \
300+
option ENABLE_VU_METER (see [myoptions.h](exsamples/myoptions.h#L113) for exsample) \
301+
**!!! Important !!!** \
302+
if you enable this feathure on the esp32 wroom, due to lack of memory, you must modify the file Arduino/libraries/AsyncTCP/src/AsyncTCP.cpp \
303+
replace the line 221 \
304+
xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE); \
305+
with \
306+
xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 / 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
307+
298308
#### v0.6.450
299309
**!!! a [full update](#update-over-web-interface) with Sketch data upload is required. After updating please press CTRL+F5 in browser !!!**
300310
- adding an IR remote control has been moved to the web-interface (more info in [Controls.md](Controls.md#ir-receiver))

exsamples/myoptions.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,20 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
110110
//#define SNTP_SERVER "pool.ntp.org", "0.ru.pool.ntp.org" /* custom ntp servers min 1 max 3 comma separated values */
111111
//#define I2S_INTERNAL false /* If true - use esp32 internal DAC */
112112
//#define SOFT_AP_REBOOT_DELAY 0 /* Delay in milliseconds after which ESP is rebooting if it is in softAP mode (0 - disabled) */
113-
113+
//#define ENABLE_VU_METER false /* enable? vu meter for some displays */
114+
/*
115+
* !!! Important !!!
116+
* if you enable this feathure on the esp32 wroom, due to lack of memory, you must modify the file Arduino/libraries/AsyncTCP/src/AsyncTCP.cpp
117+
* replace the line 221
118+
* xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
119+
* with
120+
* xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 / 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
121+
*/
122+
/* VU settings. See the default settings for your display in file yoRadio/display_vu.h */
123+
/*****************************************************************************************************************************************************************************/
124+
/* vu left | vu top | band width | band height | band space | num of bands | max samples | horisontal | Max Bands Color | Min Bands Color */
125+
/*****************************************************************************************************************************************************************************/
126+
//#define VU_PARAMS { VU_X = 4, VU_Y = 60, VU_BW = 10, VU_BH = 34, VU_BS = 2, VU_NB = 8, VU_BMS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = SILVER }
114127
/******************************************/
115128

116129
/* IR control */

yoRadio/display.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include "WiFi.h"
44
#include "time.h"
55
#include "display.h"
6-
6+
#if ENABLE_VU_METER
7+
#include "display_vu.h"
8+
#endif
79
#include "player.h"
810
#include "netserver.h"
911
#include "network.h"
@@ -453,6 +455,9 @@ void Display::loop() {
453455
}
454456
dsp.loop();
455457
if (dsp_on_loop) dsp_on_loop(&dsp);
458+
#if ENABLE_VU_METER
459+
drawVU(&dsp);
460+
#endif
456461
}
457462

458463
void Display::centerText(const char* text, byte y, uint16_t fg, uint16_t bg) {

yoRadio/display_vu.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#if ENABLE_VU_METER
2+
#ifndef display_vu_h
3+
#define display_vu_h
4+
#include "player.h"
5+
6+
#ifdef VU_PARAMS
7+
enum : uint16_t VU_PARAMS;
8+
#else
9+
/*****************************************************************************************************************************************************************************/
10+
/* vu left | vu top | band width | band height | band space |num of bands |max samples | horisontal | Max Bands Color | Min Bands Color */
11+
/*****************************************************************************************************************************************************************************/
12+
#if DSP_MODEL==DSP_ST7735 && DTYPE==INITR_BLACKTAB /* ST7735 160x128 */
13+
enum : uint16_t { VU_X = 4, VU_Y = 50, VU_BW = 10, VU_BH = 44, VU_BS = 2, VU_NB = 8, VU_BMS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = SILVER };
14+
#elif DSP_MODEL==DSP_ST7735 && DTYPE==INITR_144GREENTAB /* ST7735 128x128 */
15+
enum : uint16_t { VU_X = 4, VU_Y = 45, VU_BW = 60, VU_BH = 8, VU_BS = 0, VU_NB = 10, VU_BMS = 3, VU_HOR = 1, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
16+
#elif DSP_MODEL==DSP_ILI9341 /* ILI9341 320x240 */
17+
enum : uint16_t { VU_X = 4, VU_Y = 100, VU_BW = 20, VU_BH = 86, VU_BS = 4, VU_NB = 10, VU_BMS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
18+
#elif DSP_MODEL==DSP_ST7789 /* ST7789 320x240 */
19+
enum : uint16_t { VU_X = 4, VU_Y = 100, VU_BW = 20, VU_BH = 86, VU_BS = 4, VU_NB = 10, VU_BMS = 3, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY };
20+
#else
21+
#error YOUR DISPLAY DOES NOT SUPPORT ENABLE_VU_METER FEATURE YET
22+
#endif
23+
#endif //VU_PARAMS
24+
25+
/*****************************************************************************************************************************************************************************/
26+
27+
void drawVU(DspCore *dsp);
28+
29+
GFXcanvas16 gfxc(VU_BW*2+VU_BS,VU_BH);
30+
31+
void drawVU(DspCore *dsp){
32+
if((display.mode!=PLAYER && display.mode!=VOL)) return;
33+
player.getVUlevel();
34+
static uint16_t samples_cnt, measL, measR;
35+
samples_cnt++;
36+
uint16_t dimension = VU_HOR?VU_BW:VU_BH;
37+
uint8_t L = map((VS1053_CS!=255)?player.vuLeft:log(player.vuLeft)*38+45, 255, 0, 0, dimension);
38+
uint8_t R = map((VS1053_CS!=255)?player.vuRight:log(player.vuRight)*38+45, 255, 0, 0, dimension);
39+
if(player.isRunning()){
40+
if(L>measL) measL=L;
41+
if(R>measR) measR=R;
42+
}else{
43+
if(measL<255) measL+=2;
44+
if(measR<255) measR+=2;
45+
}
46+
#if VS1053_CS==255
47+
if(samples_cnt<VU_BMS) return;
48+
#endif
49+
samples_cnt=0;
50+
uint8_t h=(dimension/VU_NB)-2;
51+
for(int i=0; i<dimension; i++){
52+
if(i%(dimension/VU_NB)==0){
53+
if(VU_HOR){
54+
uint16_t bandColor = (i>VU_BW-(VU_BW/VU_NB)*4)?VU_COLOR_MAX:VU_COLOR_MIN;
55+
gfxc.fillRect(i, 0, h, VU_BH, bandColor);
56+
gfxc.fillRect(i+VU_BW+VU_BS, 0, h, VU_BH, bandColor);
57+
}else{
58+
uint16_t bandColor = (i<(VU_BH/VU_NB)*3)?VU_COLOR_MAX:VU_COLOR_MIN;
59+
gfxc.fillRect(0, i, VU_BW, h, bandColor);
60+
gfxc.fillRect(VU_BW+VU_BS, i, VU_BW, h, bandColor);
61+
}
62+
}
63+
}
64+
if(VU_HOR){
65+
gfxc.fillRect(VU_BW-measL, 0, measL, VU_BW, TFT_BG);
66+
gfxc.fillRect(VU_BW*2+VU_BS-measR, 0, measR, VU_BW, TFT_BG);
67+
dsp->drawRGBBitmap (VU_X, VU_Y, gfxc.getBuffer(), 120, VU_BH);
68+
}else{
69+
gfxc.fillRect(0, 0, VU_BW, measL, TFT_BG);
70+
gfxc.fillRect(VU_BW+VU_BS, 0, VU_BW, measR, TFT_BG);
71+
dsp->drawRGBBitmap (VU_X, VU_Y, gfxc.getBuffer(), VU_BW*2+VU_BS, VU_BH);
72+
}
73+
if(player.isRunning()){
74+
measL=0;
75+
measR=0;
76+
}
77+
}
78+
79+
#endif
80+
#endif

yoRadio/options.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef options_h
22
#define options_h
33

4-
#define VERSION "0.6.450"
4+
#define VERSION "0.6.494"
55

66
/*******************************************************
77
DO NOT EDIT THIS FILE.
@@ -225,6 +225,17 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
225225
#ifndef SOFT_AP_REBOOT_DELAY
226226
#define SOFT_AP_REBOOT_DELAY 0 // Delay in ms after which ESP is rebooting if it is in softAP mode (0 - disabled)
227227
#endif
228+
#ifndef ENABLE_VU_METER
229+
#define ENABLE_VU_METER false // enable? vu meter for some displays
230+
/*
231+
* !!! Important !!!
232+
* if you enable this feathure on the esp32 wroom, due to lack of memory, you must modify the file Arduino/libraries/AsyncTCP/src/AsyncTCP.cpp
233+
* replace the line 221
234+
* xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
235+
* with
236+
* xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 / 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
237+
*/
238+
#endif
228239
/*
229240
*** ST7735 display submodel ***
230241
INITR_BLACKTAB // 1.8' https://aliexpress.ru/item/1005002822797745.html

yoRadio/src/audioI2S/Audio.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4269,7 +4269,8 @@ int32_t Audio::Gain(int16_t s[2]) {
42694269
step = step * m_balance * 16;
42704270
r = (uint8_t)(step);
42714271
}
4272-
4272+
vuLeft = s[LEFTCHANNEL] >> 7;
4273+
vuRight = s[RIGHTCHANNEL] >> 7;
42734274
v[LEFTCHANNEL] = (s[LEFTCHANNEL] * (m_vol - l)) >> 8;
42744275
v[RIGHTCHANNEL]= (s[RIGHTCHANNEL] * (m_vol - r)) >> 8;
42754276

yoRadio/src/audioI2S/AudioEx.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ class Audio : private AudioBuffer{
186186
uint32_t getAudioCurrentTime();
187187
uint32_t getTotalPlayingTime();
188188
void setDefaults();
189-
189+
/* VU METER */
190+
void setVUmeter() {};
191+
void getVUlevel() {};
192+
uint8_t vuLeft, vuRight;
190193
SemaphoreHandle_t mutex_pl=NULL;
191194

192195
esp_err_t i2s_mclk_pin_select(const uint8_t pin);

yoRadio/src/audioVS1053/audioVS1053Ex.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ void Audio::begin(){
331331
write_register(SCI_AUDATA, 44100 + 1); // 44.1kHz + stereo
332332
// The next clocksetting allows SPI clocking at 5 MHz, 4 MHz is safe then.
333333
write_register(SCI_CLOCKF, 6 << 12); // Normal clock settings multiplyer 3.0=12.2 MHz
334+
//set vu meter
335+
setVUmeter();
334336
//SPI Clock to 4 MHz. Now you can set high speed SPI clock.
335337
VS1053_SPI=SPISettings(6700000, MSBFIRST, SPI_MODE0); // SPIDIV 12 -> 80/12=6.66 MHz
336338
write_register(SCI_MODE, _BV (SM_SDINEW) | _BV(SM_LINE1));
@@ -353,6 +355,16 @@ size_t Audio::bufferFree(){
353355
return InBuff.freeSpace();
354356
}
355357
//---------------------------------------------------------------------------------------------------------------------
358+
uint32_t Audio::inBufferFilled() {
359+
// current audio input buffer fillsize in bytes
360+
return InBuff.bufferFilled();
361+
}
362+
//---------------------------------------------------------------------------------------------------------------------
363+
uint32_t Audio::inBufferFree() {
364+
// current audio input buffer free space in bytes
365+
return InBuff.freeSpace();
366+
}
367+
//---------------------------------------------------------------------------------------------------------------------
356368

357369
void Audio::setVolume(uint8_t vol){
358370
// Set volume. Both left and right.
@@ -1542,6 +1554,45 @@ void Audio::setDefaults(){
15421554
m_f_tts = false; // text to speech
15431555
m_f_localfile = false;
15441556
}
1557+
//------------------------------------------------------------------------------
1558+
/**
1559+
* \brief enable VSdsp VU Meter
1560+
*
1561+
* \param[in] enable when set will enable the VU meter
1562+
*
1563+
* Writes the SS_VU_ENABLE bit of the SCI_STATUS register to enable VU meter on
1564+
* board to the VSdsp.
1565+
*
1566+
* See data patches data sheet VU meter for details.
1567+
* \warning This feature is only available with patches that support VU meter.
1568+
* \n The VU meter takes about 0.2MHz of processing power with 48 kHz samplerate.
1569+
*/
1570+
void Audio::setVUmeter() {
1571+
if(!ENABLE_VU_METER) return;
1572+
uint16_t MP3Status = read_register(SCI_STATUS);
1573+
write_register(SCI_STATUS, MP3Status | _BV(9));
1574+
}
1575+
1576+
//------------------------------------------------------------------------------
1577+
/**
1578+
* \brief get current measured VU Meter
1579+
*
1580+
* Returns the calculated peak sample values from both channels in 3 dB
1581+
* increaments through. Where the high byte represent the left channel,
1582+
* and the low bytes the right channel.
1583+
*
1584+
* Values from 0 to 31 are valid for both channels.
1585+
*
1586+
* \warning This feature is only available with patches that support VU meter.
1587+
*/
1588+
void Audio::getVUlevel() {
1589+
if(!ENABLE_VU_METER) return;
1590+
int16_t reg = read_register(SCI_AICTRL3);
1591+
uint8_t rl = map((uint8_t)reg, 81, 92, 0, 255);
1592+
uint8_t rr = map((uint8_t)(reg >> 8), 81, 92, 0, 255);
1593+
if(rl>30 || !isRunning()) vuLeft = rl;
1594+
if(rr>30 || !isRunning()) vuRight = rr;
1595+
}
15451596
//---------------------------------------------------------------------------------------------------------------------
15461597
bool Audio::connecttohost(String host){
15471598
return connecttohost(host.c_str());

yoRadio/src/audioVS1053/audioVS1053Ex.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ class Audio : private AudioBuffer{
241241
void loadUserCode();
242242

243243

244-
245244
public:
246245
// Constructor. Only sets pin values. Doesn't touch the chip. Be sure to call begin()!
247246
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 @@ class Audio : private AudioBuffer{
269268
SemaphoreHandle_t mutex_pl=NULL;
270269
size_t bufferFilled();
271270
size_t bufferFree();
271+
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
272+
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer
272273
bool isRunning() {/*Serial.printf("m_f_running=%d\n", m_f_running); */return m_f_running;}
273274
void setBalance(int8_t bal = 0);
274275
void setTone(int8_t gainLowPass, int8_t gainBandPass, int8_t gainHighPass);
275276
void setDefaults();
276277
void forceMono(bool m) {} // TODO
278+
/* VU METER */
279+
void setVUmeter();
280+
void getVUlevel();
281+
uint8_t vuLeft, vuRight;
277282
// implement several function with respect to the index of string
278283
bool startsWith (const char* base, const char* str) { return (strstr(base, str) - base) == 0;}
279284
bool endsWith (const char* base, const char* str) {

yoRadio/src/displays/displayILI9225.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,13 @@ void DspCore::displayHeapForDebug() {
284284
fillRect(TFT_FRAMEWDT, vTop, swidth - TFT_FRAMEWDT / 2, 7, TFT_BG);
285285
sprintf(buf, "%d / %d", ESP.getFreeHeap(), ESP.getMaxAllocHeap());
286286
print(buf);
287-
#if VS1053_CS==255
288287
// audio buffer;
289288
fillRect(0, sheight - 2, swidth, 2, TFT_BG);
290289
int astored = player.inBufferFilled();
291290
int afree = player.inBufferFree();
292291
int aprcnt = 100 * astored / (astored + afree);
293292
byte sbw = map(aprcnt, 0, 100 , 0, swidth);
294293
fillRect(0, sheight - 2, sbw, 2, SILVER);
295-
#endif
296294
}
297295

298296
void DspCore::printClock(const char* timestr) {

0 commit comments

Comments
 (0)