i2s audio ,some improvements (#21433)

This commit is contained in:
Christian Baars 2024-05-18 22:15:59 +02:00 committed by GitHub
parent 285a6f3532
commit 0e5b2a86b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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);
@ -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);