forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Audio for Core3, MP3Stream and Shine (arendst#20540)
- Loading branch information
1 parent
6b4254a
commit 30c3165
Showing
6 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
tasmota/tasmota_xdrv_driver/xdrv_42_2_i2s_mp3stream_idf51.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
xdrv_42_2_i2s_mp3stream_idf51.ino - Audio dac support for Tasmota | ||
Copyright (C) 2024 Gerhard Mutz and Theo Arends | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#if defined(ESP32) && ESP_IDF_VERSION_MAJOR >= 5 | ||
#if defined(USE_I2S_AUDIO) && defined(USE_SHINE) && defined(MP3_MIC_STREAM) | ||
|
||
#ifndef MP3_STREAM_PORT | ||
#define MP3_STREAM_PORT 81 | ||
#endif | ||
|
||
|
||
void Stream_mp3(void) { | ||
if (!audio_i2s.Settings->tx.stream_enable) { | ||
return; | ||
} | ||
|
||
if (audio_i2s_mp3.stream_active) { | ||
return; | ||
} | ||
AddLog(LOG_LEVEL_INFO, PSTR("I2S: Handle mp3server")); | ||
audio_i2s_mp3.stream_active = 1; | ||
audio_i2s_mp3.client = audio_i2s_mp3.MP3Server->client(); | ||
AddLog(LOG_LEVEL_INFO, PSTR("I2S: Create client")); | ||
i2s_record_shine((char*)"stream.mp3"); | ||
} | ||
|
||
void I2sMp3Loop(void) { | ||
if (audio_i2s_mp3.MP3Server) { | ||
audio_i2s_mp3.MP3Server->handleClient(); | ||
} | ||
} | ||
|
||
void I2sMp3Init(uint32_t on) { | ||
if (on) { | ||
if (!audio_i2s_mp3.MP3Server) { | ||
audio_i2s_mp3.MP3Server = new ESP8266WebServer(MP3_STREAM_PORT); | ||
audio_i2s_mp3.MP3Server->on(PSTR("/stream.mp3"), Stream_mp3); | ||
audio_i2s_mp3.MP3Server->on(PSTR("/stream.m3a"), Stream_mp3); | ||
audio_i2s_mp3.MP3Server->begin(); | ||
AddLog(LOG_LEVEL_INFO, PSTR("MP3: server created on port: %d "), MP3_STREAM_PORT); | ||
} | ||
} else { | ||
if (audio_i2s_mp3.MP3Server) { | ||
audio_i2s_mp3.MP3Server->stop(); | ||
delete audio_i2s_mp3.MP3Server; | ||
audio_i2s_mp3.MP3Server = nullptr; | ||
AddLog(LOG_LEVEL_INFO, PSTR("MP3: server deleted")); | ||
} | ||
} | ||
} | ||
|
||
|
||
void CmndI2SMP3Stream(void) { | ||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { | ||
audio_i2s_mp3.stream_enable = XdrvMailbox.payload; | ||
} | ||
I2sMp3Init(audio_i2s_mp3.stream_enable); | ||
ResponseCmndNumber(audio_i2s_mp3.stream_enable); | ||
} | ||
|
||
#endif // defined(USE_I2S_AUDIO) && defined(USE_SHINE) && defined(MP3_MIC_STREAM) | ||
#endif // defined(ESP32) && ESP_IDF_VERSION_MAJOR >= 5 |