Debian Codegraph @

src/pt2_paula.c

raw symbols SCIP
1 /* Simple Paula emulator (with BLEP synthesis by aciddose).
2 ** Limitation: The audio output frequency can't be below 31389Hz ( ceil(PAULA_PAL_CLK / 113.0) )
3 **
4 ** WARNING: These functions must not be called while paulaGenerateSamples() is running!
5 ** If so, lock the audio first so that you're sure it's not running.
6 */
7
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <string.h>
11 #include <math.h>
12 #include "pt2_header.h"cxx . . $ `<file>/src/pt2_header.h`/ // PI
13 #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/
14 #include "pt2_paula.h"cxx . . $ `<file>/src/pt2_paula.h`/
15 #include "pt2_blep.h"cxx . . $ `<file>/src/pt2_blep.h`/
16 #include "pt2_rcfilters.h"cxx . . $ `<file>/src/pt2_rcfilters.h`/
17
18 typedef struct voice_tcxx . . $ voice_t#
19 {
20 volatile boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! activecxx . . $ voice_t#active.;
21
22 // internal registers
23 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! sampleJustStartedcxx . . $ voice_t#sampleJustStarted., nextSampleStagecxx . . $ voice_t#nextSampleStage.;
24 int8_tcxx . . $ int8_t# AUD_DATcxx . . $ voice_t#AUD_DAT.[2]; // DMA data buffer
25 const int8_tcxx . . $ int8_t# *locationcxx . . $ voice_t#location.; // current location
26 uint16_tcxx . . $ uint16_t# lengthCountercxx . . $ voice_t#lengthCounter.; // current length
27 int32_tcxx . . $ int32_t# sampleCountercxx . . $ voice_t#sampleCounter.; // how many bytes left in AUD_DAT
28 float fSamplecxx . . $ voice_t#fSample.; // currently held sample point (multiplied by volume)
29 float fDeltacxx . . $ voice_t#fDelta., fPhasecxx . . $ voice_t#fPhase.;
30 float fBlepDeltacxx . . $ voice_t#fBlepDelta., fBlepPhasecxx . . $ voice_t#fBlepPhase.;
31
32 // registers modified by Paula functions
33 const int8_tcxx . . $ int8_t# *storedLocationcxx . . $ voice_t#storedLocation.; // data pointer
34 uint16_tcxx . . $ uint16_t# storedLengthcxx . . $ voice_t#storedLength.;
35 float fStoredVolcxx . . $ voice_t#fStoredVol., fStoredDeltacxx . . $ voice_t#fStoredDelta.;
36 } paulaVoice_tcxx . . $ paulaVoice_t#;
37
38 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! useLEDFiltercxx . . $ useLEDFilter., useLowpassFiltercxx . . $ useLowpassFilter., useHighpassFiltercxx . . $ useHighpassFilter.;
39 static int8_tcxx . . $ int8_t# nullSamplecxx . . $ nullSample.[0xFFFF*2]; // buffer for NULL data pointer
40 static float fPeriodToDeltaDivcxx . . $ fPeriodToDeltaDiv.;
41 static double dPaulaOutputFreqcxx . . $ dPaulaOutputFreq.;
42 static blep_tcxx . . $ blep_t# blepcxx . . $ blep.[PAULA_VOICEScxx . . $ `src/pt2_paula.h:13:9`!];
43 static onePoleFilter_tcxx . . $ onePoleFilter_t# filterLocxx . . $ filterLo., filterHicxx . . $ filterHi.;
44 static twoPoleFilter_tcxx . . $ twoPoleFilter_t# filterLEDcxx . . $ filterLED.;
45 static paulaVoice_tcxx . . $ paulaVoice_t# paulacxx . . $ paula.[PAULA_VOICEScxx . . $ `src/pt2_paula.h:13:9`!];
46
47 void paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(double dOutputFreq, uint32_tcxx . . $ uint32_t# amigaModel)
48 {
49 ASSERTcxx . . $ `src/pt2_header.h:25:9`!(dOutputFreq != 0.0);
50 dPaulaOutputFreqcxx . . $ dPaulaOutputFreq. = dOutputFreq;
51 fPeriodToDeltaDivcxx . . $ fPeriodToDeltaDiv. = (float)(PAULA_PAL_CLKcxx . . $ `src/pt2_paula.h:14:9`! / dPaulaOutputFreqcxx . . $ dPaulaOutputFreq.);
52
53 clearBlepStatecxx . . $ clearBlepState(49f6e7a06ebc5aa8).();
54
55 useLowpassFiltercxx . . $ useLowpassFilter. = useHighpassFiltercxx . . $ useHighpassFilter. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
56 clearOnePoleFilterStatecxx . . $ clearOnePoleFilterState(f6e1329b7fbf0464).(&filterLocxx . . $ filterLo.);
57 clearOnePoleFilterStatecxx . . $ clearOnePoleFilterState(f6e1329b7fbf0464).(&filterHicxx . . $ filterHi.);
58 clearTwoPoleFilterStatecxx . . $ clearTwoPoleFilterState(1647a0868bd893a0).(&filterLEDcxx . . $ filterLED.);
59
60 /*
61 ** Amiga 500/1200 filters
62 **
63 ** RC values for Amiga 500 (rev 6A):
64 ** - 1-pole (6dB/oct) RC low-pass: R=360 ohm, C=0.1uF
65 ** - 2-pole (12dB/oct) Sallen-Key low-pass ("LED"): R1/R2=10k ohm, C1=6800pF, C2=3900pF
66 ** - 1-pole (6dB/oct) RC high-pass: R=1390 ohm (1000+390), C=22.33uF (22+0.33)
67 **
68 ** RC values for Amiga 1200 (rev 1D4):
69 ** - 1-pole (6dB/oct) RC low-pass: R=680 ohm, C=6800pF
70 ** - 2-pole (12dB/oct) Sallen-Key low-pass ("LED"): R1/R2=10k ohm, C1=6800pF, C2=3900pF
71 ** - 1-pole (6dB/oct) RC high-pass: R=1360 ohm (1000+360), C=22uF
72 */
73 double R, C, R1, R2, C1, C2, cutoff, qfactor;
74
75 if (amigaModel == MODEL_A1200cxx . . $ MODEL_A1200.)
76 {
77 // Amiga 1200 rev 1D4
78
79 /* Don't handle the A1200 low-pass filter since its cutoff
80 ** is well above human hearable range anyway (~34.4kHz).
81 ** We don't do volume PWM, so we have nothing we need to
82 ** filter away.
83 */
84 useLowpassFiltercxx . . $ useLowpassFilter. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
85
86 // A1200 1-pole (6dB/oct) RC high-pass filter:
87 R = 1360.0; // R324 (1K ohm resistor) + R325 (360 ohm resistor)
88 C = 2.2e-5; // C334 (22uF capacitor)
89 cutoff = 1.0 / ((2.0 * PIcxx . . $ `src/pt2_header.h:67:9`!) * R * C); // ~5.319Hz
90 setupOnePoleFiltercxx . . $ setupOnePoleFilter(b75bf72749fa347e).(dPaulaOutputFreqcxx . . $ dPaulaOutputFreq., cutoff, &filterHicxx . . $ filterHi.);
91 }
92 else
93 {
94 // Amiga 500 rev 6A
95
96 // A500 1-pole (6dB/oct) RC low-pass filter:
97 R = 360.0; // R321 (360 ohm)
98 C = 1e-7; // C321 (0.1uF)
99 cutoff = 1.0 / ((2.0 * PIcxx . . $ `src/pt2_header.h:67:9`!) * R * C); // ~4420.971Hz
100 setupOnePoleFiltercxx . . $ setupOnePoleFilter(b75bf72749fa347e).(dPaulaOutputFreqcxx . . $ dPaulaOutputFreq., cutoff, &filterLocxx . . $ filterLo.);
101
102 // A500 1-pole (6dB/oct) RC high-pass filter:
103 R = 1390.0; // R324 (1K ohm) + R325 (390 ohm)
104 C = 2.233e-5; // C334 (22uF) + C335 (0.33uF)
105 cutoff = 1.0 / ((2.0 * PIcxx . . $ `src/pt2_header.h:67:9`!) * R * C); // ~5.128Hz
106 setupOnePoleFiltercxx . . $ setupOnePoleFilter(b75bf72749fa347e).(dPaulaOutputFreqcxx . . $ dPaulaOutputFreq., cutoff, &filterHicxx . . $ filterHi.);
107 }
108
109 // 2-pole (12dB/oct) Sallen-Key low-pass filter ("LED" filter, same values on A500/A1200):
110 R1 = 10000.0; // R322 (10K ohm)
111 R2 = 10000.0; // R323 (10K ohm)
112 C1 = 6.8e-9; // C322 (6800pF)
113 C2 = 3.9e-9; // C323 (3900pF)
114 cutoff = 1.0 / ((2.0 * PIcxx . . $ `src/pt2_header.h:67:9`!) * sqrt(R1 * R2 * C1 * C2)); // ~3090.533Hz
115 qfactor = sqrt(R1 * R2 * C1 * C2) / (C2 * (R1 + R2)); // ~0.660225
116 setupTwoPoleFiltercxx . . $ setupTwoPoleFilter(ae4e7863516b7826).(dPaulaOutputFreqcxx . . $ dPaulaOutputFreq., cutoff, qfactor, &filterLEDcxx . . $ filterLED.);
117 }
118
119 void paulaDisableFilterscxx . . $ paulaDisableFilters(49f6e7a06ebc5aa8).(void) // disables low-pass/high-pass filter ("LED" filter is kept)
120 {
121 useHighpassFiltercxx . . $ useHighpassFilter. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
122 useLowpassFiltercxx . . $ useLowpassFilter. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
123 }
124
125 int8_tcxx . . $ int8_t# *paulaGetNullSamplePtrcxx . . $ paulaGetNullSamplePtr(d09b239063734497).(void)
126 {
127 return nullSamplecxx . . $ nullSample.;
128 }
129
130 static inline void refetchPeriodcxx . . $ refetchPeriod(361ab4fa815c10fc).(paulaVoice_tcxx . . $ paulaVoice_t# *v) // Paula stage
131 {
132 v->fBlepPhasecxx . . $ voice_t#fBlepPhase. = v->fPhasecxx . . $ voice_t#fPhase.;
133 v->fBlepDeltacxx . . $ voice_t#fBlepDelta. = v->fDeltacxx . . $ voice_t#fDelta.;
134
135 // Paula only updates period (delta) during period refetching (this stage)
136 v->fDeltacxx . . $ voice_t#fDelta. = v->fStoredDeltacxx . . $ voice_t#fStoredDelta.;
137
138 v->nextSampleStagecxx . . $ voice_t#nextSampleStage. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
139 }
140
141 static inline void nextSamplecxx . . $ nextSample(293f0b9155a56260).(paulaVoice_tcxx . . $ paulaVoice_t# *v, blep_tcxx . . $ blep_t# *b) // Paula stage
142 {
143 if (v->sampleCountercxx . . $ voice_t#sampleCounter. == 0)
144 {
145 // it's time to read new samples from DMA
146
147 // don't update AUD_LEN/AUD_LC yet on DMA trigger
148 if (!v->sampleJustStartedcxx . . $ voice_t#sampleJustStarted.)
149 {
150 if (--v->lengthCountercxx . . $ voice_t#lengthCounter. == 0)
151 {
152 v->lengthCountercxx . . $ voice_t#lengthCounter. = v->storedLengthcxx . . $ voice_t#storedLength.;
153 v->locationcxx . . $ voice_t#location. = v->storedLocationcxx . . $ voice_t#storedLocation.;
154 }
155 }
156
157 v->sampleJustStartedcxx . . $ voice_t#sampleJustStarted. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
158
159 // fill DMA data buffer
160 v->AUD_DATcxx . . $ voice_t#AUD_DAT.[0] = *v->locationcxx . . $ voice_t#location.++;
161 v->AUD_DATcxx . . $ voice_t#AUD_DAT.[1] = *v->locationcxx . . $ voice_t#location.++;
162 v->sampleCountercxx . . $ voice_t#sampleCounter. = 2;
163 }
164
165 /* Pre-compute current sample point.
166 ** Output volume is only read from AUDxVOL at this stage,
167 ** and we don't emulate volume PWM anyway, so we can
168 ** pre-multiply by volume here.
169 */
170 v->fSamplecxx . . $ voice_t#fSample. = v->AUD_DATcxx . . $ voice_t#AUD_DAT.[0] * v->fStoredVolcxx . . $ voice_t#fStoredVol.; // -128..127 * 0.0f .. 1.0f
171
172 // fill BLEP buffer if the new sample differs from the old one
173 if (v->fSamplecxx . . $ voice_t#fSample. != b->fLastValuecxx . . $ blep_t#fLastValue.)
174 {
175 if (v->fBlepDeltacxx . . $ voice_t#fBlepDelta. > v->fBlepPhasecxx . . $ voice_t#fBlepPhase.) // also checks if v->fBlepDelta > 0.0f
176 {
177 const float fBlepOffset = v->fBlepPhasecxx . . $ voice_t#fBlepPhase. / v->fBlepDeltacxx . . $ voice_t#fBlepDelta.;
178 blepAddcxx . . $ blepAdd(878c0c6d9184ff8a).(b, fBlepOffset, b->fLastValuecxx . . $ blep_t#fLastValue. - v->fSamplecxx . . $ voice_t#fSample.);
179 }
180
181 b->fLastValuecxx . . $ blep_t#fLastValue. = v->fSamplecxx . . $ voice_t#fSample.;
182 }
183
184 // progress AUD_DAT buffer
185 v->AUD_DATcxx . . $ voice_t#AUD_DAT.[0] = v->AUD_DATcxx . . $ voice_t#AUD_DAT.[1];
186 v->sampleCountercxx . . $ voice_t#sampleCounter.--;
187 }
188
189 static void audxpercxx . . $ audxper(a7050f1a4cb56049).(int32_tcxx . . $ int32_t# ch, uint16_tcxx . . $ uint16_t# period)
190 {
191 paulaVoice_tcxx . . $ paulaVoice_t# *v = &paulacxx . . $ paula.[ch];
192
193 int32_tcxx . . $ int32_t# realPeriod = period;
194 if (realPeriod == 0)
195 realPeriod = 65536; // On Amiga: period 0 = period 65536 (1+65535)
196 else if (realPeriod < 113)
197 realPeriod = 113; // close to what happens on real Amiga (and low-limit needed for BLEP synthesis)
198
199 // to be read on next sampling step (or on DMA trigger)
200 v->fStoredDeltacxx . . $ voice_t#fStoredDelta. = fPeriodToDeltaDivcxx . . $ fPeriodToDeltaDiv. / (float)realPeriod;
201
202 // BLEP synthesis edge-case
203 if (v->fBlepDeltacxx . . $ voice_t#fBlepDelta. == 0.0f)
204 v->fBlepDeltacxx . . $ voice_t#fBlepDelta. = v->fDeltacxx . . $ voice_t#fDelta.;
205 }
206
207 static void audxvolcxx . . $ audxvol(a7050f1a4cb56049).(int32_tcxx . . $ int32_t# ch, uint16_tcxx . . $ uint16_t# vol)
208 {
209 int32_tcxx . . $ int32_t# realVol = vol & 127;
210 if (realVol > 64)
211 realVol = 64;
212
213 // multiplying sample point by this also scales the sample from -128..127 -> -1.000 .. ~0.992
214 paulacxx . . $ paula.[ch].fStoredVolcxx . . $ voice_t#fStoredVol. = realVol * (1.0f / (128.0f * 64.0f));
215 }
216
217 static void audxlencxx . . $ audxlen(a7050f1a4cb56049).(int32_tcxx . . $ int32_t# ch, uint16_tcxx . . $ uint16_t# len)
218 {
219 paulacxx . . $ paula.[ch].storedLengthcxx . . $ voice_t#storedLength. = len;
220 }
221
222 static void audxdatcxx . . $ audxdat(70eb3de2aab3469c).(int32_tcxx . . $ int32_t# ch, const int8_tcxx . . $ int8_t# *src)
223 {
224 if (src == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
225 src = nullSamplecxx . . $ nullSample.;
226
227 paulacxx . . $ paula.[ch].storedLocationcxx . . $ voice_t#storedLocation. = src;
228 }
229
230 static void startDMAcxx . . $ startDMA(d4f767463ce0a6b3).(int32_tcxx . . $ int32_t# ch)
231 {
232 paulaVoice_tcxx . . $ paulaVoice_t# *v = &paulacxx . . $ paula.[ch];
233
234 if (v->storedLocationcxx . . $ voice_t#storedLocation. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
235 v->storedLocationcxx . . $ voice_t#storedLocation. = nullSamplecxx . . $ nullSample.;
236
237 // immediately update these
238 v->locationcxx . . $ voice_t#location. = v->storedLocationcxx . . $ voice_t#storedLocation.;
239 v->lengthCountercxx . . $ voice_t#lengthCounter. = v->storedLengthcxx . . $ voice_t#storedLength.;
240
241 // make Paula fetch new samples immediately
242 v->sampleCountercxx . . $ voice_t#sampleCounter. = 0;
243 v->sampleJustStartedcxx . . $ voice_t#sampleJustStarted. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
244 refetchPeriodcxx . . $ refetchPeriod(361ab4fa815c10fc).(v);
245
246 // kludge: must be cleared *after* refetchPeriod()
247 v->fPhasecxx . . $ voice_t#fPhase. = 0.0f;
248
249 v->activecxx . . $ voice_t#active. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
250 }
251
252 static void stopDMAcxx . . $ stopDMA(d4f767463ce0a6b3).(int32_tcxx . . $ int32_t# ch)
253 {
254 paulacxx . . $ paula.[ch].activecxx . . $ voice_t#active. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
255 }
256
257 void paulaWriteBytecxx . . $ paulaWriteByte(cc289a6b3dfc48da).(uint32_tcxx . . $ uint32_t# address, uint8_tcxx . . $ uint8_t# data8)
258 {
259 if (address == 0)
260 return;
261
262 switch (address)
263 {
264 // CIA-A ("LED" filter control only)
265 case 0xBFE001:
266 {
267 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! oldLedFilterState = useLEDFiltercxx . . $ useLEDFilter.;
268
269 useLEDFiltercxx . . $ useLEDFilter. = !!(data8 & 2);
270 if (useLEDFiltercxx . . $ useLEDFilter. != oldLedFilterState)
271 clearTwoPoleFilterStatecxx . . $ clearTwoPoleFilterState(1647a0868bd893a0).(&filterLEDcxx . . $ filterLED.);
272 }
273 break;
274
275 default:
276 return;
277 }
278 }
279
280 void paulaWriteWordcxx . . $ paulaWriteWord(272d193675e92631).(uint32_tcxx . . $ uint32_t# address, uint16_tcxx . . $ uint16_t# data16)
281 {
282 if (address == 0)
283 return;
284
285 switch (address)
286 {
287 // DMACON
288 case 0xDFF096:
289 {
290 if (data16 & 0x8000)
291 {
292 // set
293 if (data16 & 1) startDMAcxx . . $ startDMA(d4f767463ce0a6b3).(0);
294 if (data16 & 2) startDMAcxx . . $ startDMA(d4f767463ce0a6b3).(1);
295 if (data16 & 4) startDMAcxx . . $ startDMA(d4f767463ce0a6b3).(2);
296 if (data16 & 8) startDMAcxx . . $ startDMA(d4f767463ce0a6b3).(3);
297 }
298 else
299 {
300 // clear
301 if (data16 & 1) stopDMAcxx . . $ stopDMA(d4f767463ce0a6b3).(0);
302 if (data16 & 2) stopDMAcxx . . $ stopDMA(d4f767463ce0a6b3).(1);
303 if (data16 & 4) stopDMAcxx . . $ stopDMA(d4f767463ce0a6b3).(2);
304 if (data16 & 8) stopDMAcxx . . $ stopDMA(d4f767463ce0a6b3).(3);
305 }
306 }
307 break;
308
309 // AUDxLEN
310 case 0xDFF0A4: audxlencxx . . $ audxlen(a7050f1a4cb56049).(0, data16); break;
311 case 0xDFF0B4: audxlencxx . . $ audxlen(a7050f1a4cb56049).(1, data16); break;
312 case 0xDFF0C4: audxlencxx . . $ audxlen(a7050f1a4cb56049).(2, data16); break;
313 case 0xDFF0D4: audxlencxx . . $ audxlen(a7050f1a4cb56049).(3, data16); break;
314
315 // AUDxPER
316 case 0xDFF0A6: audxpercxx . . $ audxper(a7050f1a4cb56049).(0, data16); break;
317 case 0xDFF0B6: audxpercxx . . $ audxper(a7050f1a4cb56049).(1, data16); break;
318 case 0xDFF0C6: audxpercxx . . $ audxper(a7050f1a4cb56049).(2, data16); break;
319 case 0xDFF0D6: audxpercxx . . $ audxper(a7050f1a4cb56049).(3, data16); break;
320
321 // AUDxVOL
322 case 0xDFF0A8: audxvolcxx . . $ audxvol(a7050f1a4cb56049).(0, data16); break;
323 case 0xDFF0B8: audxvolcxx . . $ audxvol(a7050f1a4cb56049).(1, data16); break;
324 case 0xDFF0C8: audxvolcxx . . $ audxvol(a7050f1a4cb56049).(2, data16); break;
325 case 0xDFF0D8: audxvolcxx . . $ audxvol(a7050f1a4cb56049).(3, data16); break;
326
327 default:
328 return;
329 }
330 }
331
332 void paulaWritePtrcxx . . $ paulaWritePtr(8ed931be62ea155e).(uint32_tcxx . . $ uint32_t# address, const int8_tcxx . . $ int8_t# *ptr)
333 {
334 if (address == 0)
335 return;
336
337 switch (address)
338 {
339 // AUDxDAT
340 case 0xDFF0A0: audxdatcxx . . $ audxdat(70eb3de2aab3469c).(0, ptr); break;
341 case 0xDFF0B0: audxdatcxx . . $ audxdat(70eb3de2aab3469c).(1, ptr); break;
342 case 0xDFF0C0: audxdatcxx . . $ audxdat(70eb3de2aab3469c).(2, ptr); break;
343 case 0xDFF0D0: audxdatcxx . . $ audxdat(70eb3de2aab3469c).(3, ptr); break;
344
345 default:
346 return;
347 }
348 }
349
350 void clearBlepStatecxx . . $ clearBlepState(49f6e7a06ebc5aa8).(void)
351 {
352 memsetcxx . . $ memset(d1de1e4fb215f1c6).(blepcxx . . $ blep., 0, sizeof (blepcxx . . $ blep.));
353 }
354
355 // output is -4.00 .. 3.97 (can be louder because of high-pass filter)
356 void paulaGenerateSamplescxx . . $ paulaGenerateSamples(ae8270d942ffb491).(float *fOutL, float *fOutR, int32_tcxx . . $ int32_t# numSamples)
357 {
358 if (numSamples <= 0)
359 return;
360
361 float *fMixBufSelect[PAULA_VOICEScxx . . $ `src/pt2_paula.h:13:9`!] = { fOutL, fOutR, fOutR, fOutL };
362
363 // clear mix buffer block
364 memsetcxx . . $ memset(d1de1e4fb215f1c6).(fOutL, 0, numSamples * sizeof (float));
365 memsetcxx . . $ memset(d1de1e4fb215f1c6).(fOutR, 0, numSamples * sizeof (float));
366
367 // mix samples
368
369 paulaVoice_tcxx . . $ paulaVoice_t# *v = paulacxx . . $ paula.;
370 blep_tcxx . . $ blep_t# *b = blepcxx . . $ blep.;
371
372 for (int32_tcxx . . $ int32_t# i = 0; i < PAULA_VOICEScxx . . $ `src/pt2_paula.h:13:9`!; i++, v++, b++)
373 {
374 if (!v->activecxx . . $ voice_t#active. || v->locationcxx . . $ voice_t#location. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || v->storedLocationcxx . . $ voice_t#storedLocation. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
375 continue;
376
377 float *fMixBuffer = fMixBufSelect[i]; // what output channel to mix into (L, R, R, L)
378 for (int32_tcxx . . $ int32_t# j = 0; j < numSamples; j++)
379 {
380 if (v->nextSampleStagecxx . . $ voice_t#nextSampleStage.)
381 {
382 v->nextSampleStagecxx . . $ voice_t#nextSampleStage. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
383 nextSamplecxx . . $ nextSample(293f0b9155a56260).(v, b);
384 }
385
386 float fSample = v->fSamplecxx . . $ voice_t#fSample.; // current sample, pre-multiplied by vol, scaled to -1.0 .. 0.992
387 if (b->samplesLeftcxx . . $ blep_t#samplesLeft. > 0)
388 fSample = blepRuncxx . . $ blepRun(6ddfbab99006406a).(b, fSample);
389
390 fMixBuffer[j] += fSample;
391
392 v->fPhasecxx . . $ voice_t#fPhase. += v->fDeltacxx . . $ voice_t#fDelta.;
393 if (v->fPhasecxx . . $ voice_t#fPhase. >= 1.0f)
394 {
395 v->fPhasecxx . . $ voice_t#fPhase. -= 1.0f;
396 refetchPeriodcxx . . $ refetchPeriod(361ab4fa815c10fc).(v);
397 }
398 }
399 }
400
401 // apply Amiga filters
402 for (int32_tcxx . . $ int32_t# i = 0; i < numSamples; i++)
403 {
404 float fOut[2];
405
406 fOut[0] = fOutL[i];
407 fOut[1] = fOutR[i];
408
409 if (useLowpassFiltercxx . . $ useLowpassFilter.)
410 onePoleLPFilterStereocxx . . $ onePoleLPFilterStereo(90467eb7f67c8a3c).(&filterLocxx . . $ filterLo., fOut, fOut);
411
412 if (useLEDFiltercxx . . $ useLEDFilter.)
413 twoPoleLPFilterStereocxx . . $ twoPoleLPFilterStereo(77050a5006a1adb7).(&filterLEDcxx . . $ filterLED., fOut, fOut);
414
415 if (useHighpassFiltercxx . . $ useHighpassFilter.)
416 onePoleHPFilterStereocxx . . $ onePoleHPFilterStereo(90467eb7f67c8a3c).(&filterHicxx . . $ filterHi., fOut, fOut);
417
418 fOutL[i] = fOut[0];
419 fOutR[i] = fOut[1];
420 }
421 }