Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2s audio, some small improvements #21433

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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