Skip to content

Commit

Permalink
i2s audio ,some improvements (#21433)
Browse files Browse the repository at this point in the history
  • Loading branch information
Staars committed May 18, 2024
1 parent 285a6f3 commit 0e5b2a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_0_config_idf51.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ typedef struct{
struct {
uint32_t sample_rate = 32000; // B00-03 - 32000 is compatible with MP3 encoding
uint16_t gain = 30 * 16; // B04-05 - in Q12.4
#if SOC_I2S_SUPPORTS_PDM_RX
uint8_t mode = I2S_MODE_PDM; // B06 - I2S mode standard, PDM, TDM, DAC
#else
uint8_t mode = I2S_MODE_STD; // B06 - I2S mode standard, PDM, TDM, DAC
#endif
uint8_t slot_mask = BIT(0); // B07 - slot mask = left/right/both depended on mode, so BIT(0) maybe left or right
uint8_t slot_bit_width = I2S_SLOT_BIT_WIDTH_32BIT; // B08 - auto equals data_bit_width - can differ from bits per sample e.g. INMP441
uint8_t channels = 1; // B09 - mono/stereo - 1 is added for both
Expand Down
8 changes: 6 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_42_0_i2s_audio_idf51.ino
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void I2sMicTask(void *arg){
}

ctime = TasmotaGlobal.uptime;
timeForOneRead = 1000 / ((audio_i2s.Settings->rx.sample_rate / samples_per_pass));
timeForOneRead = 1000 / ((audio_i2s.Settings->rx.sample_rate / (samples_per_pass * audio_i2s.Settings->rx.channels )));
timeForOneRead -= 1; // be very in time

AddLog(LOG_LEVEL_DEBUG, PSTR("I2S: samples %u, bytesize %u, time: %u"),samples_per_pass, bytesize, timeForOneRead);
Expand Down Expand Up @@ -1027,7 +1027,11 @@ void CmndI2SI2SRtttl(void) {
}

void CmndI2SMicRec(void) {
if (audio_i2s.Settings->sys.mp3_preallocate == 1) {
if (audio_i2s_mp3.mp3ram == nullptr){
AddLog(LOG_LEVEL_DEBUG,PSTR("I2S: try late buffer allocation for mp3 encoder"));
audio_i2s_mp3.mp3ram = special_malloc(preallocateCodecSize);
}
if (audio_i2s_mp3.mp3ram != nullptr) {
if (XdrvMailbox.data_len > 0) {
if (!strncmp(XdrvMailbox.data, "-?", 2)) {
Response_P("{\"I2SREC-duration\":%d}", audio_i2s_mp3.recdur);
Expand Down

0 comments on commit 0e5b2a8

Please sign in to comment.