-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3mContainer.hpp
213 lines (172 loc) · 5.09 KB
/
s3mContainer.hpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* s3mContainer.hpp
*
* Created on: Sep 11, 2017
* Author: jussi
*/
#ifndef S3MCONTAINER_HPP_
#define S3MCONTAINER_HPP_
#include "Types.hpp"
#include "ALSAPlayer.hpp"
#include <stdio.h>
#include <vector>
#include <memory>
struct Instrument{
byte type;
char filename[12];
byte memSeg[3];
int32_t length;
int32_t HIleng;
int32_t loopBegin;
int32_t HILbeg;
int32_t loopEnd;
int32_t HILend;
byte volume;
byte packFlag;
byte flags;
uint32_t c4Speed;
byte* sampleData;
byte* sampleDataL;
byte* sampleDataR;
double c4SpeedFactor;
byte name[28];
byte scrs[4];
bool stereo;
Instrument () :
type(0),
length(0),
HIleng(0),
loopBegin(0),
HILbeg(0),
loopEnd(0),
HILend(0),
volume(0),
packFlag(0),
flags(0),
c4Speed(0),
sampleData(nullptr),
sampleDataL(nullptr),
sampleDataR(nullptr),
c4SpeedFactor(0.0),
stereo(false)
{}
};
struct Channel{
uint32_t lastInstrument;
uint32_t baseNote;
double sampleOffset;
uint32_t vibratoOffset;
double livePeriod;
double slideToPeriod;
double stablePeriod;
double liveHz;
int volume;
uint32_t arpeggio;
uint32_t cacheVolumeSlide, cachePitchSlide;
uint32_t cacheVibratoHi, cacheVibratoLo;
uint32_t cacheTremoloHi, cacheTremoloLo;
uint32_t cachePortamento;
uint32_t cacheArpeggio;
Channel() :
lastInstrument(0),
baseNote(255),
sampleOffset(0.0),
vibratoOffset(0),
livePeriod(0.0),
slideToPeriod(0.0),
stablePeriod(0),
liveHz(0.0),
volume(0),
arpeggio(0),
cacheVolumeSlide(0),
cachePitchSlide(0),
cacheVibratoHi(0),
cacheVibratoLo(0),
cacheTremoloHi(0),
cacheTremoloLo(0),
cachePortamento(0),
cacheArpeggio(0)
{}
};
struct Slot{
uint32_t channel;
uint32_t note;
uint32_t instrument;
uint32_t volume;
uint32_t command;
uint32_t info;
};
class s3mContainer
{
public:
/*
* Constructor object
*/
s3mContainer();
/*
* Destructor
*/
~s3mContainer();
/*
* Load new song into this container entity
* @param filename: the filename to load. Should be in
* the same folder where the program is being run.
*/
void loadSong(const std::string& filename);
/*
* Play song that is currently loaded
*/
void playSong();
/*
* Request closing of the player
*/
void requestQuit();
/*
* Pause play
*/
void pause();
/*
* resume
*/
void resume();
private:
/*
* Private member functions
*/
static Slot readSlot(const byte*& pSlot);
static double loadSample(const Instrument& ins, double& s, double incRate);
static bool loadStereoSample(const Instrument& ins, double& s, double incRate, double& retL, double& retR);
/*
* Member variables
*/
char m_name[29]; // name, 28 chars with ending NUL
byte m_type; // File type = 16
uint16_t m_ordersNum; // Number of orders in file
uint16_t m_instrumentNum; // Number of instruments in file
uint16_t m_patternNum; // number of patterns
uint16_t m_flags; // flags, unsupported in latest tracker ver
uint16_t m_cwtv; // created with tracker version
uint16_t m_ffv; // File format version
char m_scrm[4]; // should contain SCRM
byte m_globalVolume; // global volume
byte m_initialSpeed; // initial speed
byte m_initialTempo; // initial tempo
byte m_masterVolume; // master volume
uint16_t m_special; // Special pointer, not used in ver 3
byte m_channelSettings[32]; // Channel setting for all 32 channels!
// bit 8: channel enabled
// bits 0-7: channel type
// 0..7 Left sample, 8..15 right sample, 16..31 Adlib channels (9 melody + 5 drums)
std::vector<byte> m_orders; // orders stored in a vector
std::vector<uint16_t> m_instrumentPPs; // file parapointers to instruments
std::vector<uint16_t> m_patternPPs; // file parapointers to patterns
std::vector<Instrument> m_instruments; // instrument vector
std::vector<std::vector<byte>> m_patternData; // store pattern data here
std::vector<byte*> m_patternEndPtr; // store pattern end pointers here
ALSAPlayer m_player; // ALSA Player class
uint32_t m_audioBufferSize; // size of audio buffer
std::vector<byte> m_audioBufferVector; //placeholder for audio buffer as vector
std::vector<std::string> m_playList; // playlist
uint32_t m_playerStatusFlags; // player status flags
}; // end class s3mContainer
#endif /* S3MCONTAINER_HPP_ */