diff options
Diffstat (limited to 'src/audio/include')
| -rw-r--r-- | src/audio/include/audio_decoder.hpp | 17 | ||||
| -rw-r--r-- | src/audio/include/audio_element.hpp | 48 | ||||
| -rw-r--r-- | src/audio/include/audio_element_handle.hpp | 41 | ||||
| -rw-r--r-- | src/audio/include/audio_playback.hpp | 7 | ||||
| -rw-r--r-- | src/audio/include/audio_task.hpp | 4 | ||||
| -rw-r--r-- | src/audio/include/fatfs_audio_input.hpp | 9 | ||||
| -rw-r--r-- | src/audio/include/i2s_audio_output.hpp | 13 |
7 files changed, 21 insertions, 118 deletions
diff --git a/src/audio/include/audio_decoder.hpp b/src/audio/include/audio_decoder.hpp index 9cc40162..47642469 100644 --- a/src/audio/include/audio_decoder.hpp +++ b/src/audio/include/audio_decoder.hpp @@ -24,21 +24,13 @@ class AudioDecoder : public IAudioElement { auto StackSizeBytes() const -> std::size_t override { return 10 * 1024; }; - auto InputMinChunkSize() const -> std::size_t override { - // 128 kbps MPEG-1 @ 44.1 kHz is approx. 418 bytes according to the - // internet. - // TODO(jacqueline): tune as more codecs are added. - return 1024; - } - auto HasUnprocessedInput() -> bool override; + auto IsOverBuffered() -> bool override; - auto ProcessStreamInfo(const StreamInfo& info) - -> cpp::result<void, AudioProcessingError> override; - auto ProcessChunk(const cpp::span<std::byte>& chunk) - -> cpp::result<std::size_t, AudioProcessingError> override; + auto ProcessStreamInfo(const StreamInfo& info) -> void override; + auto ProcessChunk(const cpp::span<std::byte>& chunk) -> void override; auto ProcessEndOfStream() -> void override; - auto Process() -> cpp::result<void, AudioProcessingError> override; + auto Process() -> void override; AudioDecoder(const AudioDecoder&) = delete; AudioDecoder& operator=(const AudioDecoder&) = delete; @@ -50,7 +42,6 @@ class AudioDecoder : public IAudioElement { std::optional<ChunkReader> chunk_reader_; bool has_sent_stream_info_; - std::size_t chunk_size_; bool has_samples_to_send_; bool needs_more_input_; }; diff --git a/src/audio/include/audio_element.hpp b/src/audio/include/audio_element.hpp index b881404c..91036348 100644 --- a/src/audio/include/audio_element.hpp +++ b/src/audio/include/audio_element.hpp @@ -20,25 +20,6 @@ namespace audio { -enum ElementState { - STATE_RUN, - STATE_PAUSE, - STATE_QUIT, -}; - -/* - * Errors that may be returned by any of the Process* methods of an audio - * element. - */ -enum AudioProcessingError { - // Indicates that this element is unable to handle the upcoming chunks. - UNSUPPORTED_STREAM, - // Indicates an error with reading or writing stream data. - IO_ERROR, - // Indicates that the element has run out of data to process. - OUT_OF_DATA, -}; - static const size_t kEventQueueSize = 8; /* @@ -66,35 +47,24 @@ class IAudioElement { */ virtual auto StackSizeBytes() const -> std::size_t { return 4096; }; - virtual auto InputMinChunkSize() const -> std::size_t { return 0; } - /* Returns this element's input buffer. */ auto InputEventQueue() const -> QueueHandle_t { return input_events_; } - /* Returns this element's output buffer. */ auto OutputEventQueue() const -> QueueHandle_t { return output_events_; } - auto OutputEventQueue(const QueueHandle_t q) -> void { output_events_ = q; } - auto HasUnflushedOutput() -> bool { return !buffered_output_.empty(); } - virtual auto HasUnprocessedInput() -> bool = 0; - auto IsOverBuffered() -> bool { return unprocessed_output_chunks_ > 4; } + virtual auto IsOverBuffered() -> bool { return false; } + auto HasUnflushedOutput() -> bool { return !buffered_output_.empty(); } auto FlushBufferedOutput() -> bool; - auto ElementState() const -> ElementState { return current_state_; } - auto ElementState(enum ElementState e) -> void { current_state_ = e; } - - virtual auto OnChunkProcessed() -> void { unprocessed_output_chunks_--; } - /* * Called when a StreamInfo message is received. Used to configure this * element in preperation for incoming chunks. */ - virtual auto ProcessStreamInfo(const StreamInfo& info) - -> cpp::result<void, AudioProcessingError> = 0; + virtual auto ProcessStreamInfo(const StreamInfo& info) -> void = 0; /* * Called when a ChunkHeader message is received. Includes the data associated @@ -102,8 +72,7 @@ class IAudioElement { * bytes in this chunk that were actually used; leftover bytes will be * prepended to the next call. */ - virtual auto ProcessChunk(const cpp::span<std::byte>& chunk) - -> cpp::result<std::size_t, AudioProcessingError> = 0; + virtual auto ProcessChunk(const cpp::span<std::byte>& chunk) -> void = 0; virtual auto ProcessEndOfStream() -> void = 0; @@ -114,7 +83,7 @@ class IAudioElement { * time. This could be used to synthesize output, or to save memory by * releasing unused resources. */ - virtual auto Process() -> cpp::result<void, AudioProcessingError> = 0; + virtual auto Process() -> void = 0; protected: auto SendOrBufferEvent(std::unique_ptr<StreamEvent> event) -> bool; @@ -125,15 +94,8 @@ class IAudioElement { // if we're not yet in a pipeline. // FIXME: it would be nicer if this was non-nullable. QueueHandle_t output_events_; - - // The number of output chunks that we have generated, but have not yet been - // processed by the next element in the pipeline. This includes any chunks - // that are currently help in buffered_output_. - int unprocessed_output_chunks_; // Output events that have been generated, but are yet to be sent downstream. std::deque<std::unique_ptr<StreamEvent>> buffered_output_; - - enum ElementState current_state_; }; } // namespace audio diff --git a/src/audio/include/audio_element_handle.hpp b/src/audio/include/audio_element_handle.hpp deleted file mode 100644 index e4d66491..00000000 --- a/src/audio/include/audio_element_handle.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include <memory> -#include "audio_element.hpp" - -namespace audio { - -class AudioElementHandle { - public: - AudioElementHandle(std::unique_ptr<TaskHandle_t> task, - std::shared_ptr<IAudioElement> element); - ~AudioElementHandle(); - - auto CurrentState() -> ElementState; - - // TODO: think about this contract. Would it ever make sense to pause and - // then walk away? Things could keep running for a whole loop if data comes - // through, so probably not? - enum PlayPause { - PLAY, - PAUSE, - }; - auto PlayPause(PlayPause state) -> void; - auto Quit() -> void; - - auto PauseSync() -> void; - auto QuitSync() -> void; - - AudioElementHandle(const AudioElementHandle&) = delete; - AudioElementHandle& operator=(const AudioElementHandle&) = delete; - - private: - std::unique_ptr<TaskHandle_t> task_; - std::shared_ptr<IAudioElement> element_; - - auto MonitorUntilState(eTaskState desired) -> void; - auto SetStateAndWakeUp(ElementState state) -> void; - auto WakeUpTask() -> void; -}; - -} // namespace audio diff --git a/src/audio/include/audio_playback.hpp b/src/audio/include/audio_playback.hpp index fc266c9b..a1bea64f 100644 --- a/src/audio/include/audio_playback.hpp +++ b/src/audio/include/audio_playback.hpp @@ -5,12 +5,12 @@ #include <string> #include <vector> -#include "audio_element.hpp" -#include "audio_element_handle.hpp" #include "esp_err.h" -#include "gpio_expander.hpp" #include "result.hpp" #include "span.hpp" + +#include "audio_element.hpp" +#include "gpio_expander.hpp" #include "storage.hpp" #include "stream_buffer.hpp" @@ -45,7 +45,6 @@ class AudioPlayback { private: auto ConnectElements(IAudioElement* src, IAudioElement* sink) -> void; - std::vector<std::unique_ptr<AudioElementHandle>> element_handles_; QueueHandle_t input_handle_; }; diff --git a/src/audio/include/audio_task.hpp b/src/audio/include/audio_task.hpp index 0b353735..df70ebaa 100644 --- a/src/audio/include/audio_task.hpp +++ b/src/audio/include/audio_task.hpp @@ -5,7 +5,6 @@ #include <string> #include "audio_element.hpp" -#include "audio_element_handle.hpp" #include "freertos/portmacro.h" namespace audio { @@ -16,8 +15,7 @@ struct AudioTaskArgs { auto StartAudioTask(const std::string& name, std::optional<BaseType_t> core_id, - std::shared_ptr<IAudioElement> element) - -> std::unique_ptr<AudioElementHandle>; + std::shared_ptr<IAudioElement> element) -> void; void AudioTaskMain(void* args); diff --git a/src/audio/include/fatfs_audio_input.hpp b/src/audio/include/fatfs_audio_input.hpp index 06b0b7ea..9f2d676c 100644 --- a/src/audio/include/fatfs_audio_input.hpp +++ b/src/audio/include/fatfs_audio_input.hpp @@ -24,13 +24,12 @@ class FatfsAudioInput : public IAudioElement { ~FatfsAudioInput(); auto HasUnprocessedInput() -> bool override; + auto IsOverBuffered() -> bool override; - auto ProcessStreamInfo(const StreamInfo& info) - -> cpp::result<void, AudioProcessingError> override; - auto ProcessChunk(const cpp::span<std::byte>& chunk) - -> cpp::result<std::size_t, AudioProcessingError> override; + auto ProcessStreamInfo(const StreamInfo& info) -> void override; + auto ProcessChunk(const cpp::span<std::byte>& chunk) -> void override; auto ProcessEndOfStream() -> void override; - auto Process() -> cpp::result<void, AudioProcessingError> override; + auto Process() -> void override; FatfsAudioInput(const FatfsAudioInput&) = delete; FatfsAudioInput& operator=(const FatfsAudioInput&) = delete; diff --git a/src/audio/include/i2s_audio_output.hpp b/src/audio/include/i2s_audio_output.hpp index de2f1f58..2bea091b 100644 --- a/src/audio/include/i2s_audio_output.hpp +++ b/src/audio/include/i2s_audio_output.hpp @@ -23,28 +23,23 @@ class I2SAudioOutput : public IAudioElement { ~I2SAudioOutput(); auto HasUnprocessedInput() -> bool override; + auto IsOverBuffered() -> bool override; - auto ProcessStreamInfo(const StreamInfo& info) - -> cpp::result<void, AudioProcessingError> override; - auto ProcessChunk(const cpp::span<std::byte>& chunk) - -> cpp::result<std::size_t, AudioProcessingError> override; + auto ProcessStreamInfo(const StreamInfo& info) -> void override; + auto ProcessChunk(const cpp::span<std::byte>& chunk) -> void override; auto ProcessEndOfStream() -> void override; auto ProcessLogStatus() -> void override; - auto Process() -> cpp::result<void, AudioProcessingError> override; + auto Process() -> void override; I2SAudioOutput(const I2SAudioOutput&) = delete; I2SAudioOutput& operator=(const I2SAudioOutput&) = delete; private: auto SetVolume(uint8_t volume) -> void; - auto SetSoftMute(bool enabled) -> void; drivers::GpioExpander* expander_; std::unique_ptr<drivers::AudioDac> dac_; - uint8_t volume_; - bool is_soft_muted_; - std::optional<ChunkReader> chunk_reader_; cpp::span<std::byte> latest_chunk_; }; |
