/
Yurask67
/
ESP32C3_AUDIO
Обзор
Документация
Войти
/
Yurask67
/
ESP32C3_AUDIO
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/audio_task.cpp
115 строк
3 KB
Yurask67
переда gain перенесена в очередь
11 дек 2025, 14:30
11 дек 2025, 14:30
e0825c9
Код
Авторство
О чём код?
#include "conf.h" /*-------------task--------------------*/ TaskHandle_t audio; // хендл задачи #define STACK_SIZE 8192 void vAUDIOTask(void *pvParameters); void startAUDIOTask(void) { xTaskCreate(vAUDIOTask, "audio", STACK_SIZE, NULL, 10, &audio); } /*---------------------------------*/ #define I2S_DOUT 8 #define I2S_BCLK 9 #define I2S_LRC 4 const char sound1[] = "/dog1.mp3"; const char sound2[] = "/svist1.mp3"; const char sound3[] = "/dog2.mp3"; const char soundMotion1[] = ""; const char soundMotion2[] = ""; const char soundMotion3[] = ""; AudioFileSourceLittleFS *file; AudioFileSourceID3 *id3; AudioOutputI2S *out; AudioGeneratorMP3 *mp3; File dir, root; String fileName = ""; structSound_t structSound; // для очереди // Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc. void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string) { (void)cbData; Serial.printf("ID3 callback for: %s = '", type); if (isUnicode) { string += 2; } while (*string) { char a = *(string++); if (isUnicode) { string++; } Serial.printf("%c", a); } Serial.printf("'\n"); Serial.flush(); } void playFile(void) { static structSound_t _Sound; // локальная для приема из очереди if (_Sound.count > 0) { _Sound.count--; file->open(_Sound.Track); fileName = _Sound.Track; if (fileName.length() > 0) { id3 = new AudioFileSourceID3(file); id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG"); mp3->begin(id3, out); Serial.printf("Playback of '%s' begins...\n", fileName.c_str()); } else { Serial.println("Can't find .mp3 file in LITTLEFS"); } } else { xQueueReceive(QueueSound, &_Sound, portMAX_DELAY); out->SetGain((float)_Sound.gain / 10); // громкость } } /**********сетап задачи**************/ void setupAUDIOTask(void) { Serial.printf("Sample MP3 playback begins...\n"); audioLogger = &Serial; file = new AudioFileSourceLittleFS(); id3 = NULL; out = new AudioOutputI2S(); out->SetPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); // out->SetGain(0.3); // Горомкость mp3 = new AudioGeneratorMP3(); root = LittleFS.open("/"); } void vAUDIOTask(void *pvParameters) { (void)pvParameters; setupAUDIOTask(); while (1) { if (mp3->isRunning()) { if (!mp3->loop()) { mp3->stop(); } } else { playFile(); Serial.println("MP3 done"); vTaskDelay(20); } } }