diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-26 17:36:10 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-26 17:36:10 +1000 |
| commit | b05db70c14e8835989fb7df60775f68d2732cd69 (patch) | |
| tree | 107ffebd12e2e2ea3c3b16b73b4b6f56dc3e5931 /src/audio/audio_task.cpp | |
| parent | 9b1b401dcb986a26d10bcc898be670653acc2d3f (diff) | |
| download | tangara-fw-b05db70c14e8835989fb7df60775f68d2732cd69.tar.gz | |
Fix premature end of track
Diffstat (limited to 'src/audio/audio_task.cpp')
| -rw-r--r-- | src/audio/audio_task.cpp | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/src/audio/audio_task.cpp b/src/audio/audio_task.cpp index 6079e077..b6eff550 100644 --- a/src/audio/audio_task.cpp +++ b/src/audio/audio_task.cpp @@ -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; |
