ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
resampler_microphone.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
8
10
11#include <resampler.h> // esp-audio-libs
12
13#include <memory>
14#include <vector>
15
16namespace esphome::resampler {
17
22 public:
24
25 void setup() override;
26 void loop() override;
27 void dump_config() override;
28
29 void start() override;
30 void stop() override;
31
32 void set_target_sample_rate(uint32_t target_sample_rate) { this->target_sample_rate_ = target_sample_rate; }
33 void set_filters(uint16_t filters) { this->filters_ = filters; }
34 void set_taps(uint16_t taps) { this->taps_ = taps; }
35
36 protected:
39 bool init_resampler_(const audio::AudioStreamInfo &input_stream_info);
40
42 void process_audio_(const std::vector<uint8_t> &data);
43
45 std::unique_ptr<esp_audio_libs::resampler::Resampler> resampler_;
46 // Reused for every chunk so resampling does not allocate
47 std::vector<uint8_t> output_buffer_;
48
49 // Format the resampler is set up for
51
53 uint16_t taps_;
54 uint16_t filters_;
55
57 bool resampler_ready_{false};
58};
59
60} // namespace esphome::resampler
61
62#endif // USE_ESP32
Microphone that converts the audio of a source microphone to a different sample rate.
bool init_resampler_(const audio::AudioStreamInfo &input_stream_info)
Sets up the resampler for the given input format.
void process_audio_(const std::vector< uint8_t > &data)
Resamples a chunk of source audio and passes it to the data callbacks. Source microphone task only.
microphone::MicrophoneSource * source_
ResamplerMicrophone(microphone::MicrophoneSource *source)
std::unique_ptr< esp_audio_libs::resampler::Resampler > resampler_
void set_target_sample_rate(uint32_t target_sample_rate)
static void uint32_t