Fix premature end of track
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "event_queue.hpp"
|
||||
#include "fatfs_audio_input.hpp"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/projdefs.h"
|
||||
#include "future_fetcher.hpp"
|
||||
#include "i2s_audio_output.hpp"
|
||||
#include "i2s_dac.hpp"
|
||||
@@ -120,6 +121,9 @@ void Playback::entry() {
|
||||
|
||||
void Playback::exit() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,18 +68,9 @@ auto Timer::SetLengthBytes(uint32_t len) -> 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;
|
||||
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_sample_in_second_ -= format_.sample_rate;
|
||||
incremented = true;
|
||||
|
||||
@@ -295,7 +295,7 @@ auto FatfsAudioInput::CloseCurrentFile() -> void {
|
||||
}
|
||||
|
||||
auto FatfsAudioInput::HasDataRemaining() -> bool {
|
||||
return !xStreamBufferIsEmpty(streamer_buffer_) || !streamer_->HasFinished();
|
||||
return !streamer_->HasFinished() || !xStreamBufferIsEmpty(streamer_buffer_);
|
||||
}
|
||||
|
||||
auto FatfsAudioInput::ContainerToStreamType(database::Encoding enc)
|
||||
|
||||
@@ -27,7 +27,7 @@ class IAudioSource {
|
||||
public:
|
||||
Flags(bool is_start, bool is_end) {
|
||||
flags_[0] = is_start;
|
||||
flags_[1] = is_start;
|
||||
flags_[1] = is_end;
|
||||
}
|
||||
|
||||
auto is_start() -> bool { return flags_[0]; }
|
||||
|
||||
Reference in New Issue
Block a user