From 47ae601d417d0ef99eb6fe433ef695614d8d2786 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 21 Feb 2023 14:40:18 +1100 Subject: Tidy up pipeline and use arena capacity to test for overruns --- src/audio/i2s_audio_output.cpp | 47 ++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) (limited to 'src/audio/i2s_audio_output.cpp') diff --git a/src/audio/i2s_audio_output.cpp b/src/audio/i2s_audio_output.cpp index 9a41adff..110227cf 100644 --- a/src/audio/i2s_audio_output.cpp +++ b/src/audio/i2s_audio_output.cpp @@ -40,8 +40,6 @@ I2SAudioOutput::I2SAudioOutput(drivers::GpioExpander* expander, std::unique_ptr dac) : expander_(expander), dac_(std::move(dac)), - volume_(255), - is_soft_muted_(false), chunk_reader_(), latest_chunk_() {} @@ -51,18 +49,21 @@ auto I2SAudioOutput::HasUnprocessedInput() -> bool { return latest_chunk_.size() > 0; } -auto I2SAudioOutput::ProcessStreamInfo(const StreamInfo& info) - -> cpp::result { +auto I2SAudioOutput::IsOverBuffered() -> bool { + return false; +} + +auto I2SAudioOutput::ProcessStreamInfo(const StreamInfo& info) -> void { // TODO(jacqueline): probs do something with the channel hey if (!info.bits_per_sample || !info.sample_rate) { ESP_LOGE(kTag, "audio stream missing bits or sample rate"); - return cpp::fail(UNSUPPORTED_STREAM); + return; } if (!info.chunk_size) { ESP_LOGE(kTag, "audio stream missing chunk size"); - return cpp::fail(UNSUPPORTED_STREAM); + return; } chunk_reader_.emplace(*info.chunk_size); @@ -82,7 +83,7 @@ auto I2SAudioOutput::ProcessStreamInfo(const StreamInfo& info) break; default: ESP_LOGE(kTag, "dropping stream with unknown bps"); - return cpp::fail(UNSUPPORTED_STREAM); + return; } drivers::AudioDac::SampleRate sample_rate; @@ -95,18 +96,14 @@ auto I2SAudioOutput::ProcessStreamInfo(const StreamInfo& info) break; default: ESP_LOGE(kTag, "dropping stream with unknown rate"); - return cpp::fail(UNSUPPORTED_STREAM); + return; } dac_->Reconfigure(bps, sample_rate); - - return {}; } -auto I2SAudioOutput::ProcessChunk(const cpp::span& chunk) - -> cpp::result { +auto I2SAudioOutput::ProcessChunk(const cpp::span& chunk) -> void { latest_chunk_ = chunk_reader_->HandleNewData(chunk); - return 0; } auto I2SAudioOutput::ProcessEndOfStream() -> void { @@ -119,8 +116,9 @@ auto I2SAudioOutput::ProcessLogStatus() -> void { dac_->LogStatus(); } -auto I2SAudioOutput::Process() -> cpp::result { - // Note: no logging here! +auto I2SAudioOutput::Process() -> void { + // Note: avoid logging here! We need to get bytes from the chunk buffer into + // the I2S DMA buffer as fast as possible, to avoid running out of samples. std::size_t bytes_written = dac_->WriteData(latest_chunk_); if (bytes_written == latest_chunk_.size_bytes()) { latest_chunk_ = cpp::span(); @@ -128,26 +126,11 @@ auto I2SAudioOutput::Process() -> cpp::result { } else { latest_chunk_ = latest_chunk_.subspan(bytes_written); } - return {}; + return; } auto I2SAudioOutput::SetVolume(uint8_t volume) -> void { - volume_ = volume; - if (!is_soft_muted_) { - dac_->WriteVolume(volume); - } -} - -auto I2SAudioOutput::SetSoftMute(bool enabled) -> void { - if (enabled == is_soft_muted_) { - return; - } - is_soft_muted_ = enabled; - if (is_soft_muted_) { - dac_->WriteVolume(255); - } else { - dac_->WriteVolume(volume_); - } + dac_->WriteVolume(volume); } } // namespace audio -- cgit v1.2.3