-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cd-reader.h
99 lines (80 loc) · 2.05 KB
/
cd-reader.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef CD_READER_H
#define CD_READER_H
#include <array>
#include <cstddef>
#include <filesystem>
#include "libraries/clowncd/clowncd.h"
#include "sdl-wrapper.h"
class CDReader
{
public:
enum class PlaybackSetting
{
ALL,
ONCE,
REPEAT
};
using SectorIndex = cc_u32f;
using TrackIndex = cc_u16f;
using FrameIndex = std::size_t;
private:
class ClownCDWrapper
{
private:
bool open = false;
public:
ClownCD data;
ClownCDWrapper() {}
ClownCDWrapper(ClownCD clowncd) { Open(clowncd); }
~ClownCDWrapper() { Close(); }
ClownCDWrapper(const ClownCDWrapper &other) = delete;
ClownCDWrapper(ClownCDWrapper &&other) = delete;
ClownCDWrapper& operator=(const ClownCDWrapper &other) = delete;
ClownCDWrapper& operator=(ClownCDWrapper &&other) = delete;
void Open(const ClownCD clowncd)
{
if (IsOpen())
Close();
data = clowncd;
open = true;
}
void Close()
{
if (!IsOpen())
return;
ClownCD_Close(&data);
open = false;
}
bool IsOpen() const
{
return open;
}
};
ClownCDWrapper clowncd;
PlaybackSetting playback_setting = PlaybackSetting::ALL;
bool audio_playing = false;
public:
struct State
{
CDReader::TrackIndex track_index;
CDReader::SectorIndex sector_index;
CDReader::FrameIndex frame_index;
PlaybackSetting playback_setting;
bool audio_playing;
};
static constexpr cc_u16f SECTOR_SIZE = 2048;
using Sector = std::array<cc_u8l, SECTOR_SIZE>;
CDReader() = default;
void Open(SDL::IOStream &&stream, const std::filesystem::path &path);
void Close() { clowncd.Close(); }
bool IsOpen() const { return clowncd.IsOpen(); }
bool SeekToSector(SectorIndex sector_index);
bool SeekToFrame(FrameIndex frame_index);
Sector ReadSector();
Sector ReadSector(SectorIndex sector_index);
bool PlayAudio(TrackIndex track_index, PlaybackSetting setting);
cc_u32f ReadAudio(cc_s16l *sample_buffer, cc_u32f total_frames);
State GetState();
bool SetState(const State &state);
};
#endif // CD_READER_H