diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-09-11 12:57:04 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-09-11 12:57:04 +1000 |
| commit | 542ebc65317ac4744a4b96c3131dace5bda10314 (patch) | |
| tree | 05593126ec6ac9f340fbd76afecb560a4da27ddd /src/tangara/audio/processor.cpp | |
| parent | d0b739c66ef11a6c16f99cad6957a1782236fd8c (diff) | |
| download | tangara-fw-542ebc65317ac4744a4b96c3131dace5bda10314.tar.gz | |
Play TTS files in response to TTS prompts, but it's legible now
- input files are upsamples and padded to stereo before playback
- any in-progress playback is cancelled before playing a new file
Diffstat (limited to 'src/tangara/audio/processor.cpp')
| -rw-r--r-- | src/tangara/audio/processor.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/tangara/audio/processor.cpp b/src/tangara/audio/processor.cpp index aa2604b5..2fa7f78e 100644 --- a/src/tangara/audio/processor.cpp +++ b/src/tangara/audio/processor.cpp @@ -347,34 +347,39 @@ auto SampleProcessor::discardCommand(Args& command) -> void { // End of stream commands can just be dropped without further action. } -SampleProcessor::Buffer::Buffer() - : buffer_(reinterpret_cast<sample::Sample*>( - heap_caps_calloc(kSampleBufferLength, - sizeof(sample::Sample), - MALLOC_CAP_DMA)), - kSampleBufferLength), +Buffer::Buffer(std::span<sample::Sample> storage) + : storage_(nullptr), buffer_(storage), samples_in_buffer_() {} + +Buffer::Buffer() + : storage_(reinterpret_cast<sample::Sample*>( + heap_caps_calloc(kSampleBufferLength, + sizeof(sample::Sample), + MALLOC_CAP_DMA))), + buffer_(storage_, kSampleBufferLength), samples_in_buffer_() {} -SampleProcessor::Buffer::~Buffer() { - heap_caps_free(buffer_.data()); +Buffer::~Buffer() { + if (storage_) { + heap_caps_free(storage_); + } } -auto SampleProcessor::Buffer::writeAcquire() -> std::span<sample::Sample> { +auto Buffer::writeAcquire() -> std::span<sample::Sample> { return buffer_.subspan(samples_in_buffer_.size()); } -auto SampleProcessor::Buffer::writeCommit(size_t samples) -> void { +auto Buffer::writeCommit(size_t samples) -> void { if (samples == 0) { return; } samples_in_buffer_ = buffer_.first(samples + samples_in_buffer_.size()); } -auto SampleProcessor::Buffer::readAcquire() -> std::span<sample::Sample> { +auto Buffer::readAcquire() -> std::span<sample::Sample> { return samples_in_buffer_; } -auto SampleProcessor::Buffer::readCommit(size_t samples) -> void { +auto Buffer::readCommit(size_t samples) -> void { if (samples == 0) { return; } @@ -389,11 +394,11 @@ auto SampleProcessor::Buffer::readCommit(size_t samples) -> void { } } -auto SampleProcessor::Buffer::isEmpty() -> bool { +auto Buffer::isEmpty() -> bool { return samples_in_buffer_.empty(); } -auto SampleProcessor::Buffer::clear() -> void { +auto Buffer::clear() -> void { samples_in_buffer_ = {}; } |
