| 1 | // for finding memory leaks in debug mode with Visual Studio cxx . . $ `<file>/src/pt2_pat2smp.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_config.h"cxx . . $ `<file>/src/pt2_config.h`/ |
| 12 | #include "pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/ |
| 13 | #include "pt2_visuals.h"cxx . . $ `<file>/src/pt2_visuals.h`/ |
| 14 | #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/ |
| 15 | #include "pt2_sampler.h"cxx . . $ `<file>/src/pt2_sampler.h`/ |
| 16 | #include "pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/ |
| 17 | #include "pt2_tables.h"cxx . . $ `<file>/src/pt2_tables.h`/ |
| 18 | #include "pt2_downsample2x.h"cxx . . $ `<file>/src/pt2_downsample2x.h`/ |
| 19 | #include "pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/ |
| 20 | |
| 21 | static const char *noteStrcxx . . $ noteStr.[12] = |
| 22 | { |
| 23 | "c-", "c#", "d-", "d#", "e-", "f-", "f#", "g-", "g#", "a-", "a#", "b-" |
| 24 | }; |
| 25 | |
| 26 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! pat2SmpEndReachedcxx . . $ pat2SmpEndReached.; |
| 27 | static uint8_tcxx . . $ uint8_t# pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 4, pat2SmpNotecxx . . $ pat2SmpNote. = 33; // A-3 finetune +4 (default, max safe frequency) |
| 28 | static uint8_tcxx . . $ uint8_t# pat2SmpStartRowcxx . . $ pat2SmpStartRow. = 0, pat2SmpRowscxx . . $ pat2SmpRows. = 32; |
| 29 | static int32_tcxx . . $ int32_t# pat2SmpPoscxx . . $ pat2SmpPos.; |
| 30 | static float *fMixBufferLcxx . . $ fMixBufferL., *fMixBufferRcxx . . $ fMixBufferR., *fPat2SmpBufcxx . . $ fPat2SmpBuf.; |
| 31 | static double dPat2SmpFreqcxx . . $ dPat2SmpFreq., dSecondscxx . . $ dSeconds.; |
| 32 | |
| 33 | static void pat2SmpOutputAudiocxx . . $ pat2SmpOutputAudio(918ebd27a9ddbad3).(int32_tcxx . . $ int32_t# numSamples, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! outputEnable) |
| 34 | { |
| 35 | int32_tcxx . . $ int32_t# samplesTodo = numSamples; |
| 36 | |
| 37 | if (outputEnable && pat2SmpPoscxx . . $ pat2SmpPos.+samplesTodo > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 38 | samplesTodo = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. - pat2SmpPoscxx . . $ pat2SmpPos.; |
| 39 | |
| 40 | paulaGenerateSamplescxx . . $ paulaGenerateSamples(ae8270d942ffb491).(fMixBufferLcxx . . $ fMixBufferL., fMixBufferRcxx . . $ fMixBufferR., samplesTodo*2); // 2x oversampling |
| 41 | |
| 42 | if (outputEnable) |
| 43 | { |
| 44 | for (int32_tcxx . . $ int32_t# i = 0; i < samplesTodo; i++) |
| 45 | { |
| 46 | // 2x downsampling |
| 47 | float fL = downsample2x_Lcxx . . $ downsample2x_L(d59a45cd3bfd2eda).(fMixBufferLcxx . . $ fMixBufferL.[(i << 1) + 0], fMixBufferLcxx . . $ fMixBufferL.[(i << 1) + 1]); |
| 48 | float fR = downsample2x_Rcxx . . $ downsample2x_R(d59a45cd3bfd2eda).(fMixBufferRcxx . . $ fMixBufferR.[(i << 1) + 0], fMixBufferRcxx . . $ fMixBufferR.[(i << 1) + 1]); |
| 49 | |
| 50 | fPat2SmpBufcxx . . $ fPat2SmpBuf.[pat2SmpPoscxx . . $ pat2SmpPos.+i] = (fL + fR) * 0.5f; // stereo -> mono, normalized to -128..127 later |
| 51 | } |
| 52 | |
| 53 | pat2SmpPoscxx . . $ pat2SmpPos. += samplesTodo; |
| 54 | if (pat2SmpPoscxx . . $ pat2SmpPos. >= configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 55 | pat2SmpEndReachedcxx . . $ pat2SmpEndReached. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void pat2SmpDrawNotecxx . . $ pat2SmpDrawNote(49f6e7a06ebc5aa8).(void) |
| 60 | { |
| 61 | fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(165, 51, FONT_CHAR_Wcxx . . $ `src/pt2_header.h:70:9`!*3, FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]); |
| 62 | textOutcxx . . $ textOut(ecc378a7b29cfb5a).(165, 51, noteNames1cxx . . $ noteNames1.[2+pat2SmpNotecxx . . $ pat2SmpNote.], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 63 | } |
| 64 | |
| 65 | void pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(void) |
| 66 | { |
| 67 | fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(173, 62, FONT_CHAR_Wcxx . . $ `src/pt2_header.h:70:9`!*2, FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]); |
| 68 | textOutcxx . . $ textOut(ecc378a7b29cfb5a).(173, 62, ftuneStrTabcxx . . $ ftuneStrTab.[pat2SmpFinetunecxx . . $ pat2SmpFinetune.], videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 69 | } |
| 70 | |
| 71 | void pat2SmpDrawFrequencycxx . . $ pat2SmpDrawFrequency(49f6e7a06ebc5aa8).(void) |
| 72 | { |
| 73 | const int32_tcxx . . $ int32_t# maxTextWidth = 19 * FONT_CHAR_Wcxx . . $ `src/pt2_header.h:70:9`!; |
| 74 | fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(164, 74, maxTextWidth, FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]); |
| 75 | |
| 76 | if (dPat2SmpFreqcxx . . $ dPat2SmpFreq.*2.0 < PAL_PAULA_MAX_HZcxx . . $ `src/pt2_paula.h:17:9`!) |
| 77 | { |
| 78 | textOutcxx . . $ textOut(ecc378a7b29cfb5a).(164, 74, "TOO LOW!", videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | char textBuf[32]; |
| 83 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(textBuf, "%dHz (%.1f secs)", (int32_tcxx . . $ int32_t#)(dPat2SmpFreqcxx . . $ dPat2SmpFreq. + 0.5), dSecondscxx . . $ dSeconds.); |
| 84 | textOutcxx . . $ textOut(ecc378a7b29cfb5a).(164, 74, textBuf, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | void pat2SmpDrawStartRowcxx . . $ pat2SmpDrawStartRow(49f6e7a06ebc5aa8).(void) |
| 89 | { |
| 90 | fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(276, 51, FONT_CHAR_Wcxx . . $ `src/pt2_header.h:70:9`!*2, FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]); |
| 91 | printTwoDecimalscxx . . $ printTwoDecimals(eda338842932bf2b).(276, 51, pat2SmpStartRowcxx . . $ pat2SmpStartRow., videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 92 | } |
| 93 | |
| 94 | void pat2SmpDrawRowscxx . . $ pat2SmpDrawRows(49f6e7a06ebc5aa8).(void) |
| 95 | { |
| 96 | fillRectcxx . . $ fillRect(6fb2c7d311165c4f).(276, 62, FONT_CHAR_Wcxx . . $ `src/pt2_header.h:70:9`!*2, FONT_CHAR_Hcxx . . $ `src/pt2_header.h:71:9`!, videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENBKGcxx . . $ PAL_GENBKG.]); |
| 97 | printTwoDecimalscxx . . $ printTwoDecimals(eda338842932bf2b).(276, 62, pat2SmpRowscxx . . $ pat2SmpRows., videocxx . . $ video..palettecxx . . $ video_t#palette.[PAL_GENTXTcxx . . $ PAL_GENTXT.]); |
| 98 | } |
| 99 | |
| 100 | void pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(void) |
| 101 | { |
| 102 | if (pat2SmpFinetunecxx . . $ pat2SmpFinetune. > 15) |
| 103 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 15; |
| 104 | |
| 105 | if (pat2SmpNotecxx . . $ pat2SmpNote. > 35) |
| 106 | pat2SmpNotecxx . . $ pat2SmpNote. = 35; |
| 107 | |
| 108 | dPat2SmpFreqcxx . . $ dPat2SmpFreq. = PAULA_PAL_CLKcxx . . $ `src/pt2_paula.h:14:9`! / (double)periodTablecxx . . $ periodTable.[(pat2SmpFinetunecxx . . $ pat2SmpFinetune. * 37) + pat2SmpNotecxx . . $ pat2SmpNote.]; |
| 109 | if (dPat2SmpFreqcxx . . $ dPat2SmpFreq. > PAL_PAULA_MAX_HZcxx . . $ `src/pt2_paula.h:17:9`!) |
| 110 | dPat2SmpFreqcxx . . $ dPat2SmpFreq. = PAL_PAULA_MAX_HZcxx . . $ `src/pt2_paula.h:17:9`!; |
| 111 | |
| 112 | dSecondscxx . . $ dSeconds. = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. / dPat2SmpFreqcxx . . $ dPat2SmpFreq.; |
| 113 | pat2SmpDrawFrequencycxx . . $ pat2SmpDrawFrequency(49f6e7a06ebc5aa8).(); |
| 114 | } |
| 115 | |
| 116 | void pat2SmpNoteUpcxx . . $ pat2SmpNoteUp(49f6e7a06ebc5aa8).(void) |
| 117 | { |
| 118 | if (pat2SmpNotecxx . . $ pat2SmpNote. < 35) |
| 119 | { |
| 120 | pat2SmpNotecxx . . $ pat2SmpNote.++; |
| 121 | pat2SmpDrawNotecxx . . $ pat2SmpDrawNote(49f6e7a06ebc5aa8).(); |
| 122 | |
| 123 | if (pat2SmpNotecxx . . $ pat2SmpNote. == 35 && pat2SmpFinetunecxx . . $ pat2SmpFinetune. < 8) // high-limit to B-3 finetune 0 |
| 124 | { |
| 125 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 0; |
| 126 | pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(); |
| 127 | } |
| 128 | |
| 129 | pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void pat2SmpNoteDowncxx . . $ pat2SmpNoteDown(49f6e7a06ebc5aa8).(void) |
| 134 | { |
| 135 | if (pat2SmpNotecxx . . $ pat2SmpNote. > 23) |
| 136 | { |
| 137 | pat2SmpNotecxx . . $ pat2SmpNote.--; |
| 138 | pat2SmpDrawNotecxx . . $ pat2SmpDrawNote(49f6e7a06ebc5aa8).(); |
| 139 | |
| 140 | if (pat2SmpNotecxx . . $ pat2SmpNote. == 23 && pat2SmpFinetunecxx . . $ pat2SmpFinetune. > 7) // low-limit to B-2 finetune 0 |
| 141 | { |
| 142 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 0; |
| 143 | pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(); |
| 144 | } |
| 145 | |
| 146 | pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void pat2SmpSetFinetunecxx . . $ pat2SmpSetFinetune(ac50b47256ae7414).(uint8_tcxx . . $ uint8_t# finetune) |
| 151 | { |
| 152 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = finetune & 0x0F; |
| 153 | pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(); |
| 154 | pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(); |
| 155 | } |
| 156 | |
| 157 | void pat2SmpFinetuneUpcxx . . $ pat2SmpFinetuneUp(49f6e7a06ebc5aa8).(void) |
| 158 | { |
| 159 | if ((pat2SmpFinetunecxx . . $ pat2SmpFinetune. & 0xF) != 7) |
| 160 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = (pat2SmpFinetunecxx . . $ pat2SmpFinetune. + 1) & 0xF; |
| 161 | |
| 162 | if (pat2SmpNotecxx . . $ pat2SmpNote. == 35 && pat2SmpFinetunecxx . . $ pat2SmpFinetune. < 8) // for B-3, high-limit finetune to 0 |
| 163 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 0; |
| 164 | |
| 165 | pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(); |
| 166 | pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(); |
| 167 | } |
| 168 | |
| 169 | void pat2SmpFinetuneDowncxx . . $ pat2SmpFinetuneDown(49f6e7a06ebc5aa8).(void) |
| 170 | { |
| 171 | if ((pat2SmpFinetunecxx . . $ pat2SmpFinetune. & 0xF) != 8) |
| 172 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = (pat2SmpFinetunecxx . . $ pat2SmpFinetune. - 1) & 0xF; |
| 173 | |
| 174 | if (pat2SmpNotecxx . . $ pat2SmpNote. == 23 && pat2SmpFinetunecxx . . $ pat2SmpFinetune. > 7) // for B-2, low-limit finetune to 0 |
| 175 | pat2SmpFinetunecxx . . $ pat2SmpFinetune. = 0; |
| 176 | |
| 177 | pat2SmpDrawFinetunecxx . . $ pat2SmpDrawFinetune(49f6e7a06ebc5aa8).(); |
| 178 | pat2SmpCalculateFreqcxx . . $ pat2SmpCalculateFreq(49f6e7a06ebc5aa8).(); |
| 179 | } |
| 180 | |
| 181 | void pat2SmpStartRowUpcxx . . $ pat2SmpStartRowUp(49f6e7a06ebc5aa8).(void) |
| 182 | { |
| 183 | if (pat2SmpStartRowcxx . . $ pat2SmpStartRow.+pat2SmpRowscxx . . $ pat2SmpRows. < 64) |
| 184 | { |
| 185 | pat2SmpStartRowcxx . . $ pat2SmpStartRow.++; |
| 186 | pat2SmpDrawStartRowcxx . . $ pat2SmpDrawStartRow(49f6e7a06ebc5aa8).(); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void pat2SmpStartRowDowncxx . . $ pat2SmpStartRowDown(49f6e7a06ebc5aa8).(void) |
| 191 | { |
| 192 | if (pat2SmpStartRowcxx . . $ pat2SmpStartRow. > 0) |
| 193 | { |
| 194 | pat2SmpStartRowcxx . . $ pat2SmpStartRow.--; |
| 195 | pat2SmpDrawStartRowcxx . . $ pat2SmpDrawStartRow(49f6e7a06ebc5aa8).(); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | void pat2SmpRowsUpcxx . . $ pat2SmpRowsUp(49f6e7a06ebc5aa8).(void) |
| 200 | { |
| 201 | if (pat2SmpStartRowcxx . . $ pat2SmpStartRow.+pat2SmpRowscxx . . $ pat2SmpRows. < 64) |
| 202 | { |
| 203 | pat2SmpRowscxx . . $ pat2SmpRows.++; |
| 204 | pat2SmpDrawRowscxx . . $ pat2SmpDrawRows(49f6e7a06ebc5aa8).(); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | void pat2SmpRowsDowncxx . . $ pat2SmpRowsDown(49f6e7a06ebc5aa8).(void) |
| 209 | { |
| 210 | if (pat2SmpRowscxx . . $ pat2SmpRows. > 1) |
| 211 | { |
| 212 | pat2SmpRowscxx . . $ pat2SmpRows.--; |
| 213 | pat2SmpDrawRowscxx . . $ pat2SmpDrawRows(49f6e7a06ebc5aa8).(); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void pat2SmpRendercxx . . $ pat2SmpRender(49f6e7a06ebc5aa8).(void) |
| 218 | { |
| 219 | if (editorcxx . . $ editor..sampleZerocxx . . $ editor_t#sampleZero.) |
| 220 | { |
| 221 | statusNotSampleZerocxx . . $ statusNotSampleZero(49f6e7a06ebc5aa8).(); |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | fPat2SmpBufcxx . . $ fPat2SmpBuf. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. * sizeof (float)); |
| 226 | if (fPat2SmpBufcxx . . $ fPat2SmpBuf. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 227 | { |
| 228 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | const double dAudioFrequency = dPat2SmpFreqcxx . . $ dPat2SmpFreq. * 2.0; // *2 for oversampling |
| 233 | int32_tcxx . . $ int32_t# maxSamplesPerTick = (int32_tcxx . . $ int32_t#)ceil(dAudioFrequency / (MIN_BPMcxx . . $ `src/pt2_replayer.h:7:9`! / 2.5)) + 1; |
| 234 | |
| 235 | fMixBufferLcxx . . $ fMixBufferL. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(maxSamplesPerTick * sizeof (float)); |
| 236 | fMixBufferRcxx . . $ fMixBufferR. = (float *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(maxSamplesPerTick * sizeof (float)); |
| 237 | |
| 238 | if (fMixBufferLcxx . . $ fMixBufferL. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || fMixBufferRcxx . . $ fMixBufferR. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 239 | { |
| 240 | freecxx . . $ free(5d22bdacc48458e8).(fPat2SmpBufcxx . . $ fPat2SmpBuf.); |
| 241 | |
| 242 | if (fMixBufferLcxx . . $ fMixBufferL. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) freecxx . . $ free(5d22bdacc48458e8).(fMixBufferLcxx . . $ fMixBufferL.); |
| 243 | if (fMixBufferRcxx . . $ fMixBufferR. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) freecxx . . $ free(5d22bdacc48458e8).(fMixBufferRcxx . . $ fMixBufferR.); |
| 244 | |
| 245 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | // wait for main audio callback to catch PAT2SMP flag |
| 250 | editorcxx . . $ editor..pat2SmpOngoingcxx . . $ editor_t#pat2SmpOngoing. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 251 | while (audiocxx . . $ audio..callbackOngoingcxx . . $ audio_t#callbackOngoing.) |
| 252 | SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(5); |
| 253 | |
| 254 | const int8_tcxx . . $ int8_t# oldRow = editorcxx . . $ editor..songPlayingcxx . . $ editor_t#songPlaying. ? 0 : songcxx . . $ song.->currRowcxx . . $ module_t#currRow.; |
| 255 | |
| 256 | // do some prep work |
| 257 | generateBpmTablecxx . . $ generateBpmTable(e7c9417f9c54f86f).(dPat2SmpFreqcxx . . $ dPat2SmpFreq., editorcxx . . $ editor..timingModecxx . . $ editor_t#timingMode. == TEMPO_MODE_VBLANKcxx . . $ TEMPO_MODE_VBLANK.); |
| 258 | paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(dPat2SmpFreqcxx . . $ dPat2SmpFreq.*2.0, MODEL_A1200cxx . . $ MODEL_A1200.); |
| 259 | paulaDisableFilterscxx . . $ paulaDisableFilters(49f6e7a06ebc5aa8).(); |
| 260 | storeTempVariablescxx . . $ storeTempVariables(49f6e7a06ebc5aa8).(); |
| 261 | restartSongcxx . . $ restartSong(49f6e7a06ebc5aa8).(); // this also updates BPM (samples per tick) with the PAT2SMP audio output rate |
| 262 | clearDownsample2xStatescxx . . $ clearDownsample2xStates(49f6e7a06ebc5aa8).(); |
| 263 | |
| 264 | songcxx . . $ song.->currRowcxx . . $ module_t#currRow. = songcxx . . $ song.->rowcxx . . $ module_t#row. = 0; |
| 265 | pat2SmpPoscxx . . $ pat2SmpPos. = 0; |
| 266 | |
| 267 | uint64_tcxx . . $ uint64_t# samplesToMixFrac = 0; |
| 268 | |
| 269 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! lastRow = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 270 | |
| 271 | pat2SmpEndReachedcxx . . $ pat2SmpEndReached. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 272 | while (!pat2SmpEndReachedcxx . . $ pat2SmpEndReached. && editorcxx . . $ editor..songPlayingcxx . . $ editor_t#songPlaying.) |
| 273 | { |
| 274 | /* Handle replayer tick (also sets audio.samplesPerTickInt and audio.samplesPerTickFrac). |
| 275 | ** Returns false on end of song. |
| 276 | */ |
| 277 | if (!tickReplayercxx . . $ tickReplayer(c9857a73d68e59ba).()) |
| 278 | lastRow = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 279 | |
| 280 | if (songcxx . . $ song.->rowcxx . . $ module_t#row. > pat2SmpStartRowcxx . . $ pat2SmpStartRow.+pat2SmpRowscxx . . $ pat2SmpRows.) |
| 281 | break; // we rendered as many rows as requested (don't write this tick to output) |
| 282 | |
| 283 | uint32_tcxx . . $ uint32_t# samplesToMix = audiocxx . . $ audio..samplesPerTickIntcxx . . $ audio_t#samplesPerTickInt.; |
| 284 | |
| 285 | samplesToMixFrac += audiocxx . . $ audio..samplesPerTickFraccxx . . $ audio_t#samplesPerTickFrac.; |
| 286 | if (samplesToMixFrac >= BPM_FRAC_SCALEcxx . . $ `src/pt2_audio.h:13:9`!) |
| 287 | { |
| 288 | samplesToMixFrac &= BPM_FRAC_MASKcxx . . $ `src/pt2_audio.h:14:9`!; |
| 289 | samplesToMix++; |
| 290 | } |
| 291 | |
| 292 | if (lastRow && songcxx . . $ song.->tickcxx . . $ module_t#tick. == songcxx . . $ song.->speedcxx . . $ module_t#speed.-1) |
| 293 | pat2SmpEndReachedcxx . . $ pat2SmpEndReached. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 294 | |
| 295 | const boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! outputEnableFlag = lastRow || songcxx . . $ song.->rowcxx . . $ module_t#row. > pat2SmpStartRowcxx . . $ pat2SmpStartRow.; |
| 296 | pat2SmpOutputAudiocxx . . $ pat2SmpOutputAudio(918ebd27a9ddbad3).(samplesToMix, outputEnableFlag); |
| 297 | } |
| 298 | editorcxx . . $ editor..pat2SmpOngoingcxx . . $ editor_t#pat2SmpOngoing. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 299 | |
| 300 | freecxx . . $ free(5d22bdacc48458e8).(fMixBufferLcxx . . $ fMixBufferL.); |
| 301 | freecxx . . $ free(5d22bdacc48458e8).(fMixBufferRcxx . . $ fMixBufferR.); |
| 302 | |
| 303 | songcxx . . $ song.->currRowcxx . . $ module_t#currRow. = songcxx . . $ song.->rowcxx . . $ module_t#row. = oldRow; // set back old row |
| 304 | |
| 305 | // set back audio configurations |
| 306 | 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.; |
| 307 | paulaSetupcxx . . $ paulaSetup(29649c4b077a0f6).(paulaMixFrequency, audiocxx . . $ audio..amigaModelcxx . . $ audio_t#amigaModel.); |
| 308 | generateBpmTablecxx . . $ generateBpmTable(e7c9417f9c54f86f).(audiocxx . . $ audio..outputRatecxx . . $ audio_t#outputRate., editorcxx . . $ editor..timingModecxx . . $ editor_t#timingMode. == TEMPO_MODE_VBLANKcxx . . $ TEMPO_MODE_VBLANK.); |
| 309 | clearDownsample2xStatescxx . . $ clearDownsample2xStates(49f6e7a06ebc5aa8).(); |
| 310 | resetSongcxx . . $ resetSong(49f6e7a06ebc5aa8).(); // this also updates BPM (samples per tick) with the tracker's audio output rate |
| 311 | |
| 312 | moduleSample_tcxx . . $ moduleSample_t# *s = &songcxx . . $ song.->samplescxx . . $ module_t#samples.[editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.]; |
| 313 | |
| 314 | // normalize and quantize to 8-bit |
| 315 | |
| 316 | const float fPeak = getFloatPeakcxx . . $ getFloatPeak(5c3cfcb0fda3feba).(fPat2SmpBufcxx . . $ fPat2SmpBuf., pat2SmpPoscxx . . $ pat2SmpPos.); |
| 317 | |
| 318 | float fAmp = 0.0f; |
| 319 | if (fPeak > 0.0f) |
| 320 | fAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / fPeak; |
| 321 | |
| 322 | int8_tcxx . . $ int8_t# *smpPtr = &songcxx . . $ song.->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset.]; |
| 323 | for (int32_tcxx . . $ int32_t# i = 0; i < pat2SmpPoscxx . . $ pat2SmpPos.; i++) |
| 324 | { |
| 325 | const int32_tcxx . . $ int32_t# smp = (const int32_tcxx . . $ int32_t#)roundfcxx . . $ roundf(fbcf3211dfe1bfd1).(fPat2SmpBufcxx . . $ fPat2SmpBuf.[i] * fAmp); |
| 326 | ASSERTcxx . . $ `src/pt2_header.h:25:9`!(smp >= -128 && smp <= 127); // shouldn't happen according to fAmp (but just in case) |
| 327 | smpPtr[i] = (int8_tcxx . . $ int8_t#)smp; |
| 328 | } |
| 329 | |
| 330 | freecxx . . $ free(5d22bdacc48458e8).(fPat2SmpBufcxx . . $ fPat2SmpBuf.); |
| 331 | |
| 332 | int32_tcxx . . $ int32_t# newSampleLength = (pat2SmpPoscxx . . $ pat2SmpPos. + 1) & ~1; |
| 333 | if (newSampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 334 | newSampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 335 | |
| 336 | // clear the rest of the sample (if not full) |
| 337 | if (newSampleLength < configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 338 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&songcxx . . $ song.->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset.+newSampleLength], 0, configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. - newSampleLength); |
| 339 | |
| 340 | // set sample attributes |
| 341 | |
| 342 | s->lengthcxx . . $ moduleSample_t#length. = newSampleLength; |
| 343 | s->volumecxx . . $ moduleSample_t#volume. = 64; |
| 344 | s->fineTunecxx . . $ moduleSample_t#fineTune. = pat2SmpFinetunecxx . . $ pat2SmpFinetune.; |
| 345 | s->loopStartcxx . . $ moduleSample_t#loopStart. = 0; |
| 346 | s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2; |
| 347 | |
| 348 | // set sample name |
| 349 | |
| 350 | const int32_tcxx . . $ int32_t# note = pat2SmpNotecxx . . $ pat2SmpNote. % 12; |
| 351 | const int32_tcxx . . $ int32_t# octave = (pat2SmpNotecxx . . $ pat2SmpNote. / 12) + 1; |
| 352 | |
| 353 | if (pat2SmpFinetunecxx . . $ pat2SmpFinetune. == 0) |
| 354 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(s->textcxx . . $ moduleSample_t#text., "pat2smp(%s%d ftune: 0)", noteStrcxx . . $ noteStr.[note], octave); |
| 355 | else if (pat2SmpFinetunecxx . . $ pat2SmpFinetune. < 8) |
| 356 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(s->textcxx . . $ moduleSample_t#text., "pat2smp(%s%d ftune:+%d)", noteStrcxx . . $ noteStr.[note], octave, pat2SmpFinetunecxx . . $ pat2SmpFinetune.); |
| 357 | else |
| 358 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(s->textcxx . . $ moduleSample_t#text., "pat2smp(%s%d ftune:-%d)", noteStrcxx . . $ noteStr.[note], octave, (pat2SmpFinetunecxx . . $ pat2SmpFinetune.^7)-7); |
| 359 | |
| 360 | fixSampleBeepcxx . . $ fixSampleBeep(60146f4515acbace).(s); |
| 361 | updateCurrSamplecxx . . $ updateCurrSample(49f6e7a06ebc5aa8).(); |
| 362 | |
| 363 | editorcxx . . $ editor..samplePoscxx . . $ editor_t#samplePos. = 0; // reset Edit Op. sample position |
| 364 | updateWindowTitlecxx . . $ updateWindowTitle(b45ddcbc8423892c).(MOD_IS_MODIFIEDcxx . . $ MOD_IS_MODIFIED.); |
| 365 | } |