Debian Codegraph @

debian/patches/Move-definitions-that-don-t-need-to-be-exposed-from-opl.h.patch

raw
1 From: Carl Reinke <[email protected]>
2 Date: Sun, 14 Jun 2020 14:11:00 -0600
3 Subject: Move definitions that don't need to be exposed from opl.h to opl.c
4
5 Origin: upstream, https://github.com/opentyrian/opentyrian/commit/962ee8fc46ca51691bde1c8c1022dacbe8a037ed
6 Bug-Debian: https://bugs.debian.org/966066
7 ---
8 src/opl.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
9 src/opl.h | 157 ++------------------------------------------------------------
10 2 files changed, 154 insertions(+), 156 deletions(-)
11
12 diff --git a/src/opl.c b/src/opl.c
13 index a4071c5..f15474c 100644
14 --- a/src/opl.c
15 +++ b/src/opl.c
16 @@ -23,12 +23,161 @@
17 * Copyright (C) 1998-2001 Ken Silverman
18 * Ken Silverman's official web site: "http://www.advsys.net/ken"
19 */
20 -
21 +#include "opl.h"
22
23 #include <math.h>
24 +#include <stdbool.h>
25 #include <stdlib.h> // rand()
26 #include <string.h> // memset()
27 -#include "opl.h"
28 +
29 +#define fltype double
30 +
31 + /*
32 + define attribution that inlines/forces inlining of a function (optional)
33 + */
34 +#define OPL_INLINE inline
35 +
36 +
37 +#undef NUM_CHANNELS
38 +#if defined(OPLTYPE_IS_OPL3)
39 +#define NUM_CHANNELS 18
40 +#else
41 +#define NUM_CHANNELS 9
42 +#endif
43 +
44 +#define MAXOPERATORS (NUM_CHANNELS*2)
45 +
46 +
47 +#define FL05 ((fltype)0.5)
48 +#define FL2 ((fltype)2.0)
49 +#define PI ((fltype)3.1415926535897932384626433832795)
50 +
51 +
52 +#define FIXEDPT 0x10000 // fixed-point calculations using 16+16
53 +#define FIXEDPT_LFO 0x1000000 // fixed-point calculations using 8+24
54 +
55 +#define WAVEPREC 1024 // waveform precision (10 bits)
56 +
57 +#define INTFREQU ((fltype)(14318180.0 / 288.0)) // clocking of the chip
58 +
59 +
60 +#define OF_TYPE_ATT 0
61 +#define OF_TYPE_DEC 1
62 +#define OF_TYPE_REL 2
63 +#define OF_TYPE_SUS 3
64 +#define OF_TYPE_SUS_NOKEEP 4
65 +#define OF_TYPE_OFF 5
66 +
67 +#define ARC_CONTROL 0x00
68 +#define ARC_TVS_KSR_MUL 0x20
69 +#define ARC_KSL_OUTLEV 0x40
70 +#define ARC_ATTR_DECR 0x60
71 +#define ARC_SUSL_RELR 0x80
72 +#define ARC_FREQ_NUM 0xa0
73 +#define ARC_KON_BNUM 0xb0
74 +#define ARC_PERC_MODE 0xbd
75 +#define ARC_FEEDBACK 0xc0
76 +#define ARC_WAVE_SEL 0xe0
77 +
78 +#define ARC_SECONDSET 0x100 // second operator set for OPL3
79 +
80 +
81 +#define OP_ACT_OFF 0x00
82 +#define OP_ACT_NORMAL 0x01 // regular channel activated (bitmasked)
83 +#define OP_ACT_PERC 0x02 // percussion channel activated (bitmasked)
84 +
85 +#define BLOCKBUF_SIZE 512
86 +
87 +
88 + // vibrato constants
89 +#define VIBTAB_SIZE 8
90 +#define VIBFAC 70/50000 // no braces, integer mul/div
91 +
92 + // tremolo constants and table
93 +#define TREMTAB_SIZE 53
94 +#define TREM_FREQ ((fltype)(3.7)) // tremolo at 3.7hz
95 +
96 +
97 + /* operator struct definition
98 + For OPL2 all 9 channels consist of two operators each, carrier and modulator.
99 + Channel x has operators x as modulator and operators (9+x) as carrier.
100 + For OPL3 all 18 channels consist either of two operators (2op mode) or four
101 + operators (4op mode) which is determined through register4 of the second
102 + adlib register set.
103 + Only the channels 0,1,2 (first set) and 9,10,11 (second set) can act as
104 + 4op channels. The two additional operators for a channel y come from the
105 + 2op channel y+3 so the operatorss y, (9+y), y+3, (9+y)+3 make up a 4op
106 + channel.
107 + */
108 +typedef struct operator_struct {
109 + Bit32s cval, lastcval; // current output/last output (used for feedback)
110 + Bit32u tcount, wfpos, tinc; // time (position in waveform) and time increment
111 + fltype amp, step_amp; // and amplification (envelope)
112 + fltype vol; // volume
113 + fltype sustain_level; // sustain level
114 + Bit32s mfbi; // feedback amount
115 + fltype a0, a1, a2, a3; // attack rate function coefficients
116 + fltype decaymul, releasemul; // decay/release rate functions
117 + Bit32u op_state; // current state of operator (attack/decay/sustain/release/off)
118 + Bit32u toff;
119 + Bit32s freq_high; // highest three bits of the frequency, used for vibrato calculations
120 + Bit16s* cur_wform; // start of selected waveform
121 + Bit32u cur_wmask; // mask for selected waveform
122 + Bit32u act_state; // activity state (regular, percussion)
123 + bool sus_keep; // keep sustain level when decay finished
124 + bool vibrato,tremolo; // vibrato/tremolo enable bits
125 +
126 + // variables used to provide non-continuous envelopes
127 + Bit32u generator_pos; // for non-standard sample rates we need to determine how many samples have passed
128 + Bits cur_env_step; // current (standardized) sample position
129 + Bits env_step_a,env_step_d,env_step_r; // number of std samples of one step (for attack/decay/release mode)
130 + Bit8u step_skip_pos_a; // position of 8-cyclic step skipping (always 2^x to check against mask)
131 + Bits env_step_skip_a; // bitmask that determines if a step is skipped (respective bit is zero then)
132 +
133 +#if defined(OPLTYPE_IS_OPL3)
134 + bool is_4op,is_4op_attached; // base of a 4op channel/part of a 4op channel
135 + Bit32s left_pan,right_pan; // opl3 stereo panning amount
136 +#endif
137 +} op_type;
138 +
139 +// per-chip variables
140 +static op_type op[MAXOPERATORS];
141 +
142 +static Bits int_samplerate;
143 +
144 +static Bit8u status;
145 +static Bit32u opl_index;
146 +#if defined(OPLTYPE_IS_OPL3)
147 +static Bit8u adlibreg[512]; // adlib register set (including second set)
148 +static Bit8u wave_sel[44]; // waveform selection
149 +#else
150 +static Bit8u adlibreg[256]; // adlib register set
151 +static Bit8u wave_sel[22]; // waveform selection
152 +#endif
153 +
154 +
155 + // vibrato/tremolo increment/counter
156 +static Bit32u vibtab_pos;
157 +static Bit32u vibtab_add;
158 +static Bit32u tremtab_pos;
159 +static Bit32u tremtab_add;
160 +
161 +
162 +// enable an operator
163 +void enable_operator(Bitu regbase, op_type* op_pt, Bit32u act_type);
164 +
165 +// functions to change parameters of an operator
166 +void change_frequency(Bitu chanbase, Bitu regbase, op_type* op_pt);
167 +
168 +void change_attackrate(Bitu regbase, op_type* op_pt);
169 +void change_decayrate(Bitu regbase, op_type* op_pt);
170 +void change_releaserate(Bitu regbase, op_type* op_pt);
171 +void change_sustainlevel(Bitu regbase, op_type* op_pt);
172 +void change_waveform(Bitu regbase, op_type* op_pt);
173 +void change_keepsustain(Bitu regbase, op_type* op_pt);
174 +void change_vibrato(Bitu regbase, op_type* op_pt);
175 +void change_feedback(Bitu chanbase, op_type* op_pt);
176 +
177
178 static Bit32u generator_add; // should be a chip parameter
179
180 diff --git a/src/opl.h b/src/opl.h
181 index c8e643b..cbb56ad 100644
182 --- a/src/opl.h
183 +++ b/src/opl.h
184 @@ -25,11 +25,8 @@
185 * Ken Silverman's official web site: "http://www.advsys.net/ken"
186 */
187
188 -
189 -#define fltype double
190 -
191 -#include <stdbool.h>
192 #include <stdint.h>
193 +
194 typedef uintptr_t Bitu;
195 typedef intptr_t Bits;
196 typedef uint32_t Bit32u;
197 @@ -39,154 +36,6 @@ typedef int16_t Bit16s;
198 typedef uint8_t Bit8u;
199 typedef int8_t Bit8s;
200
201 -
202 -/*
203 - define attribution that inlines/forces inlining of a function (optional)
204 -*/
205 -#define OPL_INLINE inline
206 -
207 -
208 -#undef NUM_CHANNELS
209 -#if defined(OPLTYPE_IS_OPL3)
210 -#define NUM_CHANNELS 18
211 -#else
212 -#define NUM_CHANNELS 9
213 -#endif
214 -
215 -#define MAXOPERATORS (NUM_CHANNELS*2)
216 -
217 -
218 -#define FL05 ((fltype)0.5)
219 -#define FL2 ((fltype)2.0)
220 -#define PI ((fltype)3.1415926535897932384626433832795)
221 -
222 -
223 -#define FIXEDPT 0x10000 // fixed-point calculations using 16+16
224 -#define FIXEDPT_LFO 0x1000000 // fixed-point calculations using 8+24
225 -
226 -#define WAVEPREC 1024 // waveform precision (10 bits)
227 -
228 -#define INTFREQU ((fltype)(14318180.0 / 288.0)) // clocking of the chip
229 -
230 -
231 -#define OF_TYPE_ATT 0
232 -#define OF_TYPE_DEC 1
233 -#define OF_TYPE_REL 2
234 -#define OF_TYPE_SUS 3
235 -#define OF_TYPE_SUS_NOKEEP 4
236 -#define OF_TYPE_OFF 5
237 -
238 -#define ARC_CONTROL 0x00
239 -#define ARC_TVS_KSR_MUL 0x20
240 -#define ARC_KSL_OUTLEV 0x40
241 -#define ARC_ATTR_DECR 0x60
242 -#define ARC_SUSL_RELR 0x80
243 -#define ARC_FREQ_NUM 0xa0
244 -#define ARC_KON_BNUM 0xb0
245 -#define ARC_PERC_MODE 0xbd
246 -#define ARC_FEEDBACK 0xc0
247 -#define ARC_WAVE_SEL 0xe0
248 -
249 -#define ARC_SECONDSET 0x100 // second operator set for OPL3
250 -
251 -
252 -#define OP_ACT_OFF 0x00
253 -#define OP_ACT_NORMAL 0x01 // regular channel activated (bitmasked)
254 -#define OP_ACT_PERC 0x02 // percussion channel activated (bitmasked)
255 -
256 -#define BLOCKBUF_SIZE 512
257 -
258 -
259 -// vibrato constants
260 -#define VIBTAB_SIZE 8
261 -#define VIBFAC 70/50000 // no braces, integer mul/div
262 -
263 -// tremolo constants and table
264 -#define TREMTAB_SIZE 53
265 -#define TREM_FREQ ((fltype)(3.7)) // tremolo at 3.7hz
266 -
267 -
268 -/* operator struct definition
269 - For OPL2 all 9 channels consist of two operators each, carrier and modulator.
270 - Channel x has operators x as modulator and operators (9+x) as carrier.
271 - For OPL3 all 18 channels consist either of two operators (2op mode) or four
272 - operators (4op mode) which is determined through register4 of the second
273 - adlib register set.
274 - Only the channels 0,1,2 (first set) and 9,10,11 (second set) can act as
275 - 4op channels. The two additional operators for a channel y come from the
276 - 2op channel y+3 so the operatorss y, (9+y), y+3, (9+y)+3 make up a 4op
277 - channel.
278 -*/
279 -typedef struct operator_struct {
280 - Bit32s cval, lastcval; // current output/last output (used for feedback)
281 - Bit32u tcount, wfpos, tinc; // time (position in waveform) and time increment
282 - fltype amp, step_amp; // and amplification (envelope)
283 - fltype vol; // volume
284 - fltype sustain_level; // sustain level
285 - Bit32s mfbi; // feedback amount
286 - fltype a0, a1, a2, a3; // attack rate function coefficients
287 - fltype decaymul, releasemul; // decay/release rate functions
288 - Bit32u op_state; // current state of operator (attack/decay/sustain/release/off)
289 - Bit32u toff;
290 - Bit32s freq_high; // highest three bits of the frequency, used for vibrato calculations
291 - Bit16s* cur_wform; // start of selected waveform
292 - Bit32u cur_wmask; // mask for selected waveform
293 - Bit32u act_state; // activity state (regular, percussion)
294 - bool sus_keep; // keep sustain level when decay finished
295 - bool vibrato,tremolo; // vibrato/tremolo enable bits
296 -
297 - // variables used to provide non-continuous envelopes
298 - Bit32u generator_pos; // for non-standard sample rates we need to determine how many samples have passed
299 - Bits cur_env_step; // current (standardized) sample position
300 - Bits env_step_a,env_step_d,env_step_r; // number of std samples of one step (for attack/decay/release mode)
301 - Bit8u step_skip_pos_a; // position of 8-cyclic step skipping (always 2^x to check against mask)
302 - Bits env_step_skip_a; // bitmask that determines if a step is skipped (respective bit is zero then)
303 -
304 -#if defined(OPLTYPE_IS_OPL3)
305 - bool is_4op,is_4op_attached; // base of a 4op channel/part of a 4op channel
306 - Bit32s left_pan,right_pan; // opl3 stereo panning amount
307 -#endif
308 -} op_type;
309 -
310 -// per-chip variables
311 -Bitu chip_num;
312 -op_type op[MAXOPERATORS];
313 -
314 -Bits int_samplerate;
315 -
316 -Bit8u status;
317 -Bit32u opl_index;
318 -#if defined(OPLTYPE_IS_OPL3)
319 -Bit8u adlibreg[512]; // adlib register set (including second set)
320 -Bit8u wave_sel[44]; // waveform selection
321 -#else
322 -Bit8u adlibreg[256]; // adlib register set
323 -Bit8u wave_sel[22]; // waveform selection
324 -#endif
325 -
326 -
327 -// vibrato/tremolo increment/counter
328 -Bit32u vibtab_pos;
329 -Bit32u vibtab_add;
330 -Bit32u tremtab_pos;
331 -Bit32u tremtab_add;
332 -
333 -
334 -// enable an operator
335 -void enable_operator(Bitu regbase, op_type* op_pt, Bit32u act_type);
336 -
337 -// functions to change parameters of an operator
338 -void change_frequency(Bitu chanbase, Bitu regbase, op_type* op_pt);
339 -
340 -void change_attackrate(Bitu regbase, op_type* op_pt);
341 -void change_decayrate(Bitu regbase, op_type* op_pt);
342 -void change_releaserate(Bitu regbase, op_type* op_pt);
343 -void change_sustainlevel(Bitu regbase, op_type* op_pt);
344 -void change_waveform(Bitu regbase, op_type* op_pt);
345 -void change_keepsustain(Bitu regbase, op_type* op_pt);
346 -void change_vibrato(Bitu regbase, op_type* op_pt);
347 -void change_feedback(Bitu chanbase, op_type* op_pt);
348 -
349 // general functions
350 void adlib_init(Bit32u samplerate);
351 void adlib_write(Bitu idx, Bit8u val);
352 @@ -195,8 +44,8 @@ void adlib_getsample(Bit16s* sndptr, Bits numsamples);
353 Bitu adlib_reg_read(Bitu port);
354 void adlib_write_index(Bitu port, Bit8u val);
355
356 -#endif /* OPL_H */
357 -
358 #define opl_init() adlib_init(OUTPUT_QUALITY * 11025)
359 #define opl_write(reg, val) adlib_write(reg, val)
360 #define opl_update(buf, num) adlib_getsample(buf, num)
361 +
362 +#endif /* OPL_H */