summaryrefslogtreecommitdiff
path: root/src/drivers/include/playback.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-07 12:01:29 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-07 12:01:29 +1100
commit28d73ad8660e27f9c7b20b6e978d3d0c412dec00 (patch)
treec50b739ae4712f5ddb9fb6e44e39e01e4c20356d /src/drivers/include/playback.hpp
parentb13a9793e17e7e0e52ea08fa5fb69ca9b90ad56d (diff)
downloadtangara-fw-28d73ad8660e27f9c7b20b6e978d3d0c412dec00.tar.gz
Split driver-y things into a separate component
Diffstat (limited to 'src/drivers/include/playback.hpp')
-rw-r--r--src/drivers/include/playback.hpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/drivers/include/playback.hpp b/src/drivers/include/playback.hpp
new file mode 100644
index 00000000..493dd311
--- /dev/null
+++ b/src/drivers/include/playback.hpp
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "dac.hpp"
+#include "storage.hpp"
+
+#include <cstdint>
+#include <memory>
+#include <string>
+
+#include "audio_common.h"
+#include "audio_element.h"
+#include "audio_event_iface.h"
+#include "audio_pipeline.h"
+#include "esp_err.h"
+#include "fatfs_stream.h"
+#include "i2s_stream.h"
+#include "mp3_decoder.h"
+#include "result.hpp"
+
+namespace gay_ipod {
+
+class DacAudioPlayback {
+ public:
+ enum Error { PIPELINE_INIT };
+ static auto create(AudioDac* dac)
+ -> cpp::result<std::unique_ptr<DacAudioPlayback>, Error>;
+
+ DacAudioPlayback(AudioDac* dac,
+ audio_pipeline_handle_t pipeline,
+ audio_element_handle_t fatfs_stream_reader,
+ audio_element_handle_t i2s_stream_writer,
+ audio_event_iface_handle_t event_interface,
+ audio_element_handle_t mp3_decoder);
+ ~DacAudioPlayback();
+
+ void Play(const std::string& filename);
+ void Resume();
+ void Pause();
+
+ void ProcessEvents();
+
+ /* for gapless */
+ void set_next_file(const std::string& filename);
+
+ void set_volume(uint8_t volume);
+ auto volume() -> uint8_t;
+
+ // Not copyable or movable.
+ DacAudioPlayback(const DacAudioPlayback&) = delete;
+ DacAudioPlayback& operator=(const DacAudioPlayback&) = delete;
+
+ private:
+ AudioDac* dac_;
+ std::mutex playback_lock_;
+
+ std::string next_filename_;
+ uint8_t volume_;
+
+ audio_pipeline_handle_t pipeline_;
+ audio_element_handle_t fatfs_stream_reader_;
+ audio_element_handle_t i2s_stream_writer_;
+ audio_event_iface_handle_t event_interface_;
+
+ audio_element_handle_t mp3_decoder_;
+};
+
+} // namespace gay_ipod