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

Updating to i2s_audio component #5

Open
mikenorgate opened this issue Apr 28, 2023 · 3 comments
Open

Updating to i2s_audio component #5

mikenorgate opened this issue Apr 28, 2023 · 3 comments

Comments

@mikenorgate
Copy link

Now that ESPHome has an official i2s_audio component https://esphome.io/components/i2s_audio.html do you have any plans to update the sound level meter to use that implementation?

@stas-sl
Copy link
Owner

stas-sl commented Apr 28, 2023

Yeah, I know, it would make sense of course. But unfortunately it lacks a few features for now that I consider rather important. First one is probably quite easy to fix/implement. Currently sample rate/bits per sample are hardcoded there as 16bits@16kHz. Sound meter will of course work with it, but you might need to recalculate all IIR coefficients and probably loose some precision. I don't know how much the difference will be, but I'd prefer rather more precision than less :) I hope, ability to specify audio quality via config will be implemented in the official i2s_audio component at some point.

https://github.com/esphome/esphome/blob/59d6b3afa09c51dc92f036fb8ee746d84489a3ea/esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp#L27-L41

  i2s_driver_config_t config = {
      .mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
      .sample_rate = 16000,
      .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
      .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT,
      .communication_format = I2S_COMM_FORMAT_STAND_I2S,
      .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
      .dma_buf_count = 4,
      .dma_buf_len = 256,
      .use_apll = false,
      .tx_desc_auto_clear = false,
      .fixed_mclk = 0,
      .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
      .bits_per_chan = I2S_BITS_PER_CHAN_DEFAULT,
  };

Second feature is probably more complicated. Currently I'm reading audio data in a separate FreeRTOS task, which means that it can read/process audio even if there are other long running tasks in parallel (like HTTP/MQTT requests). Depending on your config/setup you might have or have not them, but I do have and I'd like not to loose audio data.

Considering these 2 issues, I'd say I don't plan to use official i2s_audio for now, but if it will change in future, I can change my mind :)

@wojciechczyz
Copy link

Hi Stas,

bits_per_sample was added recently. Hopefully, sample rate would come soon too:
esphome/feature-requests#2289

Cheers!

@karrui
Copy link

karrui commented Jun 11, 2024

For those tracking this, sample_rate seems to have been added!

@stas-sl would this be good enough for i2s_audio support?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants