Debian Codegraph @

src/pt2_audio.c

raw symbols SCIP
1 // for finding memory leaks in debug mode with Visual Studio cxx . . $ `<file>/src/pt2_audio.c`/
2 #if defined _DEBUG && defined _MSC_VER
3 #include <crtdbg.h>
4 #endif
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <string.h>
11 #include <math.h>
12 #include <SDL2/SDL.h>
13 #ifdef _WIN32
14 #include <io.h>
15 #else
16 #include <unistd.h>
17 #endif
18 #include <fcntl.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <limits.h>
22 #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/
23 #include "pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/
24 #include "pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/
25 #include "pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/
26 #include "pt2_scopes.h"cxx . . $ `<file>/src/pt2_scopes.h`/
27 #include "pt2_visuals_sync.h"cxx . . $ `<file>/src/pt2_visuals_sync.h`/
28 #include "pt2_downsample2x.h"cxx . . $ `<file>/src/pt2_downsample2x.h`/
29 #include "pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/
30 #include "pt2_paula.h"cxx . . $ `<file>/src/pt2_paula.h`/
31
32 // cumulative mid/side normalization factor (1/sqrt(2))*(1/sqrt(2))
33 #define STEREO_NORM_FACTORcxx . . $ `src/pt2_audio.c:33:9`! 0.5f
34
35 #define INITIAL_DITHER_SEEDcxx . . $ `src/pt2_audio.c:35:9`! 0x12345000
36
37 static uint8_tcxx . . $ uint8_t# panningModecxx . . $ panningMode.;
38 static int32_tcxx . . $ int32_t# stereoSeparationcxx . . $ stereoSeparation. = 100;
39 static uint32_tcxx . . $ uint32_t# randSeedcxx . . $ randSeed. = INITIAL_DITHER_SEEDcxx . . $ `src/pt2_audio.c:35:9`!;
40 static float *fMixBufferLcxx . . $ fMixBufferL., *fMixBufferRcxx . . $ fMixBufferR., fSideFactorcxx . . $ fSideFactor., fPrngStateLcxx . . $ fPrngStateL., fPrngStateRcxx . . $ fPrngStateR.;
41 static SDL_AudioDeviceIDcxx . . $ SDL_AudioDeviceID# devcxx . . $ dev.;
42
43 audio_tcxx . . $ audio_t# audiocxx . . $ audio.; // globalized
44
45 void setAmigaFilterModelcxx . . $ setAmigaFilterModel(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# model)
46 {
47 if (audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel. == model)
48 return; // same state as before!
49
50 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
51 if (audioWasntLocked)
52 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
53
54 audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel. = model;
55
56 const int32_tcxx . . $ int32_t# paulaMixFrequency = audiocxx . . $ audio..oversamplingFlagcxx . . $ audio_t#oversamplingFlag. ? audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.*2 : audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.;
57 paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(paulaMixFrequency, audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel.);
58
59 if (audioWasntLocked)
60 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
61 }
62
63 void toggleAmigaFilterModelcxx . . $ toggleAmigaFilterModel(49f6e7a06ebc5aa8).(void)
64 {
65 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
66 if (audioWasntLocked)
67 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
68
69 audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel. ^= 1;
70
71 const int32_tcxx . . $ int32_t# paulaMixFrequency = audiocxx . . $ audio..oversamplingFlagcxx . . $ audio_t#oversamplingFlag. ? audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.*2 : audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.;
72 paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(paulaMixFrequency, audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel.);
73
74 if (audioWasntLocked)
75 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
76
77 if (audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel. == MODEL_A500cxx . . $ MODEL_A500.)
78 displayMsgcxx . . $ displayMsg(85c52e162fed56f9).("AUDIO: AMIGA 500");
79 else
80 displayMsgcxx . . $ displayMsg(85c52e162fed56f9).("AUDIO: AMIGA 1200");
81 }
82
83 void setLEDFiltercxx . . $ setLEDFilter(b45ddcbc8423892c).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! state)
84 {
85 if (audiocxx . . $ audio..ledFilterEnabledcxx . . $ audio_t#ledFilterEnabled. == state)
86 return; // same state as before!
87
88 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
89 if (audioWasntLocked)
90 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
91
92 audiocxx . . $ audio..ledFilterEnabledcxx . . $ audio_t#ledFilterEnabled. = state;
93 paulaWriteBytecxx . . $ paulaWriteByte(cc289a6b3dfc48da).(0xBFE001, (uint8_tcxx . . $ uint8_t#)audiocxx . . $ audio..ledFilterEnabledcxx . . $ audio_t#ledFilterEnabled. << 1);
94
95 if (audioWasntLocked)
96 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
97 }
98
99 void toggleLEDFiltercxx . . $ toggleLEDFilter(49f6e7a06ebc5aa8).(void)
100 {
101 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
102 if (audioWasntLocked)
103 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
104
105 audiocxx . . $ audio..ledFilterEnabledcxx . . $ audio_t#ledFilterEnabled. ^= 1;
106 paulaWriteBytecxx . . $ paulaWriteByte(cc289a6b3dfc48da).(0xBFE001, (uint8_tcxx . . $ uint8_t#)audiocxx . . $ audio..ledFilterEnabledcxx . . $ audio_t#ledFilterEnabled. << 1);
107
108 if (audioWasntLocked)
109 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
110 }
111
112 void lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).(void)
113 {
114 if (devcxx . . $ dev. != 0)
115 SDL_LockAudioDevicecxx . . $ SDL_LockAudioDevice(cb2f890c2fdad230).(devcxx . . $ dev.);
116
117 audiocxx . . $ audio..lockedcxx . . $ audio_t#locked. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
118
119 audiocxx . . $ audio..resetSyncTickTimeFlagcxx . . $ audio_t#resetSyncTickTimeFlag. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
120 resetChSyncQueuecxx . . $ resetChSyncQueue(49f6e7a06ebc5aa8).();
121 }
122
123 void unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).(void)
124 {
125 if (devcxx . . $ dev. != 0)
126 SDL_UnlockAudioDevicecxx . . $ SDL_UnlockAudioDevice(cb2f890c2fdad230).(devcxx . . $ dev.);
127
128 audiocxx . . $ audio..resetSyncTickTimeFlagcxx . . $ audio_t#resetSyncTickTimeFlag. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
129 resetChSyncQueuecxx . . $ resetChSyncQueue(49f6e7a06ebc5aa8).();
130
131 audiocxx . . $ audio..lockedcxx . . $ audio_t#locked. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
132 }
133
134 void resetAudioDithercxx . . $ resetAudioDither(49f6e7a06ebc5aa8).(void)
135 {
136 randSeedcxx . . $ randSeed. = INITIAL_DITHER_SEEDcxx . . $ `src/pt2_audio.c:35:9`!;
137 fPrngStateLcxx . . $ fPrngStateL. = fPrngStateRcxx . . $ fPrngStateR. = 0.0f;
138 }
139
140 static inline int32_tcxx . . $ int32_t# random32cxx . . $ random32(b126dc7c1de90089).(void)
141 {
142 // LCG 32-bit random
143 randSeedcxx . . $ randSeed. *= 134775813;
144 randSeedcxx . . $ randSeed.++;
145
146 return (int32_tcxx . . $ int32_t#)randSeedcxx . . $ randSeed.;
147 }
148
149 /* So yeah, the audio may be a little quiet in some cases, but
150 ** the output can already clip quite a bit in extreme cases due
151 ** to the ~5Hz high-pass filter, so think twice before changing
152 ** this...
153 */
154 #define AUDIO_GAINcxx . . $ `src/pt2_audio.c:154:9`! 2.0
155
156 #define NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`! (float)(AUDIO_GAINcxx . . $ `src/pt2_audio.c:154:9`! * ((INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!+1.0) / PAULA_VOICEScxx . . $ `src/pt2_paula.h:13:9`!))
157
158 static inline void processMixedSamplesAmigaPanningcxx . . $ processMixedSamplesAmigaPanning(4c4d8747bb7d9d45).(int32_tcxx . . $ int32_t# i, int16_tcxx . . $ int16_t# *out)
159 {
160 int32_tcxx . . $ int32_t# out32;
161 float fOut, fPrng;
162
163 float fL = fMixBufferLcxx . . $ fMixBufferL.[i];
164 float fR = fMixBufferRcxx . . $ fMixBufferR.[i];
165
166 fL *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
167 fR *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
168
169 // left channel - 1-bit triangular dithering
170 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
171 fOut = (fL + fPrng) - fPrngStateLcxx . . $ fPrngStateL.;
172 fPrngStateLcxx . . $ fPrngStateL. = fPrng;
173 out32 = (int32_tcxx . . $ int32_t#)fOut;
174 out[0] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
175
176 // right channel - 1-bit triangular dithering
177 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
178 fOut = (fR + fPrng) - fPrngStateRcxx . . $ fPrngStateR.;
179 fPrngStateRcxx . . $ fPrngStateR. = fPrng;
180 out32 = (int32_tcxx . . $ int32_t#)fOut;
181 out[1] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
182 }
183
184 static inline void processMixedSamplescxx . . $ processMixedSamples(4c4d8747bb7d9d45).(int32_tcxx . . $ int32_t# i, int16_tcxx . . $ int16_t# *out)
185 {
186 int32_tcxx . . $ int32_t# out32;
187 float fOut, fPrng;
188
189 float fL = fMixBufferLcxx . . $ fMixBufferL.[i];
190 float fR = fMixBufferRcxx . . $ fMixBufferR.[i];
191
192 // apply stereo separation
193 const float fOldL = fL;
194 const float fOldR = fR;
195 float fMid = (fOldL + fOldR) * STEREO_NORM_FACTORcxx . . $ `src/pt2_audio.c:33:9`!;
196 float fSide = (fOldL - fOldR) * fSideFactorcxx . . $ fSideFactor.;
197 fL = fMid + fSide;
198 fR = fMid - fSide;
199
200 fL *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
201 fR *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
202
203 // left channel - 1-bit triangular dithering
204 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
205 fOut = (fL + fPrng) - fPrngStateLcxx . . $ fPrngStateL.;
206 fPrngStateLcxx . . $ fPrngStateL. = fPrng;
207 out32 = (int32_tcxx . . $ int32_t#)fOut;
208 out[0] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
209
210 // right channel - 1-bit triangular dithering
211 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
212 fOut = (fR + fPrng) - fPrngStateRcxx . . $ fPrngStateR.;
213 fPrngStateRcxx . . $ fPrngStateR. = fPrng;
214 out32 = (int32_tcxx . . $ int32_t#)fOut;
215 out[1] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
216 }
217
218 static inline void processMixedSamplesAmigaPanning_2xcxx . . $ processMixedSamplesAmigaPanning_2x(4c4d8747bb7d9d45).(int32_tcxx . . $ int32_t# i, int16_tcxx . . $ int16_t# *out) // 2x oversampling
219 {
220 int32_tcxx . . $ int32_t# out32;
221 float fL, fR, fOut, fPrng;
222
223 // 2x downsampling
224 const uint32_tcxx . . $ uint32_t# offset1 = (i << 1) + 0;
225 const uint32_tcxx . . $ uint32_t# offset2 = (i << 1) + 1;
226 fL = downsample2x_Lcxx . . $ downsample2x_L(d59a45cd3bfd2eda).(fMixBufferLcxx . . $ fMixBufferL.[offset1], fMixBufferLcxx . . $ fMixBufferL.[offset2]);
227 fR = downsample2x_Rcxx . . $ downsample2x_R(d59a45cd3bfd2eda).(fMixBufferRcxx . . $ fMixBufferR.[offset1], fMixBufferRcxx . . $ fMixBufferR.[offset2]);
228
229 fL *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
230 fR *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
231
232 // left channel - 1-bit triangular dithering
233 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
234 fOut = (fL + fPrng) - fPrngStateLcxx . . $ fPrngStateL.;
235 fPrngStateLcxx . . $ fPrngStateL. = fPrng;
236 out32 = (int32_tcxx . . $ int32_t#)fOut;
237 out[0] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
238
239 // right channel - 1-bit triangular dithering
240 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
241 fOut = (fR + fPrng) - fPrngStateRcxx . . $ fPrngStateR.;
242 fPrngStateRcxx . . $ fPrngStateR. = fPrng;
243 out32 = (int32_tcxx . . $ int32_t#)fOut;
244 out[1] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
245 }
246
247 static inline void processMixedSamples_2xcxx . . $ processMixedSamples_2x(4c4d8747bb7d9d45).(int32_tcxx . . $ int32_t# i, int16_tcxx . . $ int16_t# *out) // 2x oversampling
248 {
249 int32_tcxx . . $ int32_t# out32;
250 float fL, fR, fOut, fPrng;
251
252 // 2x downsampling
253 const uint32_tcxx . . $ uint32_t# offset1 = (i << 1) + 0;
254 const uint32_tcxx . . $ uint32_t# offset2 = (i << 1) + 1;
255 fL = downsample2x_Lcxx . . $ downsample2x_L(d59a45cd3bfd2eda).(fMixBufferLcxx . . $ fMixBufferL.[offset1], fMixBufferLcxx . . $ fMixBufferL.[offset2]);
256 fR = downsample2x_Rcxx . . $ downsample2x_R(d59a45cd3bfd2eda).(fMixBufferRcxx . . $ fMixBufferR.[offset1], fMixBufferRcxx . . $ fMixBufferR.[offset2]);
257
258 // apply stereo separation
259 const float fOldL = fL;
260 const float fOldR = fR;
261 float fMid = (fOldL + fOldR) * STEREO_NORM_FACTORcxx . . $ `src/pt2_audio.c:33:9`!;
262 float fSide = (fOldL - fOldR) * fSideFactorcxx . . $ fSideFactor.;
263 fL = fMid + fSide;
264 fR = fMid - fSide;
265
266 fL *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
267 fR *= NORMALIZE_VALUEcxx . . $ `src/pt2_audio.c:156:9`!;
268
269 // left channel - 1-bit triangular dithering
270 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
271 fOut = (fL + fPrng) - fPrngStateLcxx . . $ fPrngStateL.;
272 fPrngStateLcxx . . $ fPrngStateL. = fPrng;
273 out32 = (int32_tcxx . . $ int32_t#)fOut;
274 out[0] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
275
276 // right channel - 1-bit triangular dithering
277 fPrng = (float)random32cxx . . $ random32(b126dc7c1de90089).() * (1.0f / ((float)UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:118:10`!+1.0f)); // -0.5f .. 0.5f
278 fOut = (fR + fPrng) - fPrngStateRcxx . . $ fPrngStateR.;
279 fPrngStateRcxx . . $ fPrngStateR. = fPrng;
280 out32 = (int32_tcxx . . $ int32_t#)fOut;
281 out[1] = (int16_tcxx . . $ int16_t#)(CLAMPcxx . . $ `src/pt2_helpers.h:36:9`!(out32, INT16_MINcxx . . $ `<external>/3415975807581488833/stdint.h:106:10`!, INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!));
282 }
283
284 void outputAudiocxx . . $ outputAudio(4683f455c3e046d4).(int16_tcxx . . $ int16_t# *target, int32_tcxx . . $ int32_t# numSamples)
285 {
286 if (audiocxx . . $ audio..oversamplingFlagcxx . . $ audio_t#oversamplingFlag.) // 2x oversampling
287 {
288 paulaGenerateSamplescxx . . $ paulaGenerateSamples(ae8270d942ffb491).(fMixBufferLcxx . . $ fMixBufferL., fMixBufferRcxx . . $ fMixBufferR., numSamples*2);
289
290 // downsample and normalize
291 int16_tcxx . . $ int16_t# out[2];
292 int16_tcxx . . $ int16_t# *outStream = target;
293 if (stereoSeparationcxx . . $ stereoSeparation. == 100)
294 {
295 for (int32_tcxx . . $ int32_t# i = 0; i < numSamples; i++)
296 {
297 processMixedSamplesAmigaPanning_2xcxx . . $ processMixedSamplesAmigaPanning_2x(4c4d8747bb7d9d45).(i, out);
298 *outStream++ = out[0];
299 *outStream++ = out[1];
300 }
301 }
302 else
303 {
304 for (int32_tcxx . . $ int32_t# i = 0; i < numSamples; i++)
305 {
306 processMixedSamples_2xcxx . . $ processMixedSamples_2x(4c4d8747bb7d9d45).(i, out);
307 *outStream++ = out[0];
308 *outStream++ = out[1];
309 }
310 }
311 }
312 else
313 {
314 paulaGenerateSamplescxx . . $ paulaGenerateSamples(ae8270d942ffb491).(fMixBufferLcxx . . $ fMixBufferL., fMixBufferRcxx . . $ fMixBufferR., numSamples);
315
316 // normalize
317 int16_tcxx . . $ int16_t# out[2];
318 int16_tcxx . . $ int16_t# *outStream = target;
319 if (stereoSeparationcxx . . $ stereoSeparation. == 100)
320 {
321 for (int32_tcxx . . $ int32_t# i = 0; i < numSamples; i++)
322 {
323 processMixedSamplesAmigaPanningcxx . . $ processMixedSamplesAmigaPanning(4c4d8747bb7d9d45).(i, out);
324 *outStream++ = out[0];
325 *outStream++ = out[1];
326 }
327 }
328 else
329 {
330 for (int32_tcxx . . $ int32_t# i = 0; i < numSamples; i++)
331 {
332 processMixedSamplescxx . . $ processMixedSamples(4c4d8747bb7d9d45).(i, out);
333 *outStream++ = out[0];
334 *outStream++ = out[1];
335 }
336 }
337 }
338 }
339
340 static void audioCallbackcxx . . $ audioCallback(c52f2c8079c5ae6).(void *userdata, Uint8cxx . . $ Uint8# *stream, int len)
341 {
342 if (editorcxx . . $ editor..mod2WavOngoingcxx . . $ editor_t#mod2WavOngoing. || editorcxx . . $ editor..pat2SmpOngoingcxx . . $ editor_t#pat2SmpOngoing.) // send silence to sound output device
343 {
344 memsetcxx . . $ memset(d1de1e4fb215f1c6).(stream, 0, len);
345 return;
346 }
347
348 audiocxx . . $ audio..callbackOngoingcxx . . $ audio_t#callbackOngoing. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
349
350 int16_tcxx . . $ int16_t# *streamOut = (int16_tcxx . . $ int16_t# *)stream;
351
352 uint32_tcxx . . $ uint32_t# samplesLeft = (uint32_tcxx . . $ uint32_t#)len / 4;
353 while (samplesLeft > 0)
354 {
355 if (audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. <= 0) // new replayer tick
356 {
357 if (editorcxx . . $ editor..songPlayingcxx . . $ editor_t#songPlaying.)
358 {
359 tickReplayercxx . . $ tickReplayer(c9857a73d68e59ba).(); // (sets audio.samplesPerTickInt and audio.samplesPerTickFrac)
360
361 if (audiocxx . . $ audio..samplesPerTickIntcxx . . $ audio_t#samplesPerTickInt. != 0)
362 fillVisualsSyncBuffercxx . . $ fillVisualsSyncBuffer(49f6e7a06ebc5aa8).();
363 }
364
365 audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. = audiocxx . . $ audio..samplesPerTickIntcxx . . $ audio_t#samplesPerTickInt.;
366
367 audiocxx . . $ audio..tickSampleCounterFraccxx . . $ audio_t#tickSampleCounterFrac. += audiocxx . . $ audio..samplesPerTickFraccxx . . $ audio_t#samplesPerTickFrac.;
368 if (audiocxx . . $ audio..tickSampleCounterFraccxx . . $ audio_t#tickSampleCounterFrac. >= BPM_FRAC_SCALEcxx . . $ `src/pt2_audio.h:13:9`!)
369 {
370 audiocxx . . $ audio..tickSampleCounterFraccxx . . $ audio_t#tickSampleCounterFrac. &= BPM_FRAC_MASKcxx . . $ `src/pt2_audio.h:14:9`!;
371 audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter.++;
372 }
373 }
374
375 int32_tcxx . . $ int32_t# samplesToMix = samplesLeft;
376 if (audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. > 0 && samplesToMix > audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter.)
377 samplesToMix = audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter.;
378
379 outputAudiocxx . . $ outputAudio(4683f455c3e046d4).(streamOut, samplesToMix);
380 streamOut += samplesToMix * 2; // *2 for stereo
381
382 audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. -= samplesToMix;
383 samplesLeft -= samplesToMix;
384 }
385
386 audiocxx . . $ audio..callbackOngoingcxx . . $ audio_t#callbackOngoing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
387
388 (void)userdata;
389 }
390
391 void audioSetStereoSeparationcxx . . $ audioSetStereoSeparation(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# percentage) // 0..100 (percentage)
392 {
393 ASSERTcxx . . $ `src/pt2_header.h:25:9`!(percentage <= 100);
394
395 stereoSeparationcxx . . $ stereoSeparation. = percentage;
396 fSideFactorcxx . . $ fSideFactor. = (percentage / 100.0f) * STEREO_NORM_FACTORcxx . . $ `src/pt2_audio.c:33:9`!;
397 }
398
399 void generateBpmTablecxx . . $ generateBpmTable(e7c9417f9c54f86f).(double dAudioFreq, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! vblankTimingFlag)
400 {
401 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
402 if (audioWasntLocked)
403 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
404
405 for (int32_tcxx . . $ int32_t# bpm = MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!; bpm <= MAX_BPMcxx . . $ `src/pt2_replayer.h:8:9`!; bpm++)
406 {
407 const double dHz = vblankTimingFlag ? AMIGA_PAL_VBLANK_HZcxx . . $ `src/pt2_header.h:53:9`! : ciaBpm2Hzcxx . . $ ciaBpm2Hz(4badf5dbac1308a7).(bpm);
408
409 const double dSamplesPerTick = dAudioFreq / dHz;
410 double dSamplesPerTickInt, dSamplesPerTickFrac = modf(dSamplesPerTick, &dSamplesPerTickInt);
411
412 const int32_tcxx . . $ int32_t# i = bpm - MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!;
413 audiocxx . . $ audio..samplesPerTickIntTabcxx . . $ audio_t#samplesPerTickIntTab.[i] = (uint32_tcxx . . $ uint32_t#)dSamplesPerTickInt;
414 audiocxx . . $ audio..samplesPerTickFracTabcxx . . $ audio_t#samplesPerTickFracTab.[i] = (uint64_tcxx . . $ uint64_t#)(dSamplesPerTickFrac * BPM_FRAC_SCALEcxx . . $ `src/pt2_audio.h:13:9`!);
415 }
416
417 audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. = 0;
418 audiocxx . . $ audio..tickSampleCounterFraccxx . . $ audio_t#tickSampleCounterFrac. = 0;
419
420 if (audioWasntLocked)
421 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
422 }
423
424 static void generateTickLengthTablecxx . . $ generateTickLengthTable(b45ddcbc8423892c).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! vblankTimingFlag) // for performance counter (syncing visuals to audio)
425 {
426 for (int32_tcxx . . $ int32_t# bpm = MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!; bpm <= MAX_BPMcxx . . $ `src/pt2_replayer.h:8:9`!; bpm++)
427 {
428 double dHz = vblankTimingFlag ? AMIGA_PAL_VBLANK_HZcxx . . $ `src/pt2_header.h:53:9`! : ciaBpm2Hzcxx . . $ ciaBpm2Hz(4badf5dbac1308a7).(bpm);
429
430 const double dTickTime = (double)hpcFreqcxx . . $ hpcFreq..freq64cxx . . $ $anonymous_type_f41cb469dd1dca50_0#freq64. / dHz;
431 double dTickTimeInt, dTickTimeFrac = modf(dTickTime, &dTickTimeInt);
432
433 const int32_tcxx . . $ int32_t# i = bpm - MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!;
434 audiocxx . . $ audio..tickTimeIntTabcxx . . $ audio_t#tickTimeIntTab.[i] = (uint32_tcxx . . $ uint32_t#)dTickTimeInt;
435 audiocxx . . $ audio..tickTimeFracTabcxx . . $ audio_t#tickTimeFracTab.[i] = (uint64_tcxx . . $ uint64_t#)(dTickTimeFrac * TICK_TIME_FRAC_SCALEcxx . . $ `src/pt2_audio.h:17:9`!);
436 }
437 }
438
439 void updateReplayerTimingModecxx . . $ updateReplayerTimingMode(49f6e7a06ebc5aa8).(void)
440 {
441 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
442 if (audioWasntLocked)
443 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
444
445 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! vblankTimingMode = (editorcxx . . $ editor..timingModecxx . . $ editor_t#timingMode. == TEMPO_MODE_VBLANKcxx . . $ TEMPO_MODE_VBLANK.);
446 generateBpmTablecxx . . $ generateBpmTable(e7c9417f9c54f86f).(audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate., vblankTimingMode);
447 generateTickLengthTablecxx . . $ generateTickLengthTable(b45ddcbc8423892c).(vblankTimingMode);
448
449 if (audioWasntLocked)
450 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
451 }
452
453 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! setupAudiocxx . . $ setupAudio(c9857a73d68e59ba).(void)
454 {
455 SDL_AudioSpeccxx . . $ SDL_AudioSpec# want, have;
456
457 audiocxx . . $ audio..callbackOngoingcxx . . $ audio_t#callbackOngoing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
458
459 want.freqcxx . . $ SDL_AudioSpec#freq. = configcxx . . $ config..soundFrequencycxx . . $ config_t#soundFrequency.;
460 want.samplescxx . . $ SDL_AudioSpec#samples. = (uint16_tcxx . . $ uint16_t#)configcxx . . $ config..soundBufferSizecxx . . $ config_t#soundBufferSize.;
461 want.formatcxx . . $ SDL_AudioSpec#format. = AUDIO_S16cxx . . $ `<external>/178947386371380387/SDL_audio.h:98:9`!;
462 want.channelscxx . . $ SDL_AudioSpec#channels. = 2;
463 want.callbackcxx . . $ SDL_AudioSpec#callback. = audioCallbackcxx . . $ audioCallback(c52f2c8079c5ae6).;
464 want.userdatacxx . . $ SDL_AudioSpec#userdata. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
465
466 devcxx . . $ dev. = SDL_OpenAudioDevicecxx . . $ SDL_OpenAudioDevice(8944c6df11d5148c).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, &want, &have, SDL_AUDIO_ALLOW_FREQUENCY_CHANGEcxx . . $ `<external>/178947386371380387/SDL_audio.h:142:9`!);
467 if (devcxx . . $ dev. == 0)
468 {
469 showErrorMsgBoxcxx . . $ showErrorMsgBox(326aeb464d16410c).("Couldn't open audio device:\n\"%s\"\n\nDo you have an audio device enabled and plugged in?", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
470 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
471 }
472
473 // lower than this is not safe for the BLEP synthesis in the mixer
474 const int32_tcxx . . $ int32_t# minFreq = (int32_tcxx . . $ int32_t#)(PAULA_PAL_CLKcxx . . $ `src/pt2_paula.h:14:9`! / 113.0 / 2.0)+1; // /2 because we do 2x oversampling
475 if (have.freqcxx . . $ SDL_AudioSpec#freq. < minFreq)
476 {
477 showErrorMsgBoxcxx . . $ showErrorMsgBox(326aeb464d16410c).("Unable to open audio: An audio rate below %dHz can't be used!", minFreq);
478 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
479 }
480
481 audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate. = have.freqcxx . . $ SDL_AudioSpec#freq.;
482 audiocxx . . $ audio..audioBufferSizecxx . . $ audio_t#audioBufferSize. = have.samplescxx . . $ SDL_AudioSpec#samples.;
483 audiocxx . . $ audio..oversamplingFlagcxx . . $ audio_t#oversamplingFlag. = (audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate. < 96000); // we do 2x oversampling if the audio output rate is below 96kHz
484 audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel. = configcxx . . $ config..amigaModelcxx . . $ config_t#amigaModel.;
485
486 uint32_tcxx . . $ uint32_t# maxFrequency = audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.;
487 if (maxFrequency < configcxx . . $ config..mod2WavOutputFreqcxx . . $ config_t#mod2WavOutputFreq.)
488 maxFrequency = configcxx . . $ config..mod2WavOutputFreqcxx . . $ config_t#mod2WavOutputFreq.;
489
490 maxFrequency *= 2; // oversampling
491
492 const int32_tcxx . . $ int32_t# paulaMixFrequency = audiocxx . . $ audio..oversamplingFlagcxx . . $ audio_t#oversamplingFlag. ? audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.*2 : audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.;
493 int32_tcxx . . $ int32_t# maxSamplesPerTick = (int32_tcxx . . $ int32_t#)ceil(maxFrequency / (MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`! / 2.5)) + 1;
494
495 fMixBufferLcxx . . $ fMixBufferL. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(maxSamplesPerTick * sizeof (float));
496 fMixBufferRcxx . . $ fMixBufferR. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(maxSamplesPerTick * sizeof (float));
497
498 if (fMixBufferLcxx . . $ fMixBufferL. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || fMixBufferRcxx . . $ fMixBufferR. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
499 {
500 // these two are free'd later
501 showErrorMsgBoxcxx . . $ showErrorMsgBox(326aeb464d16410c).("Out of memory!");
502 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
503 }
504
505 paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(paulaMixFrequency, audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel.);
506 audioSetStereoSeparationcxx . . $ audioSetStereoSeparation(ac50b47256ae7414).(configcxx . . $ config..stereoSeparationcxx . . $ config_t#stereoSeparation.);
507 updateReplayerTimingModecxx . . $ updateReplayerTimingMode(49f6e7a06ebc5aa8).(); // also generates the BPM table (audio.samplesPerTickIntTab & audio.samplesPerTickFracTab)
508 setLEDFiltercxx . . $ setLEDFilter(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
509 calcAudioLatencyVarscxx . . $ calcAudioLatencyVars(3e454b8ccf442868).(audiocxx . . $ audio..audioBufferSizecxx . . $ audio_t#audioBufferSize., audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate.);
510
511 clearDownsample2xStatescxx . . $ clearDownsample2xStates(49f6e7a06ebc5aa8).();
512 audiocxx . . $ audio..resetSyncTickTimeFlagcxx . . $ audio_t#resetSyncTickTimeFlag. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
513
514 audiocxx . . $ audio..samplesPerTickIntcxx . . $ audio_t#samplesPerTickInt. = audiocxx . . $ audio..samplesPerTickIntTabcxx . . $ audio_t#samplesPerTickIntTab.[125-MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!]; // BPM 125
515 audiocxx . . $ audio..samplesPerTickFraccxx . . $ audio_t#samplesPerTickFrac. = audiocxx . . $ audio..samplesPerTickFracTabcxx . . $ audio_t#samplesPerTickFracTab.[125-MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`!]; // BPM 125
516
517 audiocxx . . $ audio..tickSampleCountercxx . . $ audio_t#tickSampleCounter. = 0; // zero tick sample counter so that it will instantly initiate a tick
518 audiocxx . . $ audio..tickSampleCounterFraccxx . . $ audio_t#tickSampleCounterFrac. = 0;
519
520 SDL_PauseAudioDevicecxx . . $ SDL_PauseAudioDevice(3d89109e85ced1be).(devcxx . . $ dev., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
521 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
522 }
523
524 void audioClosecxx . . $ audioClose(49f6e7a06ebc5aa8).(void)
525 {
526 if (devcxx . . $ dev. > 0)
527 {
528 SDL_PauseAudioDevicecxx . . $ SDL_PauseAudioDevice(3d89109e85ced1be).(devcxx . . $ dev., truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
529 SDL_CloseAudioDevicecxx . . $ SDL_CloseAudioDevice(cb2f890c2fdad230).(devcxx . . $ dev.);
530 devcxx . . $ dev. = 0;
531 }
532
533 audiocxx . . $ audio..callbackOngoingcxx . . $ audio_t#callbackOngoing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
534
535 if (fMixBufferLcxx . . $ fMixBufferL. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
536 {
537 freecxx . . $ free(5d22bdacc48458e8).(fMixBufferLcxx . . $ fMixBufferL.);
538 fMixBufferLcxx . . $ fMixBufferL. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
539 }
540
541 if (fMixBufferRcxx . . $ fMixBufferR. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
542 {
543 freecxx . . $ free(5d22bdacc48458e8).(fMixBufferRcxx . . $ fMixBufferR.);
544 fMixBufferRcxx . . $ fMixBufferR. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
545 }
546 }
547
548 void toggleAmigaPanModecxx . . $ toggleAmigaPanMode(49f6e7a06ebc5aa8).(void)
549 {
550 panningModecxx . . $ panningMode. = (panningModecxx . . $ panningMode. + 1) % 3;
551
552 const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioWasntLocked = !audiocxx . . $ audio..lockedcxx . . $ audio_t#locked.;
553 if (audioWasntLocked)
554 lockAudiocxx . . $ lockAudio(49f6e7a06ebc5aa8).();
555
556 if (panningModecxx . . $ panningMode. == 0)
557 audioSetStereoSeparationcxx . . $ audioSetStereoSeparation(ac50b47256ae7414).(configcxx . . $ config..stereoSeparationcxx . . $ config_t#stereoSeparation.);
558 else if (panningModecxx . . $ panningMode. == 1)
559 audioSetStereoSeparationcxx . . $ audioSetStereoSeparation(ac50b47256ae7414).(0);
560 else
561 audioSetStereoSeparationcxx . . $ audioSetStereoSeparation(ac50b47256ae7414).(100);
562
563 if (audioWasntLocked)
564 unlockAudiocxx . . $ unlockAudio(49f6e7a06ebc5aa8).();
565
566 if (panningModecxx . . $ panningMode. == 0)
567 displayMsgcxx . . $ displayMsg(85c52e162fed56f9).("CUSTOM PANNING");
568 else if (panningModecxx . . $ panningMode. == 1)
569 displayMsgcxx . . $ displayMsg(85c52e162fed56f9).("CENTERED PANNING");
570 else
571 displayMsgcxx . . $ displayMsg(85c52e162fed56f9).("AMIGA PANNING");
572 }
573
574 uint16_tcxx . . $ uint16_t# get16BitPeakcxx . . $ get16BitPeak(5bbf7f3ea503fca5).(int16_tcxx . . $ int16_t# *sampleData, uint32_tcxx . . $ uint32_t# sampleLength)
575 {
576 uint16_tcxx . . $ uint16_t# samplePeak = 0;
577 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
578 {
579 uint16_tcxx . . $ uint16_t# sample = ABScxx . . $ `src/pt2_helpers.h:33:9`!(sampleData[i]);
580 if (samplePeak < sample)
581 samplePeak = sample;
582 }
583
584 return samplePeak;
585 }
586
587 uint32_tcxx . . $ uint32_t# get32BitPeakcxx . . $ get32BitPeak(7ca14e0a6faf8061).(int32_tcxx . . $ int32_t# *sampleData, uint32_tcxx . . $ uint32_t# sampleLength)
588 {
589 uint32_tcxx . . $ uint32_t# samplePeak = 0;
590 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
591 {
592 uint32_tcxx . . $ uint32_t# sample = ABScxx . . $ `src/pt2_helpers.h:33:9`!(sampleData[i]);
593 if (samplePeak < sample)
594 samplePeak = sample;
595 }
596
597 return samplePeak;
598 }
599
600 float getFloatPeakcxx . . $ getFloatPeak(5c3cfcb0fda3feba).(float *fSampleData, uint32_tcxx . . $ uint32_t# sampleLength)
601 {
602 float fSamplePeak = 0.0f;
603 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
604 {
605 const float fSample = fabsf(fSampleData[i]);
606 if (fSamplePeak < fSample)
607 fSamplePeak = fSample;
608 }
609
610 return fSamplePeak;
611 }
612
613 double getDoublePeakcxx . . $ getDoublePeak(fe75d5ffdcd76c3).(double *dSampleData, uint32_tcxx . . $ uint32_t# sampleLength)
614 {
615 double dSamplePeak = 0.0;
616 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
617 {
618 const double dSample = fabs(dSampleData[i]);
619 if (dSamplePeak < dSample)
620 dSamplePeak = dSample;
621 }
622
623 return dSamplePeak;
624 }
625
626 void normalize16BitTo8Bitcxx . . $ normalize16BitTo8Bit(e289b749b410839e).(int16_tcxx . . $ int16_t# *sampleData, uint32_tcxx . . $ uint32_t# sampleLength)
627 {
628 const uint16_tcxx . . $ uint16_t# samplePeak = get16BitPeakcxx . . $ get16BitPeak(5bbf7f3ea503fca5).(sampleData, sampleLength);
629 if (samplePeak == 0 || samplePeak >= INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!)
630 return;
631
632 const double dGain = (double)INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`! / samplePeak;
633 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
634 {
635 const int32_tcxx . . $ int32_t# sample = (const int32_tcxx . . $ int32_t#)(sampleData[i] * dGain);
636 sampleData[i] = (int16_tcxx . . $ int16_t#)sample;
637 }
638 }
639
640 void normalize32BitTo8Bitcxx . . $ normalize32BitTo8Bit(4ccd4d0b8005c765).(int32_tcxx . . $ int32_t# *sampleData, uint32_tcxx . . $ uint32_t# sampleLength)
641 {
642 const uint32_tcxx . . $ uint32_t# samplePeak = get32BitPeakcxx . . $ get32BitPeak(7ca14e0a6faf8061).(sampleData, sampleLength);
643 if (samplePeak == 0 || samplePeak >= INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)
644 return;
645
646 const double dGain = (double)INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`! / samplePeak;
647 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
648 {
649 const int32_tcxx . . $ int32_t# sample = (const int32_tcxx . . $ int32_t#)(sampleData[i] * dGain);
650 sampleData[i] = (int32_tcxx . . $ int32_t#)sample;
651 }
652 }
653
654 void normalizeFloatTo8Bitcxx . . $ normalizeFloatTo8Bit(ac1d28a1859f2825).(float *fSampleData, uint32_tcxx . . $ uint32_t# sampleLength)
655 {
656 const float fSamplePeak = getFloatPeakcxx . . $ getFloatPeak(5c3cfcb0fda3feba).(fSampleData, sampleLength);
657 if (fSamplePeak <= 0.0f)
658 return;
659
660 const float fGain = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / fSamplePeak;
661 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
662 fSampleData[i] *= fGain;
663 }
664
665 void normalizeDoubleTo8Bitcxx . . $ normalizeDoubleTo8Bit(b832380d3925cf6).(double *dSampleData, uint32_tcxx . . $ uint32_t# sampleLength)
666 {
667 const double dSamplePeak = getDoublePeakcxx . . $ getDoublePeak(fe75d5ffdcd76c3).(dSampleData, sampleLength);
668 if (dSamplePeak <= 0.0)
669 return;
670
671 const double dGain = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / dSamplePeak;
672 for (uint32_tcxx . . $ uint32_t# i = 0; i < sampleLength; i++)
673 dSampleData[i] *= dGain;
674 }