mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
more clang fixes
This commit is contained in:
parent
08e2af8a3e
commit
f16120ecdd
6 changed files with 24 additions and 61 deletions
|
@ -28,8 +28,8 @@ esp_err_t AudioMixer::start(Speaker *speaker, const std::string &task_name, UBas
|
|||
}
|
||||
|
||||
if (this->task_handle_ == nullptr) {
|
||||
this->task_handle_ = xTaskCreateStatic(AudioMixer::audio_mixer_task, task_name.c_str(), TASK_STACK_SIZE,
|
||||
(void *) this, priority, this->stack_buffer_, &this->task_stack_);
|
||||
xTaskCreate(AudioMixer::audio_mixer_task, task_name.c_str(), TASK_STACK_SIZE, (void *) this, priority,
|
||||
&this->task_handle_);
|
||||
}
|
||||
|
||||
if (this->task_handle_ == nullptr) {
|
||||
|
@ -72,7 +72,6 @@ void AudioMixer::audio_mixer_task(void *params) {
|
|||
int16_t *announcement_buffer = allocator.allocate(OUTPUT_BUFFER_SAMPLES);
|
||||
int16_t *combination_buffer = allocator.allocate(OUTPUT_BUFFER_SAMPLES);
|
||||
|
||||
int16_t *combination_buffer_current = combination_buffer;
|
||||
size_t combination_buffer_length = 0;
|
||||
|
||||
if ((media_buffer == nullptr) || (announcement_buffer == nullptr)) {
|
||||
|
@ -194,8 +193,6 @@ void AudioMixer::audio_mixer_task(void *params) {
|
|||
}
|
||||
size_t samples_left_to_duck = std::min(samples_left_in_step, samples_read);
|
||||
|
||||
size_t total_samples_ducked = 0;
|
||||
|
||||
while (samples_left_to_duck > 0) {
|
||||
// Ensure we only point to valid index in the Q15 scaling factor table
|
||||
uint8_t safe_db_reduction_index =
|
||||
|
@ -210,8 +207,6 @@ void AudioMixer::audio_mixer_task(void *params) {
|
|||
samples_read -= samples_left_to_duck;
|
||||
samples_left -= samples_left_to_duck;
|
||||
|
||||
total_samples_ducked += samples_left_to_duck;
|
||||
|
||||
samples_left_in_step = samples_left % samples_per_ducking_step;
|
||||
if (samples_left_in_step == 0) {
|
||||
// Start of a new step
|
||||
|
@ -296,13 +291,6 @@ esp_err_t AudioMixer::allocate_buffers_() {
|
|||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (this->stack_buffer_ == nullptr)
|
||||
this->stack_buffer_ = (StackType_t *) malloc(TASK_STACK_SIZE);
|
||||
|
||||
if (this->stack_buffer_ == nullptr) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (this->event_queue_ == nullptr)
|
||||
this->event_queue_ = xQueueCreate(QUEUE_COUNT, sizeof(TaskEvent));
|
||||
|
||||
|
|
|
@ -139,8 +139,6 @@ class AudioMixer {
|
|||
|
||||
static void audio_mixer_task(void *params);
|
||||
TaskHandle_t task_handle_{nullptr};
|
||||
StaticTask_t task_stack_;
|
||||
StackType_t *stack_buffer_{nullptr};
|
||||
|
||||
// Reports events from the mixer task
|
||||
QueueHandle_t event_queue_;
|
||||
|
|
|
@ -98,20 +98,6 @@ esp_err_t AudioPipeline::allocate_buffers_() {
|
|||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (this->read_task_stack_buffer_ == nullptr)
|
||||
this->read_task_stack_buffer_ = (StackType_t *) malloc(READER_TASK_STACK_SIZE);
|
||||
|
||||
if (this->decode_task_stack_buffer_ == nullptr)
|
||||
this->decode_task_stack_buffer_ = (StackType_t *) malloc(DECODER_TASK_STACK_SIZE);
|
||||
|
||||
if (this->resample_task_stack_buffer_ == nullptr)
|
||||
this->resample_task_stack_buffer_ = (StackType_t *) malloc(RESAMPLER_TASK_STACK_SIZE);
|
||||
|
||||
if ((this->read_task_stack_buffer_ == nullptr) || (this->decode_task_stack_buffer_ == nullptr) ||
|
||||
(this->resample_task_stack_buffer_ == nullptr)) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (this->event_group_ == nullptr)
|
||||
this->event_group_ = xEventGroupCreate();
|
||||
|
||||
|
@ -136,19 +122,16 @@ esp_err_t AudioPipeline::common_start_(uint32_t target_sample_rate, const std::s
|
|||
}
|
||||
|
||||
if (this->read_task_handle_ == nullptr) {
|
||||
this->read_task_handle_ =
|
||||
xTaskCreateStatic(AudioPipeline::read_task, (task_name + "_read").c_str(), READER_TASK_STACK_SIZE,
|
||||
(void *) this, priority, this->read_task_stack_buffer_, &this->read_task_stack_);
|
||||
xTaskCreate(AudioPipeline::read_task, (task_name + "_read").c_str(), READER_TASK_STACK_SIZE, (void *) this,
|
||||
priority, &this->read_task_handle_);
|
||||
}
|
||||
if (this->decode_task_handle_ == nullptr) {
|
||||
this->decode_task_handle_ =
|
||||
xTaskCreateStatic(AudioPipeline::decode_task, (task_name + "_decode").c_str(), DECODER_TASK_STACK_SIZE,
|
||||
(void *) this, priority, this->decode_task_stack_buffer_, &this->decode_task_stack_);
|
||||
xTaskCreate(AudioPipeline::decode_task, (task_name + "_decode").c_str(), DECODER_TASK_STACK_SIZE, (void *) this,
|
||||
priority, &this->decode_task_handle_);
|
||||
}
|
||||
if (this->resample_task_handle_ == nullptr) {
|
||||
this->resample_task_handle_ =
|
||||
xTaskCreateStatic(AudioPipeline::resample_task, (task_name + "_resample").c_str(), RESAMPLER_TASK_STACK_SIZE,
|
||||
(void *) this, priority, this->resample_task_stack_buffer_, &this->resample_task_stack_);
|
||||
xTaskCreate(AudioPipeline::resample_task, (task_name + "_resample").c_str(), RESAMPLER_TASK_STACK_SIZE,
|
||||
(void *) this, priority, &this->resample_task_handle_);
|
||||
}
|
||||
|
||||
if ((this->read_task_handle_ == nullptr) || (this->decode_task_handle_ == nullptr) ||
|
||||
|
@ -387,7 +370,7 @@ void AudioPipeline::decode_task(void *params) {
|
|||
xEventGroupSetBits(this_pipeline->event_group_, EventGroupBits::DECODER_MESSAGE_FINISHED);
|
||||
|
||||
// Wait until the reader notifies us that the media type is available
|
||||
EventBits_t event_bits = xEventGroupWaitBits(this_pipeline->event_group_,
|
||||
xEventGroupWaitBits(this_pipeline->event_group_,
|
||||
READER_MESSAGE_LOADED_MEDIA_TYPE, // Bit message to read
|
||||
pdTRUE, // Clear the bit on exit
|
||||
pdFALSE, // Wait for all the bits,
|
||||
|
@ -416,7 +399,7 @@ void AudioPipeline::decode_task(void *params) {
|
|||
bool has_stream_info = false;
|
||||
|
||||
while (true) {
|
||||
event_bits = xEventGroupGetBits(this_pipeline->event_group_);
|
||||
EventBits_t event_bits = xEventGroupGetBits(this_pipeline->event_group_);
|
||||
|
||||
if (event_bits & PIPELINE_COMMAND_STOP) {
|
||||
break;
|
||||
|
@ -474,7 +457,7 @@ void AudioPipeline::resample_task(void *params) {
|
|||
xEventGroupSetBits(this_pipeline->event_group_, EventGroupBits::RESAMPLER_MESSAGE_FINISHED);
|
||||
|
||||
// Wait until the decoder notifies us that the stream information is available
|
||||
EventBits_t event_bits = xEventGroupWaitBits(this_pipeline->event_group_,
|
||||
xEventGroupWaitBits(this_pipeline->event_group_,
|
||||
DECODER_MESSAGE_LOADED_STREAM_INFO, // Bit message to read
|
||||
pdTRUE, // Clear the bit on exit
|
||||
pdFALSE, // Wait for all the bits,
|
||||
|
@ -514,7 +497,7 @@ void AudioPipeline::resample_task(void *params) {
|
|||
}
|
||||
|
||||
while (true) {
|
||||
event_bits = xEventGroupGetBits(this_pipeline->event_group_);
|
||||
EventBits_t event_bits = xEventGroupGetBits(this_pipeline->event_group_);
|
||||
|
||||
if (event_bits & PIPELINE_COMMAND_STOP) {
|
||||
break;
|
||||
|
|
|
@ -131,20 +131,14 @@ class AudioPipeline {
|
|||
// Handles reading the media file from flash or a url
|
||||
static void read_task(void *params);
|
||||
TaskHandle_t read_task_handle_{nullptr};
|
||||
StaticTask_t read_task_stack_;
|
||||
StackType_t *read_task_stack_buffer_{nullptr};
|
||||
|
||||
// Decodes the media file into PCM audio
|
||||
static void decode_task(void *params);
|
||||
TaskHandle_t decode_task_handle_{nullptr};
|
||||
StaticTask_t decode_task_stack_;
|
||||
StackType_t *decode_task_stack_buffer_{nullptr};
|
||||
|
||||
// Resamples the audio to match the specified target sample rate. Converts mono audio to stereo audio if necessary.
|
||||
static void resample_task(void *params);
|
||||
TaskHandle_t resample_task_handle_{nullptr};
|
||||
StaticTask_t resample_task_stack_;
|
||||
StackType_t *resample_task_stack_buffer_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace speaker
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace speaker {
|
|||
static const size_t READ_WRITE_TIMEOUT_MS = 20;
|
||||
|
||||
// The number of times the http read times out with no data before throwing an error
|
||||
static const size_t ERROR_COUNT_NO_DATA_READ_TIMEOUT = 10;
|
||||
static const ssize_t ERROR_COUNT_NO_DATA_READ_TIMEOUT = 10;
|
||||
|
||||
AudioReader::AudioReader(esphome::RingBuffer *output_ring_buffer, size_t transfer_buffer_size) {
|
||||
this->output_ring_buffer_ = output_ring_buffer;
|
||||
|
@ -101,7 +101,7 @@ esp_err_t AudioReader::start(const std::string &uri, MediaFileType &file_type) {
|
|||
return err;
|
||||
}
|
||||
|
||||
int content_length = esp_http_client_fetch_headers(this->client_);
|
||||
esp_http_client_fetch_headers(this->client_);
|
||||
|
||||
char url[500];
|
||||
err = esp_http_client_get_url(this->client_, url, 500);
|
||||
|
|
|
@ -241,7 +241,7 @@ AudioResamplerState AudioResampler::resample(bool stop_gracefully) {
|
|||
|
||||
size_t samples_read = this->input_buffer_length_ / sizeof(int16_t);
|
||||
|
||||
for (int i = 0; i < samples_read; ++i) {
|
||||
for (size_t i = 0; i < samples_read; ++i) {
|
||||
this->float_input_buffer_[i] = static_cast<float>(this->input_buffer_[i]) / 32768.0f;
|
||||
}
|
||||
|
||||
|
@ -277,7 +277,7 @@ AudioResamplerState AudioResampler::resample(bool stop_gracefully) {
|
|||
|
||||
size_t samples_generated = frames_generated * this->stream_info_.channels;
|
||||
|
||||
for (int i = 0; i < samples_generated; ++i) {
|
||||
for (size_t i = 0; i < samples_generated; ++i) {
|
||||
this->output_buffer_[i] = static_cast<int16_t>(this->float_output_buffer_[i] * 32767);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue