Fix premature end of track

custom
jacqueline 2 years ago
parent 9b1b401dcb
commit b05db70c14
  1. 4
      src/audio/audio_fsm.cpp
  2. 13
      src/audio/audio_task.cpp
  3. 2
      src/audio/fatfs_audio_input.cpp
  4. 2
      src/audio/include/audio_source.hpp

@ -15,6 +15,7 @@
#include "event_queue.hpp" #include "event_queue.hpp"
#include "fatfs_audio_input.hpp" #include "fatfs_audio_input.hpp"
#include "freertos/portmacro.h" #include "freertos/portmacro.h"
#include "freertos/projdefs.h"
#include "future_fetcher.hpp" #include "future_fetcher.hpp"
#include "i2s_audio_output.hpp" #include "i2s_audio_output.hpp"
#include "i2s_dac.hpp" #include "i2s_dac.hpp"
@ -120,6 +121,9 @@ void Playback::entry() {
void Playback::exit() { void Playback::exit() {
ESP_LOGI(kTag, "finishing playback"); ESP_LOGI(kTag, "finishing playback");
// TODO(jacqueline): Second case where it's useful to wait for the i2s buffer
// to drain.
vTaskDelay(pdMS_TO_TICKS(250));
sI2SOutput->SetInUse(false); sI2SOutput->SetInUse(false);
} }

@ -68,18 +68,9 @@ auto Timer::SetLengthBytes(uint32_t len) -> void {
} }
auto Timer::AddBytes(std::size_t bytes) -> void { auto Timer::AddBytes(std::size_t bytes) -> void {
float samples_sunk = bytes;
samples_sunk /= format_.channels;
// Samples must be aligned to 16 bits. The number of actual bytes per
// sample is therefore the bps divided by 16, rounded up (align to word),
// times two (convert to bytes).
uint8_t bytes_per_sample = ((format_.bits_per_sample + 16 - 1) / 16) * 2;
samples_sunk /= bytes_per_sample;
current_sample_in_second_ += samples_sunk;
bool incremented = false; bool incremented = false;
while (current_sample_in_second_ > format_.sample_rate) { current_sample_in_second_ += bytes_to_samples(bytes);
while (current_sample_in_second_ >= format_.sample_rate) {
current_seconds_++; current_seconds_++;
current_sample_in_second_ -= format_.sample_rate; current_sample_in_second_ -= format_.sample_rate;
incremented = true; incremented = true;

@ -295,7 +295,7 @@ auto FatfsAudioInput::CloseCurrentFile() -> void {
} }
auto FatfsAudioInput::HasDataRemaining() -> bool { auto FatfsAudioInput::HasDataRemaining() -> bool {
return !xStreamBufferIsEmpty(streamer_buffer_) || !streamer_->HasFinished(); return !streamer_->HasFinished() || !xStreamBufferIsEmpty(streamer_buffer_);
} }
auto FatfsAudioInput::ContainerToStreamType(database::Encoding enc) auto FatfsAudioInput::ContainerToStreamType(database::Encoding enc)

@ -27,7 +27,7 @@ class IAudioSource {
public: public:
Flags(bool is_start, bool is_end) { Flags(bool is_start, bool is_end) {
flags_[0] = is_start; flags_[0] = is_start;
flags_[1] = is_start; flags_[1] = is_end;
} }
auto is_start() -> bool { return flags_[0]; } auto is_start() -> bool { return flags_[0]; }

Loading…
Cancel
Save