Debian Codegraph @

src/pt2_sampling.c

raw symbols SCIP
1 // for finding memory leaks in debug mode with Visual Studio cxx . . $ `<file>/src/pt2_sampling.c`/
2 #if defined _DEBUG && defined _MSC_VER
3 #include <crtdbg.h>
4 #endif
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include <string.h>
10 #include <math.h>
11 #include "pt2_header.h"cxx . . $ `<file>/src/pt2_header.h`/ // PI
12 #include "pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/
13 #include "pt2_sampler.h"cxx . . $ `<file>/src/pt2_sampler.h`/
14 #include "pt2_visuals.h"cxx . . $ `<file>/src/pt2_visuals.h`/
15 #include "pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/
16 #include "pt2_bmp.h"cxx . . $ `<file>/src/pt2_bmp.h`/
17 #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/
18 #include "pt2_tables.h"cxx . . $ `<file>/src/pt2_tables.h`/
19 #include "pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/
20 #include "pt2_sampling.h"cxx . . $ `<file>/src/pt2_sampling.h`/
21 #include "pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/
22
23 enumcxx . . $ $anonymous_type_66d486bc433cd7ff_0#
24 {
25 SAMPLE_LEFTcxx . . $ SAMPLE_LEFT. = 0,
26 SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT. = 1,
27 SAMPLE_MIXcxx . . $ SAMPLE_MIX. = 2
28 };
29
30 // ok settings based on computational time and audio quality
31 #define SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`! 64 /* 2^n */
32 #define SINC_TAPS_BITScxx . . $ `src/pt2_sampling.c:32:9`! 6 /* log2(SINC_TAPS) */
33 #define SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`! 256 /* 2^n */
34 #define SINC_OVERSAMPLING_BITScxx . . $ `src/pt2_sampling.c:34:9`! 8 /* log2(SINC_OVERSAMPLING) */
35
36 #define CENTER_TAPcxx . . $ `src/pt2_sampling.c:36:9`! ((SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2)-1)
37 #define SMP_DELTA_FRAC_BITScxx . . $ `src/pt2_sampling.c:37:9`! 32
38 #define SMP_DELTA_FRAC_SCALEcxx . . $ `src/pt2_sampling.c:38:9`! (1ULL << SMP_DELTA_FRAC_BITScxx . . $ `src/pt2_sampling.c:37:9`!)
39 #define SMP_DELTA_FRAC_MASKcxx . . $ `src/pt2_sampling.c:39:9`! (SMP_DELTA_FRAC_SCALEcxx . . $ `src/pt2_sampling.c:38:9`!-1)
40 #define INTRP_PHASE_SHIFTcxx . . $ `src/pt2_sampling.c:40:9`! (SMP_DELTA_FRAC_BITScxx . . $ `src/pt2_sampling.c:37:9`!-SINC_OVERSAMPLING_BITScxx . . $ `src/pt2_sampling.c:34:9`!)
41 #define INTRP_PHASE_SCALEcxx . . $ `src/pt2_sampling.c:41:9`! (1L << INTRP_PHASE_SHIFTcxx . . $ `src/pt2_sampling.c:40:9`!)
42 #define INTRP_PHASE_MASKcxx . . $ `src/pt2_sampling.c:42:9`! (INTRP_PHASE_SCALEcxx . . $ `src/pt2_sampling.c:41:9`!-1)
43 #define SAMPLE_PREVIEW_WITDHcxx . . $ `src/pt2_sampling.c:43:9`! 194
44 #define SAMPLE_PREVIEW_HEIGHTcxx . . $ `src/pt2_sampling.c:44:9`! 38
45 #define MAX_INPUT_DEVICEScxx . . $ `src/pt2_sampling.c:45:9`! 99
46 #define VISIBLE_LIST_ENTRIEScxx . . $ `src/pt2_sampling.c:46:9`! 4
47 #define SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`! 1024 /* may change on audio input init */
48
49 static volatile boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! callbackBusycxx . . $ callbackBusy., displayingBuffercxx . . $ displayingBuffer., samplingEndedcxx . . $ samplingEnded.;
50 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! audioDevOpencxx . . $ audioDevOpen.;
51 static char *audioInputDevscxx . . $ audioInputDevs.[MAX_INPUT_DEVICEScxx . . $ `src/pt2_sampling.c:45:9`!];
52 static uint8_tcxx . . $ uint8_t# samplingNotecxx . . $ samplingNote. = 33, samplingFinetunecxx . . $ samplingFinetune. = 4; // period 124, max safe period for PAL Paula
53 static int16_tcxx . . $ int16_t# displayBuffercxx . . $ displayBuffer.[SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`!];
54 static int32_tcxx . . $ int32_t# samplingModecxx . . $ samplingMode. = SAMPLE_MIXcxx . . $ SAMPLE_MIX., inputFrequencycxx . . $ inputFrequency., roundedOutputFrequencycxx . . $ roundedOutputFrequency.;
55 static int32_tcxx . . $ int32_t# numAudioInputDevscxx . . $ numAudioInputDevs., audioInputDevListOffsetcxx . . $ audioInputDevListOffset., selectedDevcxx . . $ selectedDev.;
56 static int32_tcxx . . $ int32_t# bytesSampledcxx . . $ bytesSampled., maxSamplingLengthcxx . . $ maxSamplingLength., inputBufferSizecxx . . $ inputBufferSize.;
57 static float *fSincLUTcxx . . $ fSincLUT., *fSamplingBuffercxx . . $ fSamplingBuffer., *fSamplingBufferOrigcxx . . $ fSamplingBufferOrig.;
58 static double dOutputFrequencycxx . . $ dOutputFrequency., dResamplingRatiocxx . . $ dResamplingRatio.;
59 static SDL_AudioDeviceIDcxx . . $ SDL_AudioDeviceID# recordDevcxx . . $ recordDev.;
60
61 static void listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).(void);
62
63 // zeroth-order modified Bessel function of the first kind (series approximation)
64 static inline double besselI0cxx . . $ besselI0(447c67c6676f75c3).(double z)
65 {
66 double s = 1.0, ds = 1.0, d = 2.0;
67 const double zz = z * z;
68
69 do
70 {
71 ds *= zz / (d * d);
72 s += ds;
73 d += 2.0;
74 }
75 while (ds > s*(1E-12));
76
77 return s;
78 }
79
80 static inline double sinccxx . . $ sinc(d8e7e0733fa41c87).(double x, double cutoff)
81 {
82 if (x == 0.0)
83 {
84 return cutoff;
85 }
86 else
87 {
88 x *= PIcxx . . $ `src/pt2_header.h:67:9`!;
89 return sincxx . . $ sin(447c67c6676f75c3).(x * cutoff) / x;
90 }
91 }
92
93 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! calcPolyphaseSincLUTcxx . . $ calcPolyphaseSincLUT(f8197d536af80c96).(double sincCutoff)
94 {
95 fSincLUTcxx . . $ fSincLUT. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`! * (SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`!+1) * sizeof (float));
96 if (fSincLUTcxx . . $ fSincLUT. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
97 {
98 showErrorMsgBoxcxx . . $ showErrorMsgBox(326aeb464d16410c).("Out of memory!");
99 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
100 }
101
102 const double kaiserBeta = 9.62046; // stopband attenuation of ~96dB
103 const double besselI0BetaMul = 1.0 / besselI0cxx . . $ besselI0(447c67c6676f75c3).(kaiserBeta);
104
105 for (int32_tcxx . . $ int32_t# i = 0; i < SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`! * SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`!; i++)
106 {
107 const double x = i * (1.0 / SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`!);
108
109 // Kaiser-Bessel window
110 const double n = (x * (2.0 / SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!)) - 1.0;
111 const double window = besselI0cxx . . $ besselI0(447c67c6676f75c3).(kaiserBeta * sqrtcxx . . $ sqrt(447c67c6676f75c3).(1.0 - n * n)) * besselI0BetaMul;
112
113 const double wsinc = sinccxx . . $ sinc(d8e7e0733fa41c87).(x - (double)(SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`! / 2), sincCutoff) * window;
114
115 // re-arrange for faster logic when in use
116 const int32_tcxx . . $ int32_t# point = i >> SINC_OVERSAMPLING_BITScxx . . $ `src/pt2_sampling.c:34:9`!;
117 const int32_tcxx . . $ int32_t# phase = i & (SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`!-1);
118 fSincLUTcxx . . $ fSincLUT.[(phase << SINC_TAPS_BITScxx . . $ `src/pt2_sampling.c:32:9`!) + ((SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!-1) - point)] = (float)wsinc;
119 }
120
121 // store inverted wrap-around taps after end of LUT (for phase interpolation)
122 float *fEnd = &fSincLUTcxx . . $ fSincLUT.[SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`! * SINC_OVERSAMPLINGcxx . . $ `src/pt2_sampling.c:33:9`!];
123 for (int32_tcxx . . $ int32_t# i = 0; i < SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!; i++)
124 fEnd[i] = fSincLUTcxx . . $ fSincLUT.[(SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!-1) - i];
125
126 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
127 }
128
129 static void freePolyphaseSincLUTcxx . . $ freePolyphaseSincLUT(49f6e7a06ebc5aa8).(void)
130 {
131 if (fSincLUTcxx . . $ fSincLUT. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
132 {
133 freecxx . . $ free(5d22bdacc48458e8).(fSincLUTcxx . . $ fSincLUT.);
134 fSincLUTcxx . . $ fSincLUT. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
135 }
136 }
137
138 static void updateOutputFrequencycxx . . $ updateOutputFrequency(49f6e7a06ebc5aa8).(void)
139 {
140 if (samplingNotecxx . . $ samplingNote. > 35)
141 samplingNotecxx . . $ samplingNote. = 35;
142
143 int32_tcxx . . $ int32_t# period = periodTablecxx . . $ periodTable.[((samplingFinetunecxx . . $ samplingFinetune. & 0xF) * 37) + samplingNotecxx . . $ samplingNote.];
144 if (period < 113) // also happens in our "set period" Paula function
145 period = 113;
146
147 dOutputFrequencycxx . . $ dOutputFrequency. = (double)PAULA_PAL_CLKcxx . . $ `src/pt2_paula.h:14:9`! / period;
148 roundedOutputFrequencycxx . . $ roundedOutputFrequency. = (int32_tcxx . . $ int32_t#)(dOutputFrequencycxx . . $ dOutputFrequency. + 0.5); // for display
149 }
150
151 static void samplingCallbackcxx . . $ samplingCallback(c52f2c8079c5ae6).(void *userdata, Uint8cxx . . $ Uint8# *stream, int len)
152 {
153 callbackBusycxx . . $ callbackBusy. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
154
155 if (!displayingBuffercxx . . $ displayingBuffer.)
156 {
157 if (len > SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`!)
158 len = SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`!;
159
160 const int16_tcxx . . $ int16_t# *L = (int16_tcxx . . $ int16_t# *)stream;
161 const int16_tcxx . . $ int16_t# *R = ((int16_tcxx . . $ int16_t# *)stream) + 1;
162
163 int16_tcxx . . $ int16_t# *dst16 = displayBuffercxx . . $ displayBuffer.;
164
165 if (samplingModecxx . . $ samplingMode. == SAMPLE_LEFTcxx . . $ SAMPLE_LEFT.)
166 {
167 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
168 dst16[i] = L[i << 1];
169 }
170 else if (samplingModecxx . . $ samplingMode. == SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT.)
171 {
172 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
173 dst16[i] = R[i << 1];
174 }
175 else
176 {
177 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
178 dst16[i] = (L[i << 1] + R[i << 1]) >> 1;
179 }
180 }
181
182 if (audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling.)
183 {
184 if (bytesSampledcxx . . $ bytesSampled.+len > maxSamplingLengthcxx . . $ maxSamplingLength.)
185 len = maxSamplingLengthcxx . . $ maxSamplingLength. - bytesSampledcxx . . $ bytesSampled.;
186
187 if (len > inputBufferSizecxx . . $ inputBufferSize.)
188 len = inputBufferSizecxx . . $ inputBufferSize.;
189
190 const int16_tcxx . . $ int16_t# *L = (int16_tcxx . . $ int16_t# *)stream;
191 const int16_tcxx . . $ int16_t# *R = ((int16_tcxx . . $ int16_t# *)stream) + 1;
192
193 float *fSmp = &fSamplingBuffercxx . . $ fSamplingBuffer.[bytesSampledcxx . . $ bytesSampled.];
194
195 if (samplingModecxx . . $ samplingMode. == SAMPLE_LEFTcxx . . $ SAMPLE_LEFT.)
196 {
197 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
198 fSmp[i] = L[i << 1] * (1.0f / (32768.0f / 128.0f));
199 }
200 else if (samplingModecxx . . $ samplingMode. == SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT.)
201 {
202 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
203 fSmp[i] = R[i << 1] * (1.0f / (32768.0f / 128.0f));
204 }
205 else
206 {
207 for (int32_tcxx . . $ int32_t# i = 0; i < len; i++)
208 fSmp[i] = (L[i << 1] + R[i << 1]) * (0.5f / (32768.0f / 128.0f));
209 }
210
211 bytesSampledcxx . . $ bytesSampled. += len;
212 if (bytesSampledcxx . . $ bytesSampled. >= maxSamplingLengthcxx . . $ maxSamplingLength.)
213 {
214 audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
215 samplingEndedcxx . . $ samplingEnded. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
216 }
217 }
218
219 callbackBusycxx . . $ callbackBusy. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
220 (void)userdata;
221 }
222
223 static void stopInputAudiocxx . . $ stopInputAudio(49f6e7a06ebc5aa8).(void)
224 {
225 if (recordDevcxx . . $ recordDev. > 0)
226 {
227 SDL_CloseAudioDevicecxx . . $ SDL_CloseAudioDevice(cb2f890c2fdad230).(recordDevcxx . . $ recordDev.);
228 recordDevcxx . . $ recordDev. = 0;
229 }
230 callbackBusycxx . . $ callbackBusy. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
231 }
232
233 static void startInputAudiocxx . . $ startInputAudio(49f6e7a06ebc5aa8).(void)
234 {
235 SDL_AudioSpeccxx . . $ SDL_AudioSpec# want, have;
236
237 if (recordDevcxx . . $ recordDev. > 0)
238 stopInputAudiocxx . . $ stopInputAudio(49f6e7a06ebc5aa8).();
239
240 if (numAudioInputDevscxx . . $ numAudioInputDevs. == 0 || selectedDevcxx . . $ selectedDev. >= numAudioInputDevscxx . . $ numAudioInputDevs.)
241 {
242 audioDevOpencxx . . $ audioDevOpen. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
243 return;
244 }
245
246 ASSERTcxx . . $ `src/pt2_header.h:25:9`!(roundedOutputFrequency > 0);
247
248 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&want, 0, sizeof (SDL_AudioSpeccxx . . $ SDL_AudioSpec#));
249 want.freqcxx . . $ SDL_AudioSpec#freq. = configcxx . . $ config..audioInputFrequencycxx . . $ config_t#audioInputFrequency.;
250 want.formatcxx . . $ SDL_AudioSpec#format. = AUDIO_S16cxx . . $ `<external>/178947386371380387/SDL_audio.h:98:9`!;
251 want.channelscxx . . $ SDL_AudioSpec#channels. = 2;
252 want.callbackcxx . . $ SDL_AudioSpec#callback. = samplingCallbackcxx . . $ samplingCallback(c52f2c8079c5ae6).;
253 want.userdatacxx . . $ SDL_AudioSpec#userdata. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
254 want.samplescxx . . $ SDL_AudioSpec#samples. = SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`!;
255
256 recordDevcxx . . $ recordDev. = SDL_OpenAudioDevicecxx . . $ SDL_OpenAudioDevice(8944c6df11d5148c).(audioInputDevscxx . . $ audioInputDevs.[selectedDevcxx . . $ selectedDev.], truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!, &want, &have, 0);
257 audioDevOpencxx . . $ audioDevOpen. = (recordDevcxx . . $ recordDev. != 0);
258
259 inputFrequencycxx . . $ inputFrequency. = have.freqcxx . . $ SDL_AudioSpec#freq.;
260 inputBufferSizecxx . . $ inputBufferSize. = have.samplescxx . . $ SDL_AudioSpec#samples.;
261
262 SDL_PauseAudioDevicecxx . . $ SDL_PauseAudioDevice(3d89109e85ced1be).(recordDevcxx . . $ recordDev., falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
263 }
264
265 static void selectAudioDevicecxx . . $ selectAudioDevice(d4f767463ce0a6b3).(int32_tcxx . . $ int32_t# dev)
266 {
267 if (dev < 0)
268 return;
269
270 if (numAudioInputDevscxx . . $ numAudioInputDevs. == 0)
271 {
272 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
273 return;
274 }
275
276 if (dev >= numAudioInputDevscxx . . $ numAudioInputDevs.)
277 return;
278
279 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
280
281 stopInputAudiocxx . . $ stopInputAudio(49f6e7a06ebc5aa8).();
282 selectedDevcxx . . $ selectedDev. = dev;
283 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
284 startInputAudiocxx . . $ startInputAudio(49f6e7a06ebc5aa8).();
285
286 changeStatusTextcxx . . $ changeStatusText(85c52e162fed56f9).(uicxx . . $ ui..statusMessagecxx . . $ ui_t#statusMessage.);
287 }
288
289 void freeAudioDeviceListcxx . . $ freeAudioDeviceList(49f6e7a06ebc5aa8).(void)
290 {
291 for (int32_tcxx . . $ int32_t# i = 0; i < numAudioInputDevscxx . . $ numAudioInputDevs.; i++)
292 {
293 if (audioInputDevscxx . . $ audioInputDevs.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
294 {
295 freecxx . . $ free(5d22bdacc48458e8).(audioInputDevscxx . . $ audioInputDevs.[i]);
296 audioInputDevscxx . . $ audioInputDevs.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
297 }
298 }
299 }
300
301 static void scanAudioDevicescxx . . $ scanAudioDevices(49f6e7a06ebc5aa8).(void)
302 {
303 freeAudioDeviceListcxx . . $ freeAudioDeviceList(49f6e7a06ebc5aa8).();
304
305 numAudioInputDevscxx . . $ numAudioInputDevs. = SDL_GetNumAudioDevicescxx . . $ SDL_GetNumAudioDevices(7864480464b09eea).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
306 if (numAudioInputDevscxx . . $ numAudioInputDevs. > MAX_INPUT_DEVICEScxx . . $ `src/pt2_sampling.c:45:9`!)
307 numAudioInputDevscxx . . $ numAudioInputDevs. = MAX_INPUT_DEVICEScxx . . $ `src/pt2_sampling.c:45:9`!;
308
309 for (int32_tcxx . . $ int32_t# i = 0; i < numAudioInputDevscxx . . $ numAudioInputDevs.; i++)
310 {
311 const char *deviceName = SDL_GetAudioDeviceNamecxx . . $ SDL_GetAudioDeviceName(bd5db3388d838e27).(i, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
312 if (deviceName == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
313 {
314 numAudioInputDevscxx . . $ numAudioInputDevs.--; // hide device
315 continue;
316 }
317
318 const uint32_tcxx . . $ uint32_t# stringLen = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(deviceName);
319
320 audioInputDevscxx . . $ audioInputDevs.[i] = (char *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(stringLen + 2);
321 if (audioInputDevscxx . . $ audioInputDevs.[i] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
322 break;
323
324 if (stringLen > 0)
325 strcpycxx . . $ strcpy(b7b3a83273496486).(audioInputDevscxx . . $ audioInputDevs.[i], deviceName);
326
327 audioInputDevscxx . . $ audioInputDevs.[i][stringLen+1] = '\0'; // UTF-8 needs double null termination (XXX: citation needed)
328 }
329
330 audioInputDevListOffsetcxx . . $ audioInputDevListOffset. = 0; // reset scroll position
331
332 if (selectedDevcxx . . $ selectedDev. >= numAudioInputDevscxx . . $ numAudioInputDevs.)
333 selectedDevcxx . . $ selectedDev. = 0;
334 }
335
336 static void listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).(void)
337 {
338 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(3, 219, 163, 33, PAL_BACKGRDcxx . . $ PAL_BACKGRD.);
339
340 if (numAudioInputDevscxx . . $ numAudioInputDevs. == 0)
341 {
342 textOutcxx . . $ textOut(ecc378a7b29cfb5a).(16, 219+13, "NO DEVICES FOUND!", videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.]);
343 return;
344 }
345
346 for (int32_tcxx . . $ int32_t# i = 0; i < VISIBLE_LIST_ENTRIEScxx . . $ `src/pt2_sampling.c:46:9`!; i++)
347 {
348 const int32_tcxx . . $ int32_t# dev = audioInputDevListOffsetcxx . . $ audioInputDevListOffset.+i;
349 if (audioInputDevListOffsetcxx . . $ audioInputDevListOffset.+i >= numAudioInputDevscxx . . $ numAudioInputDevs.)
350 break;
351
352 if (dev == selectedDevcxx . . $ selectedDev.)
353 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(4, 219+1+(i*(FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!+3)), 161, 8, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKG2cxx . . $ PAL_GENBKG2.]);
354
355 if (audioInputDevscxx . . $ audioInputDevs.[dev] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
356 textOutTightNcxx . . $ textOutTightN(14940e7ead0326d3).(2+2, 219+2+(i*(FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!+3)), audioInputDevscxx . . $ audioInputDevs.[dev], 23, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.]);
357 }
358 }
359
360 static void drawSamplingNotecxx . . $ drawSamplingNote(49f6e7a06ebc5aa8).(void)
361 {
362 ASSERTcxx . . $ `src/pt2_header.h:25:9`!(samplingNote < 36);
363 const char *str = configcxx . . $ config..accidentalcxx . . $ config_t#accidental. ? noteNames2cxx . . $ noteNames2.[2+samplingNotecxx . . $ samplingNote.]: noteNames1cxx . . $ noteNames1.[2+samplingNotecxx . . $ samplingNote.];
364 textOutBgcxx . . $ textOutBg(14940e7ead0326d3).(262, 230, str, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
365 }
366
367 static void drawSamplingFinetunecxx . . $ drawSamplingFinetune(49f6e7a06ebc5aa8).(void)
368 {
369 textOutBgcxx . . $ textOutBg(14940e7ead0326d3).(254, 219, ftuneStrTabcxx . . $ ftuneStrTab.[samplingFinetunecxx . . $ samplingFinetune. & 0xF], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
370 }
371
372 static void drawSamplingFrequencycxx . . $ drawSamplingFrequency(49f6e7a06ebc5aa8).(void)
373 {
374 char str[16];
375 sprintfcxx . . $ sprintf(26c8642d26409d6d).(str, "%05dHZ", roundedOutputFrequencycxx . . $ roundedOutputFrequency.);
376
377 const int32_tcxx . . $ int32_t# maxSafeFrequency = (int32_tcxx . . $ int32_t#)(PAL_PAULA_MAX_SAFE_HZcxx . . $ `src/pt2_paula.h:18:9`! + 0.5); // rounded
378 textOutBgcxx . . $ textOutBg(14940e7ead0326d3).(262, 208, str, roundedOutputFrequencycxx . . $ roundedOutputFrequency. <= maxSafeFrequency ? videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.] : 0x8C0F0F, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
379 }
380
381 static void drawSamplingModeCrosscxx . . $ drawSamplingModeCross(49f6e7a06ebc5aa8).(void)
382 {
383 // clear old crosses
384 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(4, 208, 6, 5, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
385 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(51, 208, 6, 5, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
386 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(105, 208, 6, 5, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
387
388 int16_tcxx . . $ int16_t# x;
389 if (samplingModecxx . . $ samplingMode. == SAMPLE_LEFTcxx . . $ SAMPLE_LEFT.)
390 x = 3;
391 else if (samplingModecxx . . $ samplingMode. == SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT.)
392 x = 50;
393 else
394 x = 104;
395
396 charOutcxx . . $ charOut(e6c1e39bfc2b37).(x, 208, 'X', videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]);
397 }
398
399 static void showCurrSamplecxx . . $ showCurrSample(49f6e7a06ebc5aa8).(void)
400 {
401 updateCurrSamplecxx . . $ updateCurrSample(49f6e7a06ebc5aa8).();
402
403 // reset sampler screen attributes
404 samplercxx . . $ sampler..loopStartPoscxx . . $ sampler_t#loopStartPos. = 0;
405 samplercxx . . $ sampler..loopEndPoscxx . . $ sampler_t#loopEndPos. = 0;
406 editorcxx . . $ editor..markStartOfscxx . . $ editor_t#markStartOfs. = -1;
407 editorcxx . . $ editor..markEndOfscxx . . $ editor_t#markEndOfs. = -1;
408 editorcxx . . $ editor..samplePoscxx . . $ editor_t#samplePos. = 0;
409 hideSpritecxx . . $ hideSprite(d4f767463ce0a6b3).(SPRITE_LOOP_PIN_LEFTcxx . . $ SPRITE_LOOP_PIN_LEFT.);
410 hideSpritecxx . . $ hideSprite(d4f767463ce0a6b3).(SPRITE_LOOP_PIN_RIGHTcxx . . $ SPRITE_LOOP_PIN_RIGHT.);
411
412 renderSampleDatacxx . . $ renderSampleData(49f6e7a06ebc5aa8).();
413 }
414
415 void renderSamplingBoxcxx . . $ renderSamplingBox(49f6e7a06ebc5aa8).(void)
416 {
417 modStopcxx . . $ modStop(49f6e7a06ebc5aa8).();
418 editorcxx . . $ editor..songPlayingcxx . . $ editor_t#songPlaying. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
419 editorcxx . . $ editor..playModecxx . . $ editor_t#playMode. = PLAY_MODE_NORMALcxx . . $ PLAY_MODE_NORMAL.;
420 editorcxx . . $ editor..currModecxx . . $ editor_t#currMode. = MODE_IDLEcxx . . $ MODE_IDLE.;
421 pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_IDLEcxx . . $ POINTER_MODE_IDLE., DO_CARRYcxx . . $ DO_CARRY.);
422
423 editorcxx . . $ editor..sampleZerocxx . . $ editor_t#sampleZero. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
424 editorcxx . . $ editor..blockMarkFlagcxx . . $ editor_t#blockMarkFlag. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
425
426 // remove all open screens (except sampler)
427 if (uicxx . . $ ui..diskOpScreenShowncxx . . $ ui_t#diskOpScreenShown. || uicxx . . $ ui..posEdScreenShowncxx . . $ ui_t#posEdScreenShown. || uicxx . . $ ui..editOpScreenShowncxx . . $ ui_t#editOpScreenShown.)
428 {
429 uicxx . . $ ui..diskOpScreenShowncxx . . $ ui_t#diskOpScreenShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
430 uicxx . . $ ui..posEdScreenShowncxx . . $ ui_t#posEdScreenShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
431 uicxx . . $ ui..editOpScreenShowncxx . . $ ui_t#editOpScreenShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
432
433 displayMainScreencxx . . $ displayMainScreen(49f6e7a06ebc5aa8).();
434 }
435
436 blit32cxx . . $ blit32(5f3dcb304cf8bfc1).(0, 203, 320, 52, samplingBoxBMPcxx . . $ samplingBoxBMP.);
437
438 // render sample monitor
439 blit32cxx . . $ blit32(5f3dcb304cf8bfc1).(120, 44, 200, 55, sampleMonitorBMPcxx . . $ sampleMonitorBMP.);
440 memsetcxx . . $ memset(d1de1e4fb215f1c6).(displayBuffercxx . . $ displayBuffer., 0, sizeof (displayBuffercxx . . $ displayBuffer.));
441 hLinecxx . . $ hLine(78a5fb7015678ec5).(123, 76, 194, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.]); // draw center line
442
443 updateOutputFrequencycxx . . $ updateOutputFrequency(49f6e7a06ebc5aa8).();
444 drawSamplingNotecxx . . $ drawSamplingNote(49f6e7a06ebc5aa8).();
445 drawSamplingFinetunecxx . . $ drawSamplingFinetune(49f6e7a06ebc5aa8).();
446 drawSamplingFrequencycxx . . $ drawSamplingFrequency(49f6e7a06ebc5aa8).();
447 drawSamplingModeCrosscxx . . $ drawSamplingModeCross(49f6e7a06ebc5aa8).();
448 showCurrSamplecxx . . $ showCurrSample(49f6e7a06ebc5aa8).();
449
450 changeStatusTextcxx . . $ changeStatusText(85c52e162fed56f9).("PLEASE WAIT...");
451 flipFramecxx . . $ flipFrame(49f6e7a06ebc5aa8).();
452 hpc_ResetCounterscxx . . $ hpc_ResetCounters(efacbc4df292ea9a).(&videocxx . . $ video..vblankHpccxx . . $ video_t#vblankHpc.);
453 scanAudioDevicescxx . . $ scanAudioDevices(49f6e7a06ebc5aa8).();
454 selectAudioDevicecxx . . $ selectAudioDevice(d4f767463ce0a6b3).(selectedDevcxx . . $ selectedDev.);
455 setStatusMessagecxx . . $ setStatusMessage(90ef5b561fbcb8de).("ALL RIGHT", DO_CARRYcxx . . $ DO_CARRY.);
456 }
457
458 static int32_tcxx . . $ int32_t# scrPos2SmpBufPoscxx . . $ scrPos2SmpBufPos(7864480464b09eea).(int32_tcxx . . $ int32_t# x) // x = 0..SAMPLE_PREVIEW_WITDH
459 {
460 return (x * ((SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`! << 16) / SAMPLE_PREVIEW_WITDHcxx . . $ `src/pt2_sampling.c:43:9`!)) >> 16;
461 }
462
463 static uint8_tcxx . . $ uint8_t# getDispBuffPeakcxx . . $ getDispBuffPeak(9d96ba1baa45a1d9).(const int16_tcxx . . $ int16_t# *smpData, int32_tcxx . . $ int32_t# smpNum)
464 {
465 int32_tcxx . . $ int32_t# smpAbs, max = 0;
466 for (int32_tcxx . . $ int32_t# i = 0; i < smpNum; i++)
467 {
468 const int32_tcxx . . $ int32_t# smp = smpData[i];
469
470 smpAbs = ABScxx . . $ `src/pt2_helpers.h:33:9`!(smp);
471 if (smpAbs > max)
472 max = smpAbs;
473 }
474
475 max = ((max * SAMPLE_PREVIEW_HEIGHTcxx . . $ `src/pt2_sampling.c:44:9`!) + 32768) >> 16;
476 if (max > (SAMPLE_PREVIEW_HEIGHTcxx . . $ `src/pt2_sampling.c:44:9`!/2)-1)
477 max = (SAMPLE_PREVIEW_HEIGHTcxx . . $ `src/pt2_sampling.c:44:9`!/2)-1;
478
479 return (uint8_tcxx . . $ uint8_t#)max;
480 }
481
482 void writeSampleMonitorWaveformcxx . . $ writeSampleMonitorWaveform(49f6e7a06ebc5aa8).(void) // called every frame
483 {
484 if (!uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown. || uicxx . . $ ui..askBoxShowncxx . . $ ui_t#askBoxShown.)
485 return;
486
487 if (samplingEndedcxx . . $ samplingEnded.)
488 {
489 samplingEndedcxx . . $ samplingEnded. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
490 stopSamplingcxx . . $ stopSampling(49f6e7a06ebc5aa8).();
491 }
492
493 // clear waveform background
494 fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(123, 58, SAMPLE_PREVIEW_WITDHcxx . . $ `src/pt2_sampling.c:43:9`!, SAMPLE_PREVIEW_HEIGHTcxx . . $ `src/pt2_sampling.c:44:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_BACKGRDcxx . . $ PAL_BACKGRD.]);
495
496 if (!audioDevOpencxx . . $ audioDevOpen.)
497 {
498 textOutTightcxx . . $ textOutTight(ecc378a7b29cfb5a).(136, 74, "CAN'T OPEN AUDIO DEVICE!", videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.]);
499 return;
500 }
501
502 uint32_tcxx . . $ uint32_t# *centerPtr = &videocxx . . $ video..frameBuffercxx . . $ video_t#frameBuffer.[(76 * SCREEN_Wcxx . . $ `src/pt2_header.h:41:9`!) + 123];
503
504 // hardcoded for a buffer size of 512
505 displayingBuffercxx . . $ displayingBuffer. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
506 for (int32_tcxx . . $ int32_t# x = 0; x < SAMPLE_PREVIEW_WITDHcxx . . $ `src/pt2_sampling.c:43:9`!; x++)
507 {
508 int32_tcxx . . $ int32_t# smpIdx = scrPos2SmpBufPoscxx . . $ scrPos2SmpBufPos(7864480464b09eea).(x);
509 int32_tcxx . . $ int32_t# smpNum = scrPos2SmpBufPoscxx . . $ scrPos2SmpBufPos(7864480464b09eea).(x+1) - smpIdx;
510
511 if (smpIdx+smpNum >= SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`!)
512 smpNum = SAMPLING_BUFFER_SIZEcxx . . $ `src/pt2_sampling.c:47:9`! - smpIdx;
513
514 const int32_tcxx . . $ int32_t# smpAbs = getDispBuffPeakcxx . . $ getDispBuffPeak(9d96ba1baa45a1d9).(&displayBuffercxx . . $ displayBuffer.[smpIdx], smpNum);
515 if (smpAbs == 0)
516 centerPtr[x] = videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.];
517 else
518 vLinecxx . . $ vLine(78a5fb7015678ec5).(x + 123, 76 - smpAbs, (smpAbs * 2) + 1, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_QADSCPcxx . . $ PAL_QADSCP.]);
519 }
520 displayingBuffercxx . . $ displayingBuffer. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
521 }
522
523 void removeSamplingBoxcxx . . $ removeSamplingBox(49f6e7a06ebc5aa8).(void)
524 {
525 stopInputAudiocxx . . $ stopInputAudio(49f6e7a06ebc5aa8).();
526 freeAudioDeviceListcxx . . $ freeAudioDeviceList(49f6e7a06ebc5aa8).();
527
528 uicxx . . $ ui..aboutScreenShowncxx . . $ ui_t#aboutScreenShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
529 editorcxx . . $ editor..blockMarkFlagcxx . . $ editor_t#blockMarkFlag. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
530 displayMainScreencxx . . $ displayMainScreen(49f6e7a06ebc5aa8).();
531 updateVisualizercxx . . $ updateVisualizer(49f6e7a06ebc5aa8).(); // kludge
532
533 // re-render sampler screen
534 exitFromSamcxx . . $ exitFromSam(49f6e7a06ebc5aa8).();
535 samplerScreencxx . . $ samplerScreen(49f6e7a06ebc5aa8).();
536 }
537
538 static void startSamplingcxx . . $ startSampling(49f6e7a06ebc5aa8).(void)
539 {
540 if (!audioDevOpencxx . . $ audioDevOpen.)
541 {
542 displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("DEVICE ERROR !");
543 return;
544 }
545
546 ASSERTcxx . . $ `src/pt2_header.h:25:9`!(roundedOutputFrequency > 0);
547
548 dResamplingRatiocxx . . $ dResamplingRatio. = dOutputFrequencycxx . . $ dOutputFrequency. / inputFrequencycxx . . $ inputFrequency.;
549 maxSamplingLengthcxx . . $ maxSamplingLength. = (int32_tcxx . . $ int32_t#)ceilcxx . . $ ceil(447c67c6676f75c3).(configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. /dResamplingRatiocxx . . $ dResamplingRatio.) + 1;
550
551 const int32_tcxx . . $ int32_t# allocLen = (SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2) + maxSamplingLengthcxx . . $ maxSamplingLength. + (SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2);
552
553 fSamplingBufferOrigcxx . . $ fSamplingBufferOrig. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(allocLen * sizeof (float));
554 if (fSamplingBufferOrigcxx . . $ fSamplingBufferOrig. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
555 {
556 statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).();
557 return;
558 }
559 fSamplingBuffercxx . . $ fSamplingBuffer. = fSamplingBufferOrigcxx . . $ fSamplingBufferOrig. + (SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2); // allow negative look-up for sinc taps
560
561 // clear tap area before sample
562 memsetcxx . . $ memset(d1de1e4fb215f1c6).(fSamplingBufferOrigcxx . . $ fSamplingBufferOrig., 0, (SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2) * sizeof (float));
563
564 const double sincCutoff = MINcxx . . $ `src/pt2_helpers.h:34:9`!(1.0, dResamplingRatio);
565 if (!calcPolyphaseSincLUTcxx . . $ calcPolyphaseSincLUT(f8197d536af80c96).(sincCutoff))
566 {
567 freecxx . . $ free(5d22bdacc48458e8).(fSamplingBufferOrigcxx . . $ fSamplingBufferOrig.);
568 statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).();
569 return;
570 }
571
572 bytesSampledcxx . . $ bytesSampled. = 0;
573 samplingEndedcxx . . $ samplingEnded. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
574 audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
575
576 turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).();
577
578 pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_RECORDcxx . . $ POINTER_MODE_RECORD., NO_CARRYcxx . . $ NO_CARRY.);
579 setStatusMessagecxx . . $ setStatusMessage(90ef5b561fbcb8de).("SAMPLING ...", NO_CARRYcxx . . $ NO_CARRY.);
580 }
581
582 static float sincInterpolationcxx . . $ sincInterpolation(5dfafd89eb6e32d9).(const float *fSmpData, const uint32_tcxx . . $ uint32_t# frac)
583 {
584 const uint32_tcxx . . $ uint32_t# lutPhase = frac >> INTRP_PHASE_SHIFTcxx . . $ `src/pt2_sampling.c:40:9`!;
585 const float fIntrpFrac = (frac & INTRP_PHASE_MASKcxx . . $ `src/pt2_sampling.c:42:9`!) * (1.0f / INTRP_PHASE_SCALEcxx . . $ `src/pt2_sampling.c:41:9`!);
586
587 // it may look like we go out of bounds for fSinc_2, but we have an extra phase after LUT
588 const float *fSinc_1 = fSincLUTcxx . . $ fSincLUT. + ( lutPhase << SINC_TAPS_BITScxx . . $ `src/pt2_sampling.c:32:9`!);
589 const float *fSinc_2 = fSincLUTcxx . . $ fSincLUT. + ((lutPhase+1) << SINC_TAPS_BITScxx . . $ `src/pt2_sampling.c:32:9`!);
590
591 float fSum = 0.0f;
592 for (int32_tcxx . . $ int32_t# i = 0; i < SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!; i++)
593 {
594 const float fSample = fSmpData[i];
595
596 // do linear interpolation between phases
597 const float y1 = fSinc_1[i];
598 const float y2 = fSinc_2[i];
599 fSum += fSample * (y1 + ((y2 - y1) * fIntrpFrac));
600 }
601
602 return fSum;
603 }
604
605 static int32_tcxx . . $ int32_t# resampleSamplingBuffercxx . . $ resampleSamplingBuffer(b126dc7c1de90089).(void)
606 {
607 int32_tcxx . . $ int32_t# newSampleLength = (int32_tcxx . . $ int32_t#)(bytesSampledcxx . . $ bytesSampled. * dResamplingRatiocxx . . $ dResamplingRatio.) & ~1;
608 if (newSampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
609 newSampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
610
611 float *fBuffer = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(newSampleLength * sizeof (float));
612 if (fBuffer == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
613 {
614 statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).();
615 return -1;
616 }
617
618 // pre-center sample data pointer (left side is pre-cleared)
619 const float *fSmpData = &fSamplingBuffercxx . . $ fSamplingBuffer.[-CENTER_TAPcxx . . $ `src/pt2_sampling.c:36:9`!];
620
621 // set out-of-bounds sampling tap area
622 for (int32_tcxx . . $ int32_t# i = 0; i < SINC_TAPScxx . . $ `src/pt2_sampling.c:31:9`!/2; i++)
623 {
624 fSamplingBuffercxx . . $ fSamplingBuffer.[i-CENTER_TAPcxx . . $ `src/pt2_sampling.c:36:9`!] = fSamplingBuffercxx . . $ fSamplingBuffer.[0];
625 fSamplingBuffercxx . . $ fSamplingBuffer.[bytesSampledcxx . . $ bytesSampled.+i] = fSamplingBuffercxx . . $ fSamplingBuffer.[bytesSampledcxx . . $ bytesSampled.-1];
626 }
627
628 const uint64_tcxx . . $ uint64_t# delta = (uint64_tcxx . . $ uint64_t#)roundcxx . . $ round(447c67c6676f75c3).(SMP_DELTA_FRAC_SCALEcxx . . $ `src/pt2_sampling.c:38:9`! / dResamplingRatiocxx . . $ dResamplingRatio.);
629 uint64_tcxx . . $ uint64_t# frac = 0;
630
631 float fSmpPeak = 0.0f;
632 for (int32_tcxx . . $ int32_t# i = 0; i < newSampleLength; i++)
633 {
634 float fSmp;
635
636 if (i < 2) // clear first 2 samps. (to prevent "stuck beep"), do it here for norm. peak scan
637 fSmp = 0.0f;
638 else
639 fSmp = sincInterpolationcxx . . $ sincInterpolation(5dfafd89eb6e32d9).(fSmpData, (uint32_tcxx . . $ uint32_t#)frac);
640
641 fBuffer[i] = fSmp;
642
643 // get peak (for normalization)
644 if (fSmp < 0.0f)
645 fSmp = -fSmp;
646
647 if (fSmp > fSmpPeak)
648 fSmpPeak = fSmp;
649 // -------------------
650
651 frac += delta;
652 fSmpData += (uint32_tcxx . . $ uint32_t#)(frac >> SMP_DELTA_FRAC_BITScxx . . $ `src/pt2_sampling.c:37:9`!);
653 frac &= SMP_DELTA_FRAC_MASKcxx . . $ `src/pt2_sampling.c:39:9`!;
654 }
655
656 // normalize and quantize to 8-bit integer
657
658 int8_tcxx . . $ int8_t# *output = &songcxx . . $ song.->sampleDatacxx . . $ module_t#sampleData.[songcxx . . $ song.->samplescxx . . $ module_t#samples.[editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.].offsetcxx . . $ moduleSample_t#offset.];
659 if (fSmpPeak <= 0.25f)
660 {
661 // clear output sample if sampling peak was extremely low
662 memsetcxx . . $ memset(d1de1e4fb215f1c6).(output, 0, newSampleLength);
663 }
664 else
665 {
666 const float fAmpMul = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / fSmpPeak;
667 for (int32_tcxx . . $ int32_t# i = 0; i < newSampleLength; i++)
668 output[i] = (int8_tcxx . . $ int8_t#)roundf(fBuffer[i] * fAmpMul);
669 }
670
671 freecxx . . $ free(5d22bdacc48458e8).(fBuffer);
672 return newSampleLength;
673 }
674
675 void stopSamplingcxx . . $ stopSampling(49f6e7a06ebc5aa8).(void)
676 {
677 while (callbackBusycxx . . $ callbackBusy.);
678 audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
679
680 int32_tcxx . . $ int32_t# newLength = resampleSamplingBuffercxx . . $ resampleSamplingBuffer(b126dc7c1de90089).();
681
682 if (fSamplingBufferOrigcxx . . $ fSamplingBufferOrig. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
683 {
684 freecxx . . $ free(5d22bdacc48458e8).(fSamplingBufferOrigcxx . . $ fSamplingBufferOrig.);
685 fSamplingBufferOrigcxx . . $ fSamplingBufferOrig. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
686 }
687
688 freePolyphaseSincLUTcxx . . $ freePolyphaseSincLUT(49f6e7a06ebc5aa8).();
689
690 if (newLength == -1)
691 return; // out of memory
692
693 moduleSample_tcxx . . $ moduleSample_t# *s = &songcxx . . $ song.->samplescxx . . $ module_t#samples.[editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.];
694 s->lengthcxx . . $ moduleSample_t#length. = newLength;
695 s->fineTunecxx . . $ moduleSample_t#fineTune. = samplingFinetunecxx . . $ samplingFinetune.;
696 s->loopStartcxx . . $ moduleSample_t#loopStart. = 0;
697 s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2;
698 s->volumecxx . . $ moduleSample_t#volume. = 64;
699
700 pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_IDLEcxx . . $ POINTER_MODE_IDLE., DO_CARRYcxx . . $ DO_CARRY.);
701 statusAllRightcxx . . $ statusAllRight(49f6e7a06ebc5aa8).();
702
703 showCurrSamplecxx . . $ showCurrSample(49f6e7a06ebc5aa8).();
704 }
705
706 static void scrollListUpcxx . . $ scrollListUp(49f6e7a06ebc5aa8).(void)
707 {
708 if (numAudioInputDevscxx . . $ numAudioInputDevs. <= VISIBLE_LIST_ENTRIEScxx . . $ `src/pt2_sampling.c:46:9`!)
709 {
710 audioInputDevListOffsetcxx . . $ audioInputDevListOffset. = 0;
711 return;
712 }
713
714 if (audioInputDevListOffsetcxx . . $ audioInputDevListOffset. > 0)
715 {
716 audioInputDevListOffsetcxx . . $ audioInputDevListOffset.--;
717 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
718 mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. = 0;
719 }
720 }
721
722 static void scrollListDowncxx . . $ scrollListDown(49f6e7a06ebc5aa8).(void)
723 {
724 if (numAudioInputDevscxx . . $ numAudioInputDevs. <= VISIBLE_LIST_ENTRIEScxx . . $ `src/pt2_sampling.c:46:9`!)
725 {
726 audioInputDevListOffsetcxx . . $ audioInputDevListOffset. = 0;
727 return;
728 }
729
730 if (audioInputDevListOffsetcxx . . $ audioInputDevListOffset. < numAudioInputDevscxx . . $ numAudioInputDevs.-VISIBLE_LIST_ENTRIEScxx . . $ `src/pt2_sampling.c:46:9`!)
731 {
732 audioInputDevListOffsetcxx . . $ audioInputDevListOffset.++;
733 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
734 mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. = 1;
735 }
736 }
737
738 static void finetuneUpcxx . . $ finetuneUp(49f6e7a06ebc5aa8).(void)
739 {
740 if ((int8_tcxx . . $ int8_t#)samplingFinetunecxx . . $ samplingFinetune. < 7)
741 {
742 samplingFinetunecxx . . $ samplingFinetune.++;
743 updateOutputFrequencycxx . . $ updateOutputFrequency(49f6e7a06ebc5aa8).();
744 drawSamplingFinetunecxx . . $ drawSamplingFinetune(49f6e7a06ebc5aa8).();
745 drawSamplingFrequencycxx . . $ drawSamplingFrequency(49f6e7a06ebc5aa8).();
746 mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. = 2;
747 }
748 }
749
750 static void finetuneDowncxx . . $ finetuneDown(49f6e7a06ebc5aa8).(void)
751 {
752 if ((int8_tcxx . . $ int8_t#)samplingFinetunecxx . . $ samplingFinetune. > -8)
753 {
754 samplingFinetunecxx . . $ samplingFinetune.--;
755 updateOutputFrequencycxx . . $ updateOutputFrequency(49f6e7a06ebc5aa8).();
756 drawSamplingFinetunecxx . . $ drawSamplingFinetune(49f6e7a06ebc5aa8).();
757 drawSamplingFrequencycxx . . $ drawSamplingFrequency(49f6e7a06ebc5aa8).();
758 mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. = 3;
759 }
760 }
761
762 void samplingSampleNumUpcxx . . $ samplingSampleNumUp(49f6e7a06ebc5aa8).(void)
763 {
764 if (editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample. < 30)
765 {
766 editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.++;
767 showCurrSamplecxx . . $ showCurrSample(49f6e7a06ebc5aa8).();
768 }
769 }
770
771 void samplingSampleNumDowncxx . . $ samplingSampleNumDown(49f6e7a06ebc5aa8).(void)
772 {
773 if (editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample. > 0)
774 {
775 editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.--;
776 showCurrSamplecxx . . $ showCurrSample(49f6e7a06ebc5aa8).();
777 }
778 }
779
780 void handleSamplingBoxcxx . . $ handleSamplingBox(49f6e7a06ebc5aa8).(void)
781 {
782 if (uicxx . . $ ui..changingSamplingNotecxx . . $ ui_t#changingSamplingNote.)
783 {
784 uicxx . . $ ui..changingSamplingNotecxx . . $ ui_t#changingSamplingNote. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
785 setPrevStatusMessagecxx . . $ setPrevStatusMessage(49f6e7a06ebc5aa8).();
786 pointerSetPreviousModecxx . . $ pointerSetPreviousMode(49f6e7a06ebc5aa8).();
787 drawSamplingNotecxx . . $ drawSamplingNote(49f6e7a06ebc5aa8).();
788 return;
789 }
790
791 if (mousecxx . . $ mouse..rightButtonPressedcxx . . $ mouse_t#rightButtonPressed.)
792 {
793 if (audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling.)
794 stopSamplingcxx . . $ stopSampling(49f6e7a06ebc5aa8).();
795 else
796 startSamplingcxx . . $ startSampling(49f6e7a06ebc5aa8).();
797
798 return;
799 }
800
801 if (!mousecxx . . $ mouse..leftButtonPressedcxx . . $ mouse_t#leftButtonPressed.)
802 return;
803
804 mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. = -1;
805 mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter. = 0;
806
807 if (audiocxx . . $ audio..isSamplingcxx . . $ audio_t#isSampling.)
808 {
809 stopSamplingcxx . . $ stopSampling(49f6e7a06ebc5aa8).();
810 return;
811 }
812
813 // check buttons
814 const int32_tcxx . . $ int32_t# mx = mousecxx . . $ mouse..xcxx . . $ mouse_t#x.;
815 const int32_tcxx . . $ int32_t# my = mousecxx . . $ mouse..ycxx . . $ mouse_t#y.;
816
817 if (mx >= 182 && mx <= 243 && my >= 0 && my <= 10) // STOP (main UI)
818 {
819 turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).();
820 }
821
822 if (mx >= 6 && mx <= 25 && my >= 124 && my <= 133) // EXIT (main UI)
823 {
824 uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
825 removeSamplingBoxcxx . . $ removeSamplingBox(49f6e7a06ebc5aa8).();
826 exitFromSamcxx . . $ exitFromSam(49f6e7a06ebc5aa8).();
827 }
828
829 if (mx >= 98 && mx <= 108 && my >= 44 && my <= 54) // SAMPLE UP (main UI)
830 {
831 samplingSampleNumUpcxx . . $ samplingSampleNumUp(49f6e7a06ebc5aa8).();
832 }
833
834 else if (mx >= 109 && mx <= 119 && my >= 44 && my <= 54) // SAMPLE DOWN (main UI)
835 {
836 samplingSampleNumDowncxx . . $ samplingSampleNumDown(49f6e7a06ebc5aa8).();
837 }
838
839 else if (mx >= 143 && mx <= 176 && my >= 205 && my <= 215) // SCAN
840 {
841 if (audiocxx . . $ audio..rescanAudioDevicesSupportedcxx . . $ audio_t#rescanAudioDevicesSupported.)
842 {
843 scanAudioDevicescxx . . $ scanAudioDevices(49f6e7a06ebc5aa8).();
844 listAudioDevicescxx . . $ listAudioDevices(49f6e7a06ebc5aa8).();
845 }
846 else
847 {
848 displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED !");
849 }
850 }
851
852 else if (mx >= 4 && mx <= 165 && my >= 220 && my <= 250) // DEVICE LIST
853 {
854 selectAudioDevicecxx . . $ selectAudioDevice(d4f767463ce0a6b3).(audioInputDevListOffsetcxx . . $ audioInputDevListOffset. + ((my - 220) >> 3));
855 }
856
857 else if (mx >= 2 && mx <= 41 && my >= 206 && my <= 216) // LEFT
858 {
859 if (samplingModecxx . . $ samplingMode. != SAMPLE_LEFTcxx . . $ SAMPLE_LEFT.)
860 {
861 samplingModecxx . . $ samplingMode. = SAMPLE_LEFTcxx . . $ SAMPLE_LEFT.;
862 drawSamplingModeCrosscxx . . $ drawSamplingModeCross(49f6e7a06ebc5aa8).();
863 }
864 }
865
866 else if (mx >= 49 && mx <= 95 && my >= 206 && my <= 216) // RIGHT
867 {
868 if (samplingModecxx . . $ samplingMode. != SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT.)
869 {
870 samplingModecxx . . $ samplingMode. = SAMPLE_RIGHTcxx . . $ SAMPLE_RIGHT.;
871 drawSamplingModeCrosscxx . . $ drawSamplingModeCross(49f6e7a06ebc5aa8).();
872 }
873 }
874
875 else if (mx >= 103 && mx <= 135 && my >= 206 && my <= 216) // MIX
876 {
877 if (samplingModecxx . . $ samplingMode. != SAMPLE_MIXcxx . . $ SAMPLE_MIX.)
878 {
879 samplingModecxx . . $ samplingMode. = SAMPLE_MIXcxx . . $ SAMPLE_MIX.;
880 drawSamplingModeCrosscxx . . $ drawSamplingModeCross(49f6e7a06ebc5aa8).();
881 }
882 }
883
884 else if (mx >= 188 && mx <= 237 && my >= 242 && my <= 252) // SAMPLE
885 {
886 startSamplingcxx . . $ startSampling(49f6e7a06ebc5aa8).();
887 }
888
889 else if (mx >= 242 && mx <= 277 && my >= 242 && my <= 252) // NOTE
890 {
891 uicxx . . $ ui..changingSamplingNotecxx . . $ ui_t#changingSamplingNote. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
892 textOutBgcxx . . $ textOutBg(14940e7ead0326d3).(262, 230, "---", videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]);
893 setStatusMessagecxx . . $ setStatusMessage(90ef5b561fbcb8de).("SELECT NOTE", NO_CARRYcxx . . $ NO_CARRY.);
894 pointerSetModecxx . . $ pointerSetMode(f2ac3508b56cd10).(POINTER_MODE_MSG1cxx . . $ POINTER_MODE_MSG1., NO_CARRYcxx . . $ NO_CARRY.);
895 }
896
897 else if (mx >= 282 && mx <= 317 && my >= 242 && my <= 252) // EXIT
898 {
899 uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
900 removeSamplingBoxcxx . . $ removeSamplingBox(49f6e7a06ebc5aa8).();
901 }
902
903 else if (mx >= 166 && mx <= 177 && my >= 218 && my <= 228) // SCROLL LIST UP
904 {
905 scrollListUpcxx . . $ scrollListUp(49f6e7a06ebc5aa8).();
906 }
907
908 else if (mx >= 166 && mx <= 177 && my >= 242 && my <= 252) // SCROLL LIST DOWN
909 {
910 scrollListDowncxx . . $ scrollListDown(49f6e7a06ebc5aa8).();
911 }
912
913 else if (mx >= 296 && mx <= 306 && my >= 217 && my <= 227) // FINETUNE UP
914 {
915 finetuneUpcxx . . $ finetuneUp(49f6e7a06ebc5aa8).();
916 }
917
918 else if (mx >= 307 && mx <= 317 && my >= 217 && my <= 227) // FINETUNE DOWN
919 {
920 finetuneDowncxx . . $ finetuneDown(49f6e7a06ebc5aa8).();
921 }
922 }
923
924 void setSamplingNotecxx . . $ setSamplingNote(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# note) // must be called from video thread!
925 {
926 if (note > 35)
927 note = 35;
928
929 samplingNotecxx . . $ samplingNote. = note;
930 samplingFinetunecxx . . $ samplingFinetune. = 0;
931 updateOutputFrequencycxx . . $ updateOutputFrequency(49f6e7a06ebc5aa8).();
932
933 drawSamplingNotecxx . . $ drawSamplingNote(49f6e7a06ebc5aa8).();
934 drawSamplingFinetunecxx . . $ drawSamplingFinetune(49f6e7a06ebc5aa8).();
935 drawSamplingFrequencycxx . . $ drawSamplingFrequency(49f6e7a06ebc5aa8).();
936 }
937
938 void handleRepeatedSamplingButtonscxx . . $ handleRepeatedSamplingButtons(49f6e7a06ebc5aa8).(void)
939 {
940 if (!mousecxx . . $ mouse..leftButtonPressedcxx . . $ mouse_t#leftButtonPressed. || mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton. == -1)
941 return;
942
943 switch (mousecxx . . $ mouse..lastSamplingButtoncxx . . $ mouse_t#lastSamplingButton.)
944 {
945 case 0:
946 {
947 if (mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter.++ >= 3)
948 {
949 mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter. = 0;
950 scrollListUpcxx . . $ scrollListUp(49f6e7a06ebc5aa8).();
951 }
952 }
953 break;
954
955 case 1:
956 {
957 if (mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter.++ >= 3)
958 {
959 mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter. = 0;
960 scrollListDowncxx . . $ scrollListDown(49f6e7a06ebc5aa8).();
961 }
962 }
963 break;
964
965 case 2:
966 {
967 if (mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter.++ >= 5)
968 {
969 mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter. = 0;
970 finetuneUpcxx . . $ finetuneUp(49f6e7a06ebc5aa8).();
971 }
972 }
973 break;
974
975 case 3:
976 {
977 if (mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter.++ >= 5)
978 {
979 mousecxx . . $ mouse..repeatCountercxx . . $ mouse_t#repeatCounter. = 0;
980 finetuneDowncxx . . $ finetuneDown(49f6e7a06ebc5aa8).();
981 }
982 }
983 break;
984
985 default: break;
986 }
987 }