diff --git a/components/t-deck/include/t-deck.hpp b/components/t-deck/include/t-deck.hpp index d864f3534..859a7888e 100644 --- a/components/t-deck/include/t-deck.hpp +++ b/components/t-deck/include/t-deck.hpp @@ -651,7 +651,5 @@ class TDeck : public BaseComponent { std::vector audio_tx_buffer; StreamBufferHandle_t audio_tx_stream; i2s_std_config_t audio_std_cfg; - i2s_event_callbacks_t audio_tx_callbacks_; - std::atomic has_sound{false}; }; // class TDeck } // namespace espp diff --git a/components/t-deck/src/audio.cpp b/components/t-deck/src/audio.cpp index a270b4533..46e97fd13 100644 --- a/components/t-deck/src/audio.cpp +++ b/components/t-deck/src/audio.cpp @@ -6,15 +6,6 @@ using namespace espp; // Audio Functions // //////////////////////// -static TaskHandle_t play_audio_task_handle_ = NULL; - -static bool IRAM_ATTR audio_tx_sent_callback(i2s_chan_handle_t handle, i2s_event_data_t *event, - void *user_ctx) { - // notify the main task that we're done - vTaskNotifyGiveFromISR(play_audio_task_handle_, NULL); - return true; -} - bool TDeck::initialize_i2s(uint32_t default_audio_rate) { logger_.info("initializing i2s driver"); logger_.debug("Using newer I2S standard"); @@ -65,12 +56,6 @@ bool TDeck::initialize_i2s(uint32_t default_audio_rate) { audio_tx_stream = xStreamBufferCreate(buffer_size * 4, 0); - play_audio_task_handle_ = xTaskGetCurrentTaskHandle(); - - memset(&audio_tx_callbacks_, 0, sizeof(audio_tx_callbacks_)); - audio_tx_callbacks_.on_sent = audio_tx_sent_callback; - i2s_channel_register_event_callback(audio_tx_handle, &audio_tx_callbacks_, NULL); - xStreamBufferReset(audio_tx_stream); ESP_ERROR_CHECK(i2s_channel_enable(audio_tx_handle)); @@ -125,13 +110,13 @@ bool TDeck::audio_task_callback(std::mutex &m, std::condition_variable &cv, bool // pointers to the buffer to the correct positions. int16_t *ptr = reinterpret_cast(buffer); for (int i = 0; i < (available / 2); ++i) { - int16_t sample = ptr[i]; - ptr[i] = static_cast((sample * volume_) / 100.0f); + int32_t sample = (ptr[i] * volume_) / 100.0f; + ptr[i] = static_cast(std::clamp(sample, INT16_MIN, INT16_MAX)); } } // write the buffer to the I2S channel - i2s_channel_write(audio_tx_handle, buffer, available, NULL, portMAX_DELAY); + i2s_channel_write(audio_tx_handle, buffer, buffer_size, NULL, portMAX_DELAY); } return false; // don't stop the task } @@ -164,11 +149,6 @@ void TDeck::audio_sample_rate(uint32_t sample_rate) { void TDeck::play_audio(const std::vector &data) { play_audio(data.data(), data.size()); } void TDeck::play_audio(const uint8_t *data, uint32_t num_bytes) { - play_audio_task_handle_ = xTaskGetCurrentTaskHandle(); - if (has_sound) { - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - } // don't block here xStreamBufferSendFromISR(audio_tx_stream, data, num_bytes, NULL); - has_sound = true; }