-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod32.h
171 lines (140 loc) · 4.2 KB
/
mod32.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
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
#pragma once
/*
Original code by "Pascal Piazzalunga" - http://www.serveurperso.com
Adapted for bitbox by makapuf - makapuf2@gmail.com
adapted for Beat Blocks by makapuf 2014
*/
#include <stdbool.h>
#include <stdint.h>
#define SAMPLERATE BITBOX_SAMPLERATE
#define BITDEPTH BITBOX_SAMPLE_BITDEPTH
#define FATBUFFERSIZE 2048 // File system buffers CHANNELS * 2048 = 8192 bytes of memory
#define DIVIDER 10 // Fixed-point mantissa used for integer arithmetic
#define STEREOSEPARATION 32 // 0 (max) to 64 (mono)
// Hz = 7093789 / (amigaPeriod * 2) for PAL
// Hz = 7159091 / (amigaPeriod * 2) for NTSC
#define AMIGA (7093789 / 2 / SAMPLERATE << DIVIDER)
// Mixer.channelFrequency[channel] = AMIGA / amigaPeriod
#define ROWS 64
#define SAMPLES 31
#define CHANNELS 8 // changed from 18 to 4 - to 6
#define NONOTE 0xFFFF
typedef struct {
uint8_t name[22];
uint16_t length;
int8_t fineTune;
uint8_t volume;
uint16_t loopBegin;
uint16_t loopLength;
} Sample;
struct mod{
uint8_t name[20];
Sample samples[SAMPLES];
uint8_t songLength;
uint8_t numberOfPatterns;
uint8_t order[128];
uint8_t numberOfChannels;
};
typedef struct {
uint8_t sampleNumber[ROWS][CHANNELS];
uint16_t note[ROWS][CHANNELS];
uint8_t effectNumber[ROWS][CHANNELS];
uint8_t effectParameter[ROWS][CHANNELS];
} Pattern;
struct player{
Pattern currentPattern;
uint8_t follow_song; // follows song or keep playing same pattern?
uint32_t amiga;
uint16_t samplesPerTick;
uint8_t speed;
uint8_t tick;
uint8_t row;
uint8_t lastRow;
uint8_t orderIndex; // index in the list of songs to play
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];
};
struct mixer{
uint32_t sampleBegin[SAMPLES];
uint32_t sampleEnd[SAMPLES];
uint32_t sampleloopBegin[SAMPLES];
uint16_t sampleLoopLength[SAMPLES];
uint32_t sampleLoopEnd[SAMPLES];
uint8_t channelSampleNumber[CHANNELS];
uint32_t channelSampleOffset[CHANNELS];
uint16_t channelFrequency[CHANNELS];
uint8_t channelVolume[CHANNELS];
uint8_t channelPanning[CHANNELS];
};
struct fatBuffer{
uint8_t channels[CHANNELS][FATBUFFERSIZE];
uint32_t samplePointer[CHANNELS];
uint8_t channelSampleNumber[CHANNELS];
};
/*
struct soundBuffer{
uint16_t left[SOUNDBUFFERSIZE];
uint16_t right[SOUNDBUFFERSIZE];
uint16_t writePos;
volatile uint16_t readPos;
};
extern struct soundBuffer SoundBuffer;
This is replaced ont he bitbox by the sound driver buffer.
*/
extern struct player Player;
extern struct mod Mod;
extern struct mixer Mixer;
extern struct fatBuffer FatBuffer;
//prototypes
void loadMod(void);
void player(void);
uint16_t mixer(uint16_t *buffer);
void loadPattern(uint8_t pattern);
// Effects
#define ARPEGGIO 0x0
#define PORTAMENTOUP 0x1
#define PORTAMENTODOWN 0x2
#define TONEPORTAMENTO 0x3
#define VIBRATO 0x4
#define PORTAMENTOVOLUMESLIDE 0x5
#define VIBRATOVOLUMESLIDE 0x6
#define TREMOLO 0x7
#define SETCHANNELPANNING 0x8
#define SETSAMPLEOFFSET 0x9
#define VOLUMESLIDE 0xA
#define JUMPTOORDER 0xB
#define SETVOLUME 0xC
#define BREAKPATTERNTOROW 0xD
#define SETSPEED 0xF
// 0xE subset
#define SETFILTER 0x0
#define FINEPORTAMENTOUP 0x1
#define FINEPORTAMENTODOWN 0x2
#define GLISSANDOCONTROL 0x3
#define SETVIBRATOWAVEFORM 0x4
#define SETFINETUNE 0x5
#define PATTERNLOOP 0x6
#define SETTREMOLOWAVEFORM 0x7
#define RETRIGGERNOTE 0x9
#define FINEVOLUMESLIDEUP 0xA
#define FINEVOLUMESLIDEDOWN 0xB
#define NOTECUT 0xC
#define NOTEDELAY 0xD
#define PATTERNDELAY 0xE
#define INVERTLOOP 0xF