summaryrefslogtreecommitdiff
path: root/src/audio/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-17 17:36:37 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-17 17:36:37 +1100
commitacd6d7890051b9253007941733ea37e4011b1b5e (patch)
tree5a542b3c98fe2a37dd9c10d9093a6e46b2267875 /src/audio/include
parentddcbcad6d4771e0ec8228dc1848ebd1dfe303a0b (diff)
downloadtangara-fw-acd6d7890051b9253007941733ea37e4011b1b5e.tar.gz
Progress on own pipeline. Still very WIP
Diffstat (limited to 'src/audio/include')
-rw-r--r--src/audio/include/audio_decoder.hpp34
-rw-r--r--src/audio/include/audio_element.hpp13
-rw-r--r--src/audio/include/audio_output.hpp16
-rw-r--r--src/audio/include/fatfs_audio_input.hpp11
4 files changed, 45 insertions, 29 deletions
diff --git a/src/audio/include/audio_decoder.hpp b/src/audio/include/audio_decoder.hpp
index f460f9e9..083bd564 100644
--- a/src/audio/include/audio_decoder.hpp
+++ b/src/audio/include/audio_decoder.hpp
@@ -1,34 +1,36 @@
#pragma once
#include <cstddef>
+#include "audio_element.hpp"
#include "ff.h"
+#include "codec.hpp"
namespace audio {
-enum SampleRate {};
-enum BitDepth {};
-
-struct PcmStreamHeader {
- SampleRate sample_rate;
- BitDepth bit_depth;
- bool configure_now;
-};
-
-class AudioDecoder {
+class AudioDecoder : public IAudioElement {
public:
AudioDecoder();
~AudioDecoder();
- auto SetSource(RingbufHandle_t& source) -> void;
+ auto Pause() -> void;
+ auto IsPaused() -> bool;
- enum Status {};
- auto ProcessChunk() -> Status;
+ auto Resume() -> void;
- auto GetOutputStream() const -> RingbufHandle_t;
+ auto SetInputCommandQueue(QueueHandle_t) -> void;
+ auto SetOutputCommandQueue(QueueHandle_t) -> void;
+ auto SetInputBuffer(StreamBufferHandle_t) -> void;
+ auto SetOutputBuffer(StreamBufferHandle_t) -> void;
private:
- RingbufHandle_t input_;
- RingbufHandle_t output_;
+ std::unique_ptr<codecs::ICodec> current_codec_;
+
+ uint8_t *working_buffer_;
+
+ QueueHandle_t input_queue_;
+ QueueHandle_t output_queue_;
+ StreamBufferHandle_t input_buffer_;
+ StreamBufferHandle_t output_buffer_;
};
} // namespace audio
diff --git a/src/audio/include/audio_element.hpp b/src/audio/include/audio_element.hpp
index ea4256ac..03fefd70 100644
--- a/src/audio/include/audio_element.hpp
+++ b/src/audio/include/audio_element.hpp
@@ -33,6 +33,7 @@ class IAudioElement {
struct Command {
CommandType type;
uint8_t sequence_number;
+ // TODO: tag data's type
union {
void* data;
std::size_t frame_size;
@@ -52,22 +53,28 @@ class IAudioElement {
*/
virtual auto InputBuffer() -> StreamBufferHandle_t = 0;
+ enum ProcessResult {
+ OK,
+ OUTPUT_FULL,
+ ERROR,
+ };
+
/*
* Called when an element-specific command has been received.
*/
- virtual auto ProcessElementCommand(void* command) -> void = 0;
+ virtual auto ProcessElementCommand(void* command) -> ProcessResult = 0;
virtual auto SkipElementCommand(void* command) -> void = 0;
/*
* Called with the result of a read bytes command.
*/
- virtual auto ProcessData(uint8_t* data, uint16_t length) -> void = 0;
+ virtual auto ProcessData(uint8_t* data, uint16_t length) -> ProcessResult = 0;
/*
* Called periodically when there are no pending commands.
*/
- virtual auto ProcessIdle() -> void = 0;
+ virtual auto ProcessIdle() -> ProcessResult = 0;
};
} // namespace audio
diff --git a/src/audio/include/audio_output.hpp b/src/audio/include/audio_output.hpp
index 82dca82d..9726c3b5 100644
--- a/src/audio/include/audio_output.hpp
+++ b/src/audio/include/audio_output.hpp
@@ -5,25 +5,25 @@
#include "audio_common.h"
#include "audio_element.h"
+#include "audio_element.hpp"
-namespace drivers {
+namespace audio {
-class IAudioOutput {
+class AudioOutput : IAudioElement {
public:
- IAudioOutput(audio_element_handle_t element) : element_(element) {}
- virtual ~IAudioOutput() { audio_element_deinit(element_); }
+ AudioOutput();
+ ~AudioOutput();
auto GetAudioElement() -> audio_element_handle_t { return element_; }
- virtual auto SetVolume(uint8_t volume) -> void = 0;
- virtual auto GetVolume() const -> uint8_t { return volume_; }
+ auto SetInputBuffer(StreamBufferHandle_t buffer) -> void;
virtual auto Configure(audio_element_info_t& info) -> void = 0;
virtual auto SetSoftMute(bool enabled) -> void = 0;
- protected:
+ private:
audio_element_handle_t element_;
uint8_t volume_;
};
-} // namespace drivers
+} // namespace audio
diff --git a/src/audio/include/fatfs_audio_input.hpp b/src/audio/include/fatfs_audio_input.hpp
index ed4da55e..bf5f150d 100644
--- a/src/audio/include/fatfs_audio_input.hpp
+++ b/src/audio/include/fatfs_audio_input.hpp
@@ -2,6 +2,7 @@
#include <cstdint>
#include <memory>
+#include <string>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
@@ -16,10 +17,12 @@ class FatfsAudioInput : public IAudioElement {
public:
struct InputCommand {
std::string filename;
+ size_t seek_to;
+ bool interrupt;
};
struct OutputCommand {
- // TODO: does this actually need any special output?
+ std::string extension;
};
FatfsAudioInput(std::shared_ptr<drivers::SdStorage> storage);
@@ -31,7 +34,11 @@ class FatfsAudioInput : public IAudioElement {
private:
std::shared_ptr<drivers::SdStorage> storage_;
- uint8_t current_sequence = 0;
+ uint8_t *working_buffer_;
+
+ uint8_t current_sequence_ = 0;
+ FIL current_file_;
+ bool is_file_open_ = false;
uint8_t* input_queue_memory_;
StaticQueue_t input_queue_metadata_;