-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.h
More file actions
313 lines (253 loc) · 7.42 KB
/
Copy pathglobal.h
File metadata and controls
313 lines (253 loc) · 7.42 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*
* global.h
*
* Created on: 10 2012
* Author: R.K.
*/
#ifndef GLOBAL_H_
#define GLOBAL_H_
#define _GNU_SOURCE
#include <stdbool.h>
#include <stdint.h>
#include ".\fatfs\ff.h"
#define SYSCLK 80000000L
//#define SYSCLK 96000000L
//#define SYSCLK 200000000L
#define PATH "/mods"
#define BITDEPTH 11 // 11 bits PWM
//#define SAMPLERATE (SYSCLK / (1 << BITDEPTH)) // Best audio quality 96MHz / (1 << 11) = 46875Hz
#define SAMPLERATE (SYSCLK / (1 << BITDEPTH) / 2) // Medium audio quality 96MHz / (1 << 11) / 2 = 23437.5Hz
#define SOUNDBUFFERSIZE 512 // Stereo circular sound buffer 2 * 2048 = 4096 bytes of memory
#define FATBUFFERSIZE 1024 // File system buffers CHANNELS * 512 = 1152 bytes of memory
#define DIVIDER 10 // Fixed-point mantissa used for integer arithmetic
//MOD part
#define STEREOSEPARATION 64 // 0 (max) to 64 (mono)
// Hz = 14317056 / amigaPeriod
#define AMIGA (14317056 / SAMPLERATE << DIVIDER) //s3m player
#define AMIGA_MOD (7093789 / 2 / SAMPLERATE << DIVIDER) //MOD player
// Mixer.channelFrequency[channel] = AMIGA / amigaPeriod
#define ROWS 64
#define INSTRUMENTS 99
#define CHANNELS 14 //14
#define NONOTE 108
#define KEYOFF 109
#define NOVOLUME 255
//MOD Part
#define SAMPLES 31
#define NONOTE_MOD 0xFFFF
//#define LEDTRIS TRISE
//#define LEDLAT LATE
#define ENCODERRATE 5000
//#define ENCODERPORT PORTG
//#define ENCODERBTNPIN PORTFbits.RF0
#define ENCODERBTNPIN ButtonsPoll(0,0)&LEFT_BUTTON
#ifdef PLAYERSRC
#define EXTERN
#define INITIALIZER(...) = __VA_ARGS__
#else
#define EXTERN extern
#define INITIALIZER(...) /* nothing */
#endif
uint8_t nextprevfile;
uint8_t numsteps;
uint16_t modFileNumber;
//nextprevfile= 0;
/***************************************
* MOD section
***************************************/
typedef struct {
uint8_t name[22];
uint16_t length;
int8_t fineTune;
uint8_t volume;
uint16_t loopBegin;
uint16_t loopLength;
} MOD_Sample;
//MOD
typedef struct {
uint8_t sampleNumber[ROWS][CHANNELS];
uint16_t note[ROWS][CHANNELS];
uint8_t effectNumber[ROWS][CHANNELS];
uint8_t effectParameter[ROWS][CHANNELS];
} MOD_Pattern;
struct mod{
uint8_t name[20];
MOD_Sample samples[SAMPLES];
uint8_t songLength;
uint8_t numberOfPatterns;
uint8_t order[128];
uint8_t numberOfChannels;
};
struct mod_player{
MOD_Pattern currentPattern;
uint32_t amiga;
uint16_t samplesPerTick;
uint8_t speed;
uint8_t tick;
uint8_t row;
uint8_t lastRow;
uint8_t orderIndex;
uint8_t oldOrderIndex;
uint8_t patternDelay;
uint8_t patternLoopCount[CHANNELS];
uint8_t patternLoopRow[CHANNELS];
uint8_t lastSampleNumber[CHANNELS];
int8_t volume[CHANNELS];
uint16_t lastNote[CHANNELS];
uint16_t amigaPeriod[CHANNELS];
int16_t lastAmigaPeriod[CHANNELS];
uint16_t portamentoNote[CHANNELS];
uint8_t portamentoSpeed[CHANNELS];
uint8_t waveControl[CHANNELS];
uint8_t vibratoSpeed[CHANNELS];
uint8_t vibratoDepth[CHANNELS];
int8_t vibratoPos[CHANNELS];
uint8_t tremoloSpeed[CHANNELS];
uint8_t tremoloDepth[CHANNELS];
int8_t tremoloPos[CHANNELS];
};
/***************************************
* S3m section
***************************************/
//S3m
typedef struct {
uint8_t name[28];
uint16_t sampleParapointer;
uint16_t length;
uint16_t loopBegin;
uint16_t loopEnd;
uint8_t volume;
uint16_t middleC;
bool loop;
} S3M_Instrument;
//s3m
typedef struct{
uint16_t note[ROWS][CHANNELS];
uint8_t instrumentNumber[ROWS][CHANNELS];
uint8_t volume[ROWS][CHANNELS];
uint8_t effectNumber[ROWS][CHANNELS];
uint8_t effectParameter[ROWS][CHANNELS];
} S3M_Pattern;
//s3m
struct s3m{
uint8_t name[28];
S3M_Instrument instruments[INSTRUMENTS];
uint16_t songLength;
uint16_t numberOfInstruments;
uint16_t numberOfPatterns;
bool fastVolumeSlides;
uint8_t globalVolume;
uint8_t order[256];
uint8_t numberOfChannels;
uint8_t channelRemapping[CHANNELS];
uint16_t instrumentParapointers[INSTRUMENTS];
uint16_t patternParapointers[256];
};
struct s3m_player{
S3M_Pattern currentPattern;
uint32_t amiga;
uint16_t samplesPerTick;
uint8_t speed;
uint8_t tick;
uint8_t row;
uint8_t lastRow;
uint8_t orderIndex;
uint8_t oldOrderIndex;
uint8_t patternDelay;
uint8_t patternLoopCount[CHANNELS];
uint8_t patternLoopRow[CHANNELS];
uint8_t lastInstrumentNumber[CHANNELS];
int8_t volume[CHANNELS];
uint16_t lastNote[CHANNELS];
uint16_t amigaPeriod[CHANNELS];
int16_t lastAmigaPeriod[CHANNELS];
uint8_t lastVolumeSlide[CHANNELS];
uint8_t lastPortamento[CHANNELS];
uint16_t portamentoNote[CHANNELS];
uint8_t portamentoSpeed[CHANNELS];
uint8_t waveControl[CHANNELS];
uint8_t vibratoSpeed[CHANNELS];
uint8_t vibratoDepth[CHANNELS];
int8_t vibratoPos[CHANNELS];
uint8_t tremoloSpeed[CHANNELS];
uint8_t tremoloDepth[CHANNELS];
int8_t tremoloPos[CHANNELS];
uint8_t tremorOnOff[CHANNELS];
uint8_t tremorCount[CHANNELS];
uint8_t retriggerVolumeSlide[CHANNELS];
uint8_t retriggerSpeed[CHANNELS];
};
/***************************************
* Common section
***************************************/
union umod{
struct mod Mod;
struct s3m S3m;
};
union player{
struct mod_player Mod_player;
struct s3m_player S3m_player;
};
//s3m mixer is used for both mod and s3m since it is big enough for both
struct mixer{
uint32_t sampleBegin[INSTRUMENTS];
uint32_t sampleEnd[INSTRUMENTS];
uint32_t sampleLoopBegin[INSTRUMENTS];
uint16_t sampleLoopLength[INSTRUMENTS];
uint32_t sampleLoopEnd[INSTRUMENTS];
uint8_t channelSampleNumber[CHANNELS];
uint32_t channelSampleOffset[CHANNELS];
uint16_t channelFrequency[CHANNELS];
uint8_t channelVolume[CHANNELS];
uint8_t channelPanning[CHANNELS];
};
//Identical
struct fatBuffer{
uint8_t channels[CHANNELS][FATBUFFERSIZE];
uint32_t samplePointer[CHANNELS];
uint8_t channelSampleNumber[CHANNELS];
};
//identical
struct soundBuffer{
uint16_t left[SOUNDBUFFERSIZE];
uint16_t right[SOUNDBUFFERSIZE];
uint16_t writePos;
volatile uint16_t readPos;
};
typedef struct{
char szFileExt[5];
void (*player)(void);
void (*mixer)(void);
void (*loader)(void);
uint16_t (*getSamplesPerTick)(void);
}FileHandler;
#ifdef PLAYERSRC
union player uPlayer;
union umod uMod;
struct soundBuffer SoundBuffer;
struct mixer Mixer;
//Fat stuff
FATFS fso; // The FATFS structure (file system object) holds dynamic work area of individual logical drives
DIR dir; // The DIR structure is used for the work area to read a directory by f_oepndir, f_readdir function
FILINFO fileInfo; // The FILINFO structure holds a file information returned by f_stat and f_readdir function
FIL file; // The FIL structure (file object) holds state of an open file
struct fatBuffer FatBuffer;
#else
extern union player uPlayer;
extern union umod uMod;
extern struct soundBuffer SoundBuffer;
extern struct mixer Mixer;
extern struct fatBuffer FatBuffer;
extern FATFS fso; // The FATFS structure (file system object) holds dynamic work area of individual logical drives
extern DIR dir; // The DIR structure is used for the work area to read a directory by f_oepndir, f_readdir function
extern FILINFO fileInfo; // The FILINFO structure holds a file information returned by f_stat and f_readdir function
extern FIL file; // The FIL structure (file object) holds state of an open file
#endif
//prototypes
void player();
void mixer();
void loadNextFile();
void loadPreviousFile();
void loadRandomFile(uint8_t);
uint16_t getSamplesPerTick();
#endif /* GLOBAL_H_ */