| 1 | #cxx . . $ `<file>/src/smploaders/pt2_load_aiff.c`/include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> |
| 5 | #include <string.h> |
| 6 | #include <math.h> |
| 7 | #include "../pt2_header.h"cxx . . $ `<file>/src/pt2_header.h`/ |
| 8 | #include "../pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/ |
| 9 | #include "../pt2_structs.h"cxx . . $ `<file>/src/pt2_structs.h`/ |
| 10 | #include "../pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/ |
| 11 | #include "../pt2_visuals.h"cxx . . $ `<file>/src/pt2_visuals.h`/ |
| 12 | #include "../pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/ |
| 13 | #include "../pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/ |
| 14 | #include "../pt2_askbox.h"cxx . . $ `<file>/src/pt2_askbox.h`/ |
| 15 | #include "../pt2_downsample2x.h"cxx . . $ `<file>/src/pt2_downsample2x.h`/ |
| 16 | #include "../pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/ |
| 17 | |
| 18 | static uint32_tcxx . . $ uint32_t# getAIFFSampleRatecxx . . $ getAIFFSampleRate(df34ef224e8b6259).(uint8_tcxx . . $ uint8_t# *in) |
| 19 | { |
| 20 | /* 80-bit IEEE-754 to unsigned 32-bit integer (rounded). |
| 21 | ** Sign bit is ignored. |
| 22 | */ |
| 23 | |
| 24 | #define EXP_BIAScxx . . $ `src/smploaders/pt2_load_aiff.c:24:9`! 16383 |
| 25 | |
| 26 | const uint16_tcxx . . $ uint16_t# exp15 = ((in[0] & 0x7F) << 8) | in[1]; |
| 27 | const uint64_tcxx . . $ uint64_t# mantissaBits = *(uint64_tcxx . . $ uint64_t# *)&in[2]; |
| 28 | const uint64_tcxx . . $ uint64_t# mantissa63 = SWAP64cxx . . $ `src/pt2_helpers.h:20:9`!(mantissaBits) & INT64_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:113:10`!; |
| 29 | |
| 30 | double dExp = exp15 - EXP_BIAScxx . . $ `src/smploaders/pt2_load_aiff.c:24:9`!; |
| 31 | double dMantissa = mantissa63 / ((double)INT64_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:113:10`!+1.0); |
| 32 | |
| 33 | double dResult = (1.0 + dMantissa) * exp2cxx . . $ exp2(447c67c6676f75c3).(dExp); |
| 34 | return (uint32_tcxx . . $ uint32_t#)roundcxx . . $ round(447c67c6676f75c3).(dResult); |
| 35 | } |
| 36 | |
| 37 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadAIFFSamplecxx . . $ loadAIFFSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s) |
| 38 | { |
| 39 | uint8_tcxx . . $ uint8_t# sampleRateBytes[10]; |
| 40 | uint16_tcxx . . $ uint16_t# bitDepth, numChannels; |
| 41 | uint32_tcxx . . $ uint32_t# offset, sampleRate; |
| 42 | |
| 43 | // zero out chunk pointers and lengths |
| 44 | uint32_tcxx . . $ uint32_t# commPtr = 0; uint32_tcxx . . $ uint32_t# commLen = 0; |
| 45 | uint32_tcxx . . $ uint32_t# ssndPtr = 0; uint32_tcxx . . $ uint32_t# ssndLen = 0; |
| 46 | |
| 47 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! unsigned8bit = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 48 | |
| 49 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 12, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 50 | while (!feofcxx . . $ feof(89bc1efcdac0ca22).(f) && (uint32_tcxx . . $ uint32_t#)ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f) < filesize-12) |
| 51 | { |
| 52 | uint32_tcxx . . $ uint32_t# blockName, blockSize; |
| 53 | |
| 54 | freadcxx . . $ fread(738fc8ac1d711e58).(&blockName, 4, 1, f); if (feofcxx . . $ feof(89bc1efcdac0ca22).(f)) break; |
| 55 | freadcxx . . $ fread(738fc8ac1d711e58).(&blockSize, 4, 1, f); if (feofcxx . . $ feof(89bc1efcdac0ca22).(f)) break; |
| 56 | |
| 57 | blockName = SWAP32cxx . . $ `src/pt2_helpers.h:12:9`!(blockName); |
| 58 | blockSize = SWAP32cxx . . $ `src/pt2_helpers.h:12:9`!(blockSize); |
| 59 | |
| 60 | switch (blockName) |
| 61 | { |
| 62 | case 0x434F4D4D: // "COMM" |
| 63 | { |
| 64 | commPtr = ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f); |
| 65 | commLen = blockSize; |
| 66 | } |
| 67 | break; |
| 68 | |
| 69 | case 0x53534E44: // "SSND" |
| 70 | { |
| 71 | ssndPtr = ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f); |
| 72 | ssndLen = blockSize; |
| 73 | } |
| 74 | break; |
| 75 | |
| 76 | default: break; |
| 77 | } |
| 78 | |
| 79 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, blockSize + (blockSize & 1), SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!); |
| 80 | } |
| 81 | |
| 82 | if (commPtr == 0 || commLen < 18 || ssndPtr == 0) |
| 83 | { |
| 84 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("NOT A VALID AIFF!"); |
| 85 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 86 | } |
| 87 | |
| 88 | // kludge for some really strange AIFFs |
| 89 | if (ssndLen == 0) |
| 90 | ssndLen = filesize - ssndPtr; |
| 91 | |
| 92 | if (ssndPtr+ssndLen > (uint32_tcxx . . $ uint32_t#)filesize) |
| 93 | ssndLen = filesize - ssndPtr; |
| 94 | |
| 95 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, commPtr, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 96 | freadcxx . . $ fread(738fc8ac1d711e58).(&numChannels, 2, 1, f); numChannels = SWAP16cxx . . $ `src/pt2_helpers.h:6:9`!(numChannels); |
| 97 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 4, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!); |
| 98 | freadcxx . . $ fread(738fc8ac1d711e58).(&bitDepth, 2, 1, f); bitDepth = SWAP16cxx . . $ `src/pt2_helpers.h:6:9`!(bitDepth); |
| 99 | freadcxx . . $ fread(738fc8ac1d711e58).(sampleRateBytes, 1, 10, f); |
| 100 | |
| 101 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 4 + 2 + 1, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!); |
| 102 | |
| 103 | if (numChannels != 1 && numChannels != 2) // sample type |
| 104 | { |
| 105 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED AIFF!"); |
| 106 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 107 | } |
| 108 | |
| 109 | if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32) |
| 110 | { |
| 111 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED AIFF!"); |
| 112 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 113 | } |
| 114 | |
| 115 | // read compression type (if present) |
| 116 | if (commLen > 18) |
| 117 | { |
| 118 | char compType[4]; |
| 119 | freadcxx . . $ fread(738fc8ac1d711e58).(&compType, 1, 4, f); |
| 120 | if (memcmpcxx . . $ memcmp(36f949851efa3055).(compType, "NONE", 4)) |
| 121 | { |
| 122 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED AIFF!"); |
| 123 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | sampleRate = getAIFFSampleRatecxx . . $ getAIFFSampleRate(df34ef224e8b6259).(sampleRateBytes); |
| 128 | |
| 129 | // sample data chunk |
| 130 | |
| 131 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, ssndPtr, SEEK_SETcxx . . $ `<external>/232824719582829767/stdio.h:110:9`!); |
| 132 | |
| 133 | freadcxx . . $ fread(738fc8ac1d711e58).(&offset, 4, 1, f); |
| 134 | if (offset > 0) |
| 135 | { |
| 136 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED AIFF!"); |
| 137 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 138 | } |
| 139 | |
| 140 | fseekcxx . . $ fseek(543fae30d249f6b1).(f, 4, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!); |
| 141 | |
| 142 | ssndLen -= 8; // don't include offset and blockSize datas |
| 143 | |
| 144 | int32_tcxx . . $ int32_t# sampleLength = ssndLen; |
| 145 | if (sampleLength == 0) |
| 146 | { |
| 147 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("NOT A VALID AIFF!"); |
| 148 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 149 | } |
| 150 | |
| 151 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! downSample = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 152 | if (sampleRate > 22050 && !configcxx . . $ config..noDownsampleOnSmpLoadcxx . . $ config_t#noDownsampleOnSmpLoad.) |
| 153 | { |
| 154 | if (askBoxcxx . . $ askBox(7371ee129cebb502).(ASKBOX_DOWNSAMPLEcxx . . $ ASKBOX_DOWNSAMPLE., "DOWNSAMPLE ?")) |
| 155 | downSample = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 156 | } |
| 157 | |
| 158 | int8_tcxx . . $ int8_t# *smpDataPtr = &songcxx . . $ song.->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset.]; |
| 159 | |
| 160 | if (bitDepth == 8) // 8-BIT INTEGER SAMPLE |
| 161 | { |
| 162 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4) |
| 163 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4; |
| 164 | |
| 165 | int8_tcxx . . $ int8_t# *audioDataS8 = (int8_tcxx . . $ int8_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sampleLength * sizeof (int8_tcxx . . $ int8_t#)); |
| 166 | if (audioDataS8 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 167 | { |
| 168 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 169 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 170 | } |
| 171 | |
| 172 | // read sample data |
| 173 | if (freadcxx . . $ fread(738fc8ac1d711e58).(audioDataS8, 1, sampleLength, f) != (size_t)sampleLength) |
| 174 | { |
| 175 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS8); |
| 176 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("I/O ERROR !"); |
| 177 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 178 | } |
| 179 | |
| 180 | if (unsigned8bit) |
| 181 | { |
| 182 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 183 | audioDataS8[i] ^= 0x80; |
| 184 | } |
| 185 | |
| 186 | // convert from stereo to mono (if needed) |
| 187 | if (numChannels == 2) |
| 188 | { |
| 189 | sampleLength >>= 1; |
| 190 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) // add right channel to left channel |
| 191 | audioDataS8[i] = (audioDataS8[(i * 2) + 0] + audioDataS8[(i * 2) + 1]) >> 1; |
| 192 | } |
| 193 | |
| 194 | // 2x downsampling |
| 195 | if (downSample) |
| 196 | { |
| 197 | downsample2x8Bitcxx . . $ downsample2x8Bit(9b8781d28ee69655).(audioDataS8, sampleLength); |
| 198 | sampleLength >>= 1; |
| 199 | } |
| 200 | |
| 201 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 202 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 203 | |
| 204 | turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).(); |
| 205 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 206 | smpDataPtr[i] = audioDataS8[i]; |
| 207 | |
| 208 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS8); |
| 209 | } |
| 210 | else if (bitDepth == 16) // 16-BIT INTEGER SAMPLE |
| 211 | { |
| 212 | sampleLength >>= 1; |
| 213 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4) |
| 214 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4; |
| 215 | |
| 216 | int16_tcxx . . $ int16_t# *audioDataS16 = (int16_tcxx . . $ int16_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sampleLength * sizeof (int16_tcxx . . $ int16_t#)); |
| 217 | if (audioDataS16 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 218 | { |
| 219 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 220 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 221 | } |
| 222 | |
| 223 | // read sample data |
| 224 | if (freadcxx . . $ fread(738fc8ac1d711e58).(audioDataS16, 2, sampleLength, f) != (size_t)sampleLength) |
| 225 | { |
| 226 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS16); |
| 227 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("I/O ERROR !"); |
| 228 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 229 | } |
| 230 | |
| 231 | // fix endianness |
| 232 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 233 | audioDataS16[i] = SWAP16cxx . . $ `src/pt2_helpers.h:6:9`!(audioDataS16[i]); |
| 234 | |
| 235 | // convert from stereo to mono (if needed) |
| 236 | if (numChannels == 2) |
| 237 | { |
| 238 | sampleLength >>= 1; |
| 239 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) // add right channel to left channel |
| 240 | audioDataS16[i] = (audioDataS16[(i << 1) + 0] + audioDataS16[(i << 1) + 1]) >> 1; |
| 241 | } |
| 242 | |
| 243 | // 2x downsampling |
| 244 | if (downSample) |
| 245 | { |
| 246 | downsample2x16Bitcxx . . $ downsample2x16Bit(6f0a599713eb5608).(audioDataS16, sampleLength); |
| 247 | sampleLength >>= 1; |
| 248 | } |
| 249 | |
| 250 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 251 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 252 | |
| 253 | double dAmp = 1.0; |
| 254 | if (downSample) // we already normalized |
| 255 | { |
| 256 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / (double)INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!; |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | const double dPeak = get16BitPeakcxx . . $ get16BitPeak(5bbf7f3ea503fca5).(audioDataS16, sampleLength); |
| 261 | if (dPeak > 0.0) |
| 262 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / dPeak; |
| 263 | } |
| 264 | |
| 265 | turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).(); |
| 266 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 267 | { |
| 268 | int32_tcxx . . $ int32_t# smp32 = (int32_tcxx . . $ int32_t#)roundcxx . . $ round(447c67c6676f75c3).(audioDataS16[i] * dAmp); |
| 269 | ASSERTcxx . . $ `src/pt2_header.h:25:9`!(smp32 >= -128 && smp32 <= 127); // shouldn't happen according to dAmp (but just in case) |
| 270 | smpDataPtr[i] = (int8_tcxx . . $ int8_t#)smp32; |
| 271 | } |
| 272 | |
| 273 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS16); |
| 274 | } |
| 275 | else if (bitDepth == 24) // 24-BIT INTEGER SAMPLE |
| 276 | { |
| 277 | sampleLength /= 3; |
| 278 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4) |
| 279 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4; |
| 280 | |
| 281 | int32_tcxx . . $ int32_t# *audioDataS32 = (int32_tcxx . . $ int32_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sampleLength * sizeof (int32_tcxx . . $ int32_t#)); |
| 282 | if (audioDataS32 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 283 | { |
| 284 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 285 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 286 | } |
| 287 | |
| 288 | // read sample data |
| 289 | if (freadcxx . . $ fread(738fc8ac1d711e58).(&audioDataS32[sampleLength >> 2], 3, sampleLength, f) != (size_t)sampleLength) |
| 290 | { |
| 291 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS32); |
| 292 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("I/O ERROR !"); |
| 293 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 294 | } |
| 295 | |
| 296 | // convert to 32-bit |
| 297 | uint8_tcxx . . $ uint8_t# *audioDataU8 = (uint8_tcxx . . $ uint8_t# *)audioDataS32 + sampleLength; |
| 298 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 299 | { |
| 300 | audioDataS32[i] = (audioDataU8[0] << 24) | (audioDataU8[1] << 16) | (audioDataU8[2] << 8); |
| 301 | audioDataU8 += 3; |
| 302 | } |
| 303 | |
| 304 | // convert from stereo to mono (if needed) |
| 305 | if (numChannels == 2) |
| 306 | { |
| 307 | sampleLength >>= 1; |
| 308 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) // add right channel to left channel |
| 309 | { |
| 310 | int64_tcxx . . $ int64_t# smp = ((int64_tcxx . . $ int64_t#)audioDataS32[(i << 1) + 0] + audioDataS32[(i << 1) + 1]) >> 1; |
| 311 | audioDataS32[i] = (int32_tcxx . . $ int32_t#)smp; |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | // 2x downsampling |
| 316 | if (downSample) |
| 317 | { |
| 318 | downsample2x32Bitcxx . . $ downsample2x32Bit(fdfc7b0a9f333dff).(audioDataS32, sampleLength); |
| 319 | sampleLength >>= 1; |
| 320 | } |
| 321 | |
| 322 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 323 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 324 | |
| 325 | double dAmp = 1.0; |
| 326 | if (downSample) // we already normalized |
| 327 | { |
| 328 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / (double)INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!; |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | const double dPeak = get32BitPeakcxx . . $ get32BitPeak(7ca14e0a6faf8061).(audioDataS32, sampleLength); |
| 333 | if (dPeak > 0.0) |
| 334 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / dPeak; |
| 335 | } |
| 336 | |
| 337 | turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).(); |
| 338 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 339 | { |
| 340 | int32_tcxx . . $ int32_t# smp32 = (int32_tcxx . . $ int32_t#)roundcxx . . $ round(447c67c6676f75c3).(audioDataS32[i] * dAmp); |
| 341 | smpDataPtr[i] = (int8_tcxx . . $ int8_t#)smp32; |
| 342 | } |
| 343 | |
| 344 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS32); |
| 345 | } |
| 346 | else if (bitDepth == 32) // 32-BIT INTEGER SAMPLE |
| 347 | { |
| 348 | sampleLength >>= 2; |
| 349 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4) |
| 350 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.*4; |
| 351 | |
| 352 | int32_tcxx . . $ int32_t# *audioDataS32 = (int32_tcxx . . $ int32_t# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sampleLength * sizeof (int32_tcxx . . $ int32_t#)); |
| 353 | if (audioDataS32 == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 354 | { |
| 355 | statusOutOfMemorycxx . . $ statusOutOfMemory(49f6e7a06ebc5aa8).(); |
| 356 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 357 | } |
| 358 | |
| 359 | // read sample data |
| 360 | if (freadcxx . . $ fread(738fc8ac1d711e58).(audioDataS32, 4, sampleLength, f) != (size_t)sampleLength) |
| 361 | { |
| 362 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS32); |
| 363 | displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("I/O ERROR !"); |
| 364 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 365 | } |
| 366 | |
| 367 | // fix endianness |
| 368 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 369 | audioDataS32[i] = SWAP32cxx . . $ `src/pt2_helpers.h:12:9`!(audioDataS32[i]); |
| 370 | |
| 371 | // convert from stereo to mono (if needed) |
| 372 | if (numChannels == 2) |
| 373 | { |
| 374 | sampleLength >>= 1; |
| 375 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) // add right channel to left channel |
| 376 | { |
| 377 | int64_tcxx . . $ int64_t# smp = ((int64_tcxx . . $ int64_t#)audioDataS32[(i << 1) + 0] + audioDataS32[(i << 1) + 1]) >> 1; |
| 378 | audioDataS32[i] = (int32_tcxx . . $ int32_t#)smp; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // 2x downsampling |
| 383 | if (downSample) |
| 384 | { |
| 385 | downsample2x32Bitcxx . . $ downsample2x32Bit(fdfc7b0a9f333dff).(audioDataS32, sampleLength); |
| 386 | sampleLength >>= 1; |
| 387 | } |
| 388 | |
| 389 | if (sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 390 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 391 | |
| 392 | double dAmp = 1.0; |
| 393 | if (downSample) // we already normalized |
| 394 | { |
| 395 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / (double)INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!; |
| 396 | } |
| 397 | else |
| 398 | { |
| 399 | const double dPeak = get32BitPeakcxx . . $ get32BitPeak(7ca14e0a6faf8061).(audioDataS32, sampleLength); |
| 400 | if (dPeak > 0.0) |
| 401 | dAmp = INT8_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:110:10`! / dPeak; |
| 402 | } |
| 403 | |
| 404 | turnOffVoicescxx . . $ turnOffVoices(49f6e7a06ebc5aa8).(); |
| 405 | for (int32_tcxx . . $ int32_t# i = 0; i < sampleLength; i++) |
| 406 | { |
| 407 | int32_tcxx . . $ int32_t# smp32 = (int32_tcxx . . $ int32_t#)roundcxx . . $ round(447c67c6676f75c3).(audioDataS32[i] * dAmp); |
| 408 | smpDataPtr[i] = (int8_tcxx . . $ int8_t#)smp32; |
| 409 | } |
| 410 | |
| 411 | freecxx . . $ free(5d22bdacc48458e8).(audioDataS32); |
| 412 | } |
| 413 | |
| 414 | if (sampleLength & 1) |
| 415 | { |
| 416 | if (++sampleLength > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.) |
| 417 | sampleLength = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.; |
| 418 | else |
| 419 | smpDataPtr[sampleLength-1] = 0; |
| 420 | } |
| 421 | |
| 422 | s->lengthcxx . . $ moduleSample_t#length. = sampleLength; |
| 423 | s->fineTunecxx . . $ moduleSample_t#fineTune. = 0; |
| 424 | s->volumecxx . . $ moduleSample_t#volume. = 64; |
| 425 | s->loopStartcxx . . $ moduleSample_t#loopStart. = 0; |
| 426 | s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2; |
| 427 | |
| 428 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 429 | } |