ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
sound_level.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
9
11
12namespace esphome::sound_level {
13
14class SoundLevelComponent final : public Component {
15 public:
16 void dump_config() override;
17 void setup() override;
18 void loop() override;
19
20 float get_setup_priority() const override { return setup_priority::AFTER_CONNECTION; }
21
22 void set_measurement_duration(uint32_t measurement_duration_ms) {
23 this->measurement_duration_ms_ = measurement_duration_ms;
24 }
26 this->microphone_source_ = microphone_source;
27 }
28 void set_peak_sensor(sensor::Sensor *peak_sensor) { this->peak_sensor_ = peak_sensor; }
29 void set_rms_sensor(sensor::Sensor *rms_sensor) { this->rms_sensor_ = rms_sensor; }
30
32 void start();
33
35 void stop();
36
37 protected:
41 bool start_();
42
44 void stop_();
45
47
50
51 std::unique_ptr<audio::RingBufferAudioSource> audio_source_;
52 std::weak_ptr<ring_buffer::RingBuffer> ring_buffer_;
53
54 int32_t squared_peak_{0};
57
59};
60
61} // namespace esphome::sound_level
62
63#endif
Base-class for all sensors.
Definition sensor.h:47
void set_peak_sensor(sensor::Sensor *peak_sensor)
Definition sound_level.h:28
void start()
Starts the MicrophoneSource to start measuring sound levels.
void set_rms_sensor(sensor::Sensor *rms_sensor)
Definition sound_level.h:29
void set_measurement_duration(uint32_t measurement_duration_ms)
Definition sound_level.h:22
std::weak_ptr< ring_buffer::RingBuffer > ring_buffer_
Definition sound_level.h:52
microphone::MicrophoneSource * microphone_source_
Definition sound_level.h:46
void stop()
Stops the MicrophoneSource.
void set_microphone_source(microphone::MicrophoneSource *microphone_source)
Definition sound_level.h:25
float get_setup_priority() const override
Definition sound_level.h:20
void stop_()
Internal start command that, if necessary, allocates a ring buffer and a zero-copy RingBufferAudioSou...
std::unique_ptr< audio::RingBufferAudioSource > audio_source_
Definition sound_level.h:51
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Definition component.h:57
static void uint32_t