stas-sl / esphome-sound-level-meter

77 stars 14 forks source link

Configurable channel (left/right) #20

Closed RaymiiOrg closed 7 months ago

RaymiiOrg commented 8 months ago

Made the channel configurable in the YAML. I'm unfamiliair with the python code so for that I looked at the official esphome for an example: https://github.com/esphome/esphome/tree/dev/esphome/components/i2s_audio/microphone

I've tested it with my setup and when the right channel is selected, I'm around 75 dB(A), I supect that is noise since my other decibel meter says the room is around 41 (quiet empty office). With the left channel selected I'm around 43 dB(A).

RaymiiOrg commented 7 months ago

I saw another todothe mode:

I2S_MODE_MASTER | I2S_MODE_RX),  // TODO: make it configurable

If you'd like I can try to make that configurable as well?

stas-sl commented 7 months ago

Thanks!

I made a few small changes, one of them is I set right channel as default. There are several arguments for that: 1) esphome i2s microphone also has this default, and 2) it will match previous behaviour of this component. However there is some confusion with I2S_CHANNEL_FMT_ONLY_RIGHT/I2S_CHANNEL_FMT_ONLY_LEFT constants in code and what datasheet says. If you check the datasheet, it says that if you connect L/R pin to GND the signal will be in the LEFT channel, however in my experience when I connect L/R pin to GND then to be able to get the signal I have to set I2S_CHANNEL_FMT_ONLY_RIGHT in config. I found there were some issues/discussions about it and it supposed to be fixed however I've just checked, and I still see the same behaviour.

Although, in my experience I don't see such major difference when using different channels. With both channels in quiet room I have 35-36 dB(A) and 40-45 db(Z)

If you'd like I can try to make that configurable as well?

Regarding configuring mode in config, I actually don't think it is needed. Esphome's i2s microphone component also has this value hardcoded. If i2s component could be used to send audio data (instead of receiving), then it could be useful, but as long as we only reading the signal from microphone, seems like we don't need to change the mode.

If it looks ok to you, I can merge it.

RaymiiOrg commented 7 months ago

Thanks!

I made a few small changes, one of them is I set right channel as default. There are several arguments for that: 1) esphome i2s microphone also has this default, and 2) it will match previous behaviour of this component. However there is some confusion with I2S_CHANNEL_FMT_ONLY_RIGHT/I2S_CHANNEL_FMT_ONLY_LEFT constants in code and what datasheet says. If you check the datasheet, it says that if you connect L/R pin to GND the signal will be in the LEFT channel, however in my experience when I connect L/R pin to GND then to be able to get the signal I have to set I2S_CHANNEL_FMT_ONLY_RIGHT in config. I found there were some issues/discussions about it and it supposed to be fixed however I've just checked, and I still see the same behaviour.

Although, in my experience I don't see such major difference when using different channels. With both channels in quiet room I have 35-36 dB(A) and 40-45 db(Z)

If you'd like I can try to make that configurable as well?

Regarding configuring mode in config, I actually don't think it is needed. Esphome's i2s microphone component also has this value hardcoded. If i2s component could be used to send audio data (instead of receiving), then it could be useful, but as long as we only reading the signal from microphone, seems like we don't need to change the mode.

If it looks ok to you, I can merge it.

Thank you for taking a look and thoroughly explaining the choice for the default channel. I seem to have an oddball setup since mine is left, but being consistent with the defaults in esphome is important indeed.

Go ahead and merge 👍🏻 (it's your project after all so who am I to decide)