summaryrefslogtreecommitdiff
path: root/src/audio/include/audio_playback.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-12-07 15:36:47 +1100
committerjacqueline <me@jacqueline.id.au>2022-12-07 15:36:47 +1100
commit01be69eca1fa89c047fc29f5cb0ea8ba0898dad1 (patch)
treed40f749b3ebf6327f13d51d585f7c315a6d864c3 /src/audio/include/audio_playback.hpp
parentf35bb64c2b8dbb72fd15f1880e4d01d263660910 (diff)
downloadtangara-fw-01be69eca1fa89c047fc29f5cb0ea8ba0898dad1.tar.gz
better handling of chunk buffer
Diffstat (limited to 'src/audio/include/audio_playback.hpp')
-rw-r--r--src/audio/include/audio_playback.hpp85
1 files changed, 17 insertions, 68 deletions
diff --git a/src/audio/include/audio_playback.hpp b/src/audio/include/audio_playback.hpp
index 41ab46d2..9a7c5fc0 100644
--- a/src/audio/include/audio_playback.hpp
+++ b/src/audio/include/audio_playback.hpp
@@ -3,95 +3,44 @@
#include <cstdint>
#include <memory>
#include <string>
+#include <vector>
-#include "audio_common.h"
-#include "audio_element.h"
-#include "audio_event_iface.h"
-#include "audio_pipeline.h"
+#include "audio_element.hpp"
#include "esp_err.h"
-#include "fatfs_stream.h"
-#include "i2s_stream.h"
-#include "mp3_decoder.h"
+#include "gpio_expander.hpp"
#include "result.hpp"
-
-#include "audio_output.hpp"
-#include "dac.hpp"
+#include "span.hpp"
#include "storage.hpp"
+#include "stream_buffer.hpp"
-namespace drivers {
+namespace audio {
/*
- * Sends an I2S audio stream to the DAC. Includes basic controls for pausing
- * and resuming the stream, as well as support for gapless playback of the next
- * queued song, but does not implement any kind of sophisticated queing or
- * playback control; these should be handled at a higher level.
+ * TODO.
*/
class AudioPlayback {
public:
- enum Error { FATFS_INIT, I2S_INIT, PIPELINE_INIT };
- static auto create(std::unique_ptr<IAudioOutput> output)
+ enum Error { ERR_INIT_ELEMENT, ERR_MEM };
+ static auto create(drivers::GpioExpander* expander,
+ std::shared_ptr<drivers::SdStorage> storage)
-> cpp::result<std::unique_ptr<AudioPlayback>, Error>;
- AudioPlayback(std::unique_ptr<IAudioOutput>& output,
- audio_pipeline_handle_t pipeline,
- audio_element_handle_t source_element,
- audio_event_iface_handle_t event_interface);
+ // TODO(jacqueline): configure on the fly once we have things to configure.
+ AudioPlayback();
~AudioPlayback();
- /*
- * Replaces any currently playing file with the one given, and begins
- * playback.
- *
- * Any value set in `set_next_file` is cleared by this method.
- */
auto Play(const std::string& filename) -> void;
- /* Toogle between resumed and paused. */
- auto Toggle() -> void;
- auto Resume() -> void;
- auto Pause() -> void;
-
- enum PlaybackState { PLAYING, PAUSED, STOPPED };
- auto GetPlaybackState() const -> PlaybackState;
-
- /*
- * Handles any pending events from the underlying audio pipeline. This must
- * be called regularly in order to handle configuring the I2S stream for
- * different audio types (e.g. sample rate, bit depth), and for gapless
- * playback.
- */
- auto ProcessEvents(uint16_t max_time_ms) -> void;
-
- /*
- * Sets the file that should be played immediately after the current file
- * finishes. This is used for gapless playback
- */
- auto SetNextFile(const std::string& filename) -> void;
-
- auto SetVolume(uint8_t volume) -> void;
- auto GetVolume() const -> uint8_t;
// Not copyable or movable.
AudioPlayback(const AudioPlayback&) = delete;
AudioPlayback& operator=(const AudioPlayback&) = delete;
private:
- PlaybackState playback_state_;
-
- enum Decoder { NONE, MP3, AMR, OPUS, OGG, FLAC, WAV, AAC };
- auto GetDecoderForFilename(std::string filename) const -> Decoder;
- auto CreateDecoder(Decoder decoder) const -> audio_element_handle_t;
- auto ReconfigurePipeline(Decoder decoder) -> void;
-
- std::unique_ptr<IAudioOutput> output_;
-
- std::string next_filename_ = "";
-
- audio_pipeline_handle_t pipeline_;
- audio_element_handle_t source_element_;
- audio_event_iface_handle_t event_interface_;
+ auto ConnectElements(IAudioElement* src, IAudioElement* sink) -> void;
- audio_element_handle_t decoder_ = nullptr;
- Decoder decoder_type_ = NONE;
+ StreamBuffer stream_start_;
+ StreamBuffer stream_end_;
+ std::vector<std::unique_ptr<StreamBuffer>> element_buffers_;
};
-} // namespace drivers
+} // namespace audio