diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-25 21:17:38 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-25 21:17:38 +1000 |
| commit | d8194135bbaad97d1f3428a74c7fc54ba3f604ec (patch) | |
| tree | eac58bb2229d3883987ef0876710e4edd7b2473b /src/audio/audio_task.cpp | |
| parent | 80d7df910987db5201402fe987124f29f09344f3 (diff) | |
| download | tangara-fw-d8194135bbaad97d1f3428a74c7fc54ba3f604ec.tar.gz | |
Do time tracking without floats
Diffstat (limited to 'src/audio/audio_task.cpp')
| -rw-r--r-- | src/audio/audio_task.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index dbe5d50e..7d117cb4 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -53,9 +53,9 @@ static constexpr std::size_t kSampleBufferSize = 16 * 1024; Timer::Timer(StreamInfo::Pcm format) : format_(format), - last_seconds_(0), - total_duration_seconds_(0), - current_seconds_(0) {} + current_seconds_(0), + current_sample_in_second_(0), + total_duration_seconds_(0) {} auto Timer::SetLengthSeconds(uint32_t len) -> void { total_duration_seconds_ = len; @@ -75,15 +75,22 @@ auto Timer::AddBytes(std::size_t bytes) -> void { uint8_t bytes_per_sample = ((format_.bits_per_sample + 16 - 1) / 16) * 2; samples_sunk /= bytes_per_sample; - current_seconds_ += samples_sunk / format_.sample_rate; + current_sample_in_second_ += samples_sunk; + bool incremented = false; + while (current_sample_in_second_ > format_.sample_rate) { + current_seconds_++; + current_sample_in_second_ -= format_.sample_rate; + incremented = true; + } - uint32_t rounded = std::round(current_seconds_); - if (rounded != last_seconds_) { - last_seconds_ = rounded; + if (incremented) { + ESP_LOGI("timer", "new time %lu", current_seconds_); + /* events::Dispatch<PlaybackUpdate, AudioState, ui::UiState>(PlaybackUpdate{ - .seconds_elapsed = rounded, - .seconds_total = - total_duration_seconds_ == 0 ? rounded : total_duration_seconds_}); + .seconds_elapsed = current_seconds_, + .seconds_total = 0, + }); + */ } } |
