diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-09-17 00:09:10 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-09-17 00:09:10 +0000 |
| commit | c030a4510ac6aaed30ad920dfb4e3d8cc384a6a5 (patch) | |
| tree | 12e57cd25efda02a1c6dd58250b3fe8a644434de /src/tangara/audio/processor.cpp | |
| parent | a174d76aa16e09ddfc2ce67393c92ed947a817a5 (diff) | |
| parent | 1106012bde558dab5e192c2129178d44f80b9e4e (diff) | |
| download | tangara-fw-c030a4510ac6aaed30ad920dfb4e3d8cc384a6a5.tar.gz | |
Merge pull request 'Introduce basic TTS support using pre-recorded voice lines' (#103) from jqln/tts into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/103
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_ = {}; } |
