ESPHome 2026.11.0b6
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
19class PositionResampler : public esp_audio_libs::resampler::Resampler {
20 public:
21 using Resampler::Resampler;
23 float get_position() { return esp_audio_libs::art_resampler::resampleGetPosition(this->resampler_); }
24};
25
30 public:
32
33 void setup() override;
34 void loop() override;
35 void dump_config() override;
36
37 void start() override;
38 void stop() override;
39
40 void set_target_sample_rate(uint32_t target_sample_rate) { this->target_sample_rate_ = target_sample_rate; }
41 void set_filters(uint16_t filters) { this->filters_ = filters; }
42 void set_taps(uint16_t taps) { this->taps_ = taps; }
43
44 protected:
47 bool init_resampler_(const audio::AudioStreamInfo &input_stream_info);
48
50 void process_audio_(const microphone::AudioCapture &capture);
51
53 std::unique_ptr<PositionResampler> resampler_;
54 // Reused for every chunk so resampling does not allocate
55 std::vector<uint8_t> output_buffer_;
56
57 // Format the resampler is set up for
59
61 uint16_t taps_;
62 uint16_t filters_;
63
65 bool resampler_ready_{false};
66};
67
68} // namespace esphome::resampler
69
70#endif // USE_ESP32
The esp-audio-libs resampler, with its exact position for timestamping output.
float get_position()
Input frames from (last frame taken in - taps / 2) to the next output frame; usually within one frame...
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.
microphone::MicrophoneSource * source_
ResamplerMicrophone(microphone::MicrophoneSource *source)
void set_target_sample_rate(uint32_t target_sample_rate)
void process_audio_(const microphone::AudioCapture &capture)
Resamples a chunk of source audio and passes it to the data callbacks. Source microphone task only.
std::unique_ptr< PositionResampler > resampler_
static void uint32_t