blob: 493dd31154618d97ac894933574bb5c775bca7f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
|