Do time tracking without floats
This commit is contained in:
+17
-10
@@ -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,
|
||||
});
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ class Timer {
|
||||
private:
|
||||
StreamInfo::Pcm format_;
|
||||
|
||||
uint32_t last_seconds_;
|
||||
uint32_t current_seconds_;
|
||||
uint32_t current_sample_in_second_;
|
||||
uint32_t total_duration_seconds_;
|
||||
float current_seconds_;
|
||||
};
|
||||
|
||||
class AudioTask {
|
||||
|
||||
@@ -119,8 +119,8 @@ I2SDac::I2SDac(IGpios* gpio, i2s_chan_handle_t i2s_handle)
|
||||
// TODO: testing
|
||||
// write_register(kDacGainLeft, 0b01, 0x50);
|
||||
// write_register(kDacGainRight, 0b11, 0x50);
|
||||
write_register(kDacGainLeft, 0b01, 0x80);
|
||||
write_register(kDacGainRight, 0b11, 0x78);
|
||||
write_register(kDacGainLeft, 0b01, 0x0);
|
||||
write_register(kDacGainRight, 0b11, 0x0);
|
||||
}
|
||||
|
||||
I2SDac::~I2SDac() {
|
||||
|
||||
Reference in New Issue
Block a user