Skip to content

Commit

Permalink
introdice timemanagement for local files
Browse files Browse the repository at this point in the history
log AudioCurrentTime and AudioFileDuration every second
  • Loading branch information
schreibfaul1 committed Apr 8, 2024
1 parent c54ba4c commit a6779e6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
25 changes: 23 additions & 2 deletions src/audiotask.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// created: 10.02.2022
// updated: 05.04.2024
// updated: 08.04.2024

#include "common.h"
#include "SPIFFS.h"
Expand All @@ -14,7 +14,7 @@ extern SemaphoreHandle_t mutex_rtc;

enum : uint8_t { SET_VOLUME, GET_VOLUME, GET_BITRATE, CONNECTTOHOST, CONNECTTOFS, STOPSONG, SETTONE, INBUFF_FILLED,
INBUFF_FREE, INBUFF_SIZE, ISRUNNING, HIGHWATERMARK, GET_CODEC, PAUSERESUME, CONNECTION_TIMEOUT, GET_FILESIZE,
GET_FILEPOSITION, GET_VULEVEL};
GET_FILEPOSITION, GET_VULEVEL, GET_AUDIOFILEDURATION, GET_AUDIOCURRENTTIME};

struct audioMessage{
uint8_t cmd;
Expand Down Expand Up @@ -154,6 +154,16 @@ void audioTask(void *parameter) {
audioTxTaskMessage.ret = audio.getVUlevel();
xQueueSend(audioGetQueue, &audioTxTaskMessage, portMAX_DELAY);
}
else if(audioRxTaskMessage.cmd == GET_AUDIOFILEDURATION){
audioTxTaskMessage.cmd = GET_AUDIOFILEDURATION;
audioTxTaskMessage.ret = audio.getAudioFileDuration();
xQueueSend(audioGetQueue, &audioTxTaskMessage, portMAX_DELAY);
}
else if(audioRxTaskMessage.cmd == GET_AUDIOCURRENTTIME){
audioTxTaskMessage.cmd = GET_AUDIOCURRENTTIME;
audioTxTaskMessage.ret = audio.getAudioCurrentTime();
xQueueSend(audioGetQueue, &audioTxTaskMessage, portMAX_DELAY);
}
else{
SerialPrintfln(ANSI_ESC_RED "Error: unknown audioTaskMessage");
}
Expand Down Expand Up @@ -316,3 +326,14 @@ uint16_t audioGetVUlevel(){
return RX.ret;
}

uint32_t audioGetFileDuration(){
audioTxMessage.cmd = GET_AUDIOFILEDURATION;
audioMessage RX = transmitReceive(audioTxMessage);
return RX.ret;
}

uint32_t audioGetCurrentTime(){
audioTxMessage.cmd = GET_AUDIOCURRENTTIME;
audioMessage RX = transmitReceive(audioTxMessage);
return RX.ret;
}
4 changes: 3 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// created: 10.Feb.2022
// updated: 08.Feb 2024
// updated: 08.Apr 2024

#pragma once
#pragma GCC optimize("Os") // optimize for code size
Expand Down Expand Up @@ -252,3 +252,5 @@ void audioConnectionTimeout(uint32_t timeout_ms, uint32_t timeout_ms_ssl);
uint32_t audioGetFileSize();
uint32_t audioGetFilePosition();
uint16_t audioGetVUlevel();
uint32_t audioGetFileDuration();
uint32_t audioGetCurrentTime();
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
MiniWebRadio -- Webradio receiver for ESP32
first release on 03/2017 */String Version ="\
Version 3.01 Apr 05/2024 ";
Version 3.01a Apr 08/2024 ";

/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
3.5" color display (480x320px) wiht controller ILI9486 or ILI9488 (SPI)
Expand Down Expand Up @@ -72,6 +72,8 @@ uint32_t _playlistTime = 0; // playlist start time millis() for time
uint32_t _settingsHash = 0;
uint32_t _audioFileSize = 0;
uint32_t _media_downloadPort = 0;
uint32_t _audioCurrentTime = 0;
uint32_t _audioFileDuration = 0;
uint8_t _resetResaon = (esp_reset_reason_t) ESP_RST_UNKNOWN;
const char* _pressBtn[8];
const char* _releaseBtn[8];
Expand Down Expand Up @@ -3038,6 +3040,12 @@ void loop() {
else { SerialPrintfln("Headphone unplugged"); }
_f_hpChanged = false;
}
if(audioIsRunning() && _f_isFSConnected){
_audioCurrentTime = audioGetCurrentTime();
_audioFileDuration = audioGetFileDuration();
SerialPrintfln("AUDIO_FILE: " ANSI_ESC_GREEN "AudioCurrentTime " ANSI_ESC_GREEN "%li, "
ANSI_ESC_GREEN "AudioFileDuration " ANSI_ESC_GREEN "%li", _audioCurrentTime, _audioFileDuration);
}
}
if(_commercial_dur > 0) {
_commercial_dur--;
Expand Down

0 comments on commit a6779e6

Please sign in to comment.