-
Notifications
You must be signed in to change notification settings - Fork 1
/
s3mfile.h
124 lines (100 loc) · 2.21 KB
/
s3mfile.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
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
#pragma once
#include <cstdint>
#include <cstdio>
namespace S3M {
struct Instrument {
struct {
uint8_t type;
char filename[12];
struct {
uint8_t memseg[3];
inline uint32_t ptr() {
return (((uint32_t)memseg[0] << 16) + ((uint32_t)memseg[2] << 8) + (uint32_t)memseg[1]) * 16UL;
}
} memseg;
uint32_t length;
uint32_t loop_begin;
uint32_t loop_end;
uint8_t volume;
uint8_t dummy;
uint8_t pack_scheme;
uint8_t flags;
uint32_t c4spd;
uint8_t dummy2[12];
char sample_name[28];
uint8_t scrs[4];
} __attribute__((packed)) header;
uint8_t *sample_data;
Instrument() : sample_data(nullptr) {
}
~Instrument() {
if(sample_data)
delete [] sample_data;
}
void load(FILE* fp);
};
struct Slot {
uint8_t channel;
uint8_t note;
uint8_t instrument;
uint8_t volume;
uint8_t command;
uint8_t infobyte;
void load(uint8_t *&ptr);
void print() const;
inline int base_note() const {
return (note>>4)*12 + (note&0x0F);
}
};
struct Row {
struct Slot slots[32]; //maximum 32 channels, so a maximum of 32 slots per row
int num_slots;
void load(uint8_t *&ptr);
void print() const;
inline Slot* begin() {
return slots;
}
inline const Slot* begin() const {
return slots;
}
inline Slot* end() {
return slots + num_slots;
}
inline const Slot* end() const {
return slots + num_slots;
}
};
struct Pattern {
struct Row rows[64]; //there are always 64 rows in a pattern
void load(FILE* fp);
};
struct File {
struct {
char name[28];
uint8_t eofchar;
uint8_t type;
uint8_t dummy[2];
uint16_t num_orders;
uint16_t num_instruments;
uint16_t num_patterns;
uint16_t flags;
uint16_t version;
uint16_t ffi; //signed/unsigned samples
char scrm[4];
uint8_t global_volume; //Vxx
uint8_t initial_speed; //Axx
uint8_t initial_tempo; //Txx
uint8_t master_volume;
uint8_t uc; //ultraclick removal
uint8_t default_panning;
uint8_t dummy2[8];
uint16_t special;
uint8_t channel_settings[32];
} __attribute__((packed)) header;
uint8_t orders[256];
struct Instrument instruments[99];
struct Pattern patterns[100];
float panning[32];
void load(const char* filename);
};
}