Debian Codegraph @

src/pt2_sample_loader.c

raw symbols SCIP
1 // for finding memory leaks in debug mode with Visual Studio cxx . . $ `<file>/src/pt2_sample_loader.c`/
2 #if defined _DEBUG && defined _MSC_VER
3 #include <crtdbg.h>
4 #endif
5
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include "pt2_textout.h"cxx . . $ `<file>/src/pt2_textout.h`/
11 #include "pt2_sampler.h"cxx . . $ `<file>/src/pt2_sampler.h`/
12 #include "pt2_audio.h"cxx . . $ `<file>/src/pt2_audio.h`/
13 #include "pt2_visuals.h"cxx . . $ `<file>/src/pt2_visuals.h`/
14 #include "pt2_helpers.h"cxx . . $ `<file>/src/pt2_helpers.h`/
15 #include "pt2_config.h"cxx . . $ `<file>/src/pt2_config.h`/
16 #include "pt2_sampling.h"cxx . . $ `<file>/src/pt2_sampling.h`/
17 #include "pt2_downsample2x.h"cxx . . $ `<file>/src/pt2_downsample2x.h`/
18 #include "pt2_askbox.h"cxx . . $ `<file>/src/pt2_askbox.h`/
19 #include "pt2_replayer.h"cxx . . $ `<file>/src/pt2_replayer.h`/
20
21 enumcxx . . $ $anonymous_type_ac33f78ff90134a5_0#
22 {
23 SAMPLETYPE_RAWcxx . . $ SAMPLETYPE_RAW.,
24 SAMPLETYPE_IFFcxx . . $ SAMPLETYPE_IFF.,
25 SAMPLETYPE_AIFFcxx . . $ SAMPLETYPE_AIFF.,
26 SAMPLETYPE_WAVcxx . . $ SAMPLETYPE_WAV.,
27 SAMPLETYPE_FLACcxx . . $ SAMPLETYPE_FLAC.
28 };
29
30 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadRAWSamplecxx . . $ loadRAWSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s);
31 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadIFFSamplecxx . . $ loadIFFSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s);
32 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadAIFFSamplecxx . . $ loadAIFFSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s);
33 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadWAVSamplecxx . . $ loadWAVSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s);
34 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadFLACSamplecxx . . $ loadFLACSample(85a5b89df4a007d2).(FILEcxx . . $ FILE# *f, uint32_tcxx . . $ uint32_t# filesize, moduleSample_tcxx . . $ moduleSample_t# *s);
35
36 static void setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(moduleSample_tcxx . . $ moduleSample_t# *s, char *entryName, const char *ext)
37 {
38 int32_tcxx . . $ int32_t# extLen = (int32_tcxx . . $ int32_t#)strlencxx . . $ strlen(751346f8406fd082).(ext);
39 int32_tcxx . . $ int32_t# nameLen = (int32_tcxx . . $ int32_t#)strlencxx . . $ strlen(751346f8406fd082).(entryName);
40
41 // don't include file extension (if present)
42 if (nameLen >= extLen && !_strnicmpcxx . . $ `src/pt2_header.h:35:9`!(&entryName[nameLen-extLen], ext, extLen))
43 nameLen -= extLen;
44
45 // copy over filename to sample name first
46 for (int32_tcxx . . $ int32_t# i = 0; i < 21; i++)
47 s->textcxx . . $ moduleSample_t#text.[i] = (i < nameLen) ? (char)entryName[i] : '\0';
48
49 s->textcxx . . $ moduleSample_t#text.[21] = '\0';
50 s->textcxx . . $ moduleSample_t#text.[22] = '\0';
51 }
52
53 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! loadSamplecxx . . $ loadSample(14223ed414283e68).(UNICHARcxx . . $ UNICHAR# *fileName, char *entryName)
54 {
55 if (editorcxx . . $ editor..sampleZerocxx . . $ editor_t#sampleZero.)
56 {
57 statusNotSampleZerocxx . . $ statusNotSampleZero(49f6e7a06ebc5aa8).();
58 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
59 }
60
61 FILEcxx . . $ FILE# *f = UNICHAR_FOPENcxx . . $ `src/pt2_unicode.h:35:9`!(fileName, "rb");
62 if (f == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
63 {
64 displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("FILE I/O ERROR !");
65 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
66 }
67
68 uint32_tcxx . . $ uint32_t# filesize;
69 fseekcxx . . $ fseek(543fae30d249f6b1).(f, 0, SEEK_ENDcxx . . $ `<external>/232824719582829767/stdio.h:112:9`!);
70 filesize = (uint32_tcxx . . $ uint32_t#)ftellcxx . . $ ftell(1dcafcd8ef4c6e6c).(f);
71 rewindcxx . . $ rewind(8d4262d45fc644ab).(f);
72
73 // defaults to RAW if no format was identified
74 uint8_tcxx . . $ uint8_t# sampleType = SAMPLETYPE_RAWcxx . . $ SAMPLETYPE_RAW.;
75
76 // first, check heades before we eventually load as RAW
77 if (filesize > 16)
78 {
79 uint32_tcxx . . $ uint32_t# ID;
80 freadcxx . . $ fread(738fc8ac1d711e58).(&ID, 4, 1, f);
81
82 if (ID == 0x43614C66) // "fLaC" (XXX: weak detection)
83 {
84 sampleType = SAMPLETYPE_FLACcxx . . $ SAMPLETYPE_FLAC.;
85 }
86 else if (ID == 0x46464952) // "RIFF" (WAV)
87 {
88 fseekcxx . . $ fseek(543fae30d249f6b1).(f, 4, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!);
89 freadcxx . . $ fread(738fc8ac1d711e58).(&ID, 4, 1, f);
90
91 if (ID == 0x45564157) // "WAVE"
92 sampleType = SAMPLETYPE_WAVcxx . . $ SAMPLETYPE_WAV.;
93 }
94 else if (ID == 0x4D524F46) // "FORM" (IFF/AIFF)
95 {
96 fseekcxx . . $ fseek(543fae30d249f6b1).(f, 4, SEEK_CURcxx . . $ `<external>/232824719582829767/stdio.h:111:9`!);
97 freadcxx . . $ fread(738fc8ac1d711e58).(&ID, 4, 1, f);
98
99 // check if it's an Amiga IFF sample
100 if (ID == 0x58565338 || ID == 0x56533631) // "8SVX" (normal) and "16SV" (FT2 sample)
101 {
102 sampleType = SAMPLETYPE_IFFcxx . . $ SAMPLETYPE_IFF.;
103 }
104
105 // check if it's an AIFF sample
106 else if (ID == 0x46464941) // "AIFF"
107 {
108 sampleType = SAMPLETYPE_AIFFcxx . . $ SAMPLETYPE_AIFF.;
109 }
110
111 else if (ID == 0x43464941) // "AIFC" (compressed AIFF)
112 {
113 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
114 displayErrorMsgcxx . . $ displayErrorMsg(85c52e162fed56f9).("UNSUPPORTED AIFF!");
115 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
116 }
117 }
118 }
119
120 moduleSample_tcxx . . $ moduleSample_t# *s = &songcxx . . $ song.->samplescxx . . $ module_t#samples.[editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.];
121
122 // we're not ready to load the sample (error message is shown in the loaders)
123
124 rewindcxx . . $ rewind(8d4262d45fc644ab).(f);
125
126 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! result = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
127 switch (sampleType)
128 {
129 case SAMPLETYPE_RAWcxx . . $ SAMPLETYPE_RAW.:
130 setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(s, entryName, ".raw");
131 result = loadRAWSamplecxx . . $ loadRAWSample(85a5b89df4a007d2).(f, filesize, s);
132 break;
133
134 case SAMPLETYPE_IFFcxx . . $ SAMPLETYPE_IFF.:
135 setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(s, entryName, ".iff");
136 result = loadIFFSamplecxx . . $ loadIFFSample(85a5b89df4a007d2).(f, filesize, s);
137 break;
138
139 case SAMPLETYPE_AIFFcxx . . $ SAMPLETYPE_AIFF.:
140 setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(s, entryName, ".aiff");
141 result = loadAIFFSamplecxx . . $ loadAIFFSample(85a5b89df4a007d2).(f, filesize, s);
142 break;
143
144 case SAMPLETYPE_WAVcxx . . $ SAMPLETYPE_WAV.:
145 setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(s, entryName, ".wav");
146 result = loadWAVSamplecxx . . $ loadWAVSample(85a5b89df4a007d2).(f, filesize, s);
147 break;
148
149 case SAMPLETYPE_FLACcxx . . $ SAMPLETYPE_FLAC.:
150 setSampleTextFromFilenamecxx . . $ setSampleTextFromFilename(abb902985d64b45).(s, entryName, ".flac");
151 result = loadFLACSamplecxx . . $ loadFLACSample(85a5b89df4a007d2).(f, filesize, s);
152 break;
153
154 default: break;
155 }
156
157 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
158
159 if (result == truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!)
160 {
161 // sample load was successful
162
163 if (s->lengthcxx . . $ moduleSample_t#length. > configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
164 s->lengthcxx . . $ moduleSample_t#length. = configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.;
165
166 if (s->loopStartcxx . . $ moduleSample_t#loopStart.+s->loopLengthcxx . . $ moduleSample_t#loopLength. > s->lengthcxx . . $ moduleSample_t#length.)
167 {
168 s->loopStartcxx . . $ moduleSample_t#loopStart. = 0;
169 s->loopLengthcxx . . $ moduleSample_t#loopLength. = 2;
170 }
171
172 // zero out rest of sample (if not full length)
173 if (s->lengthcxx . . $ moduleSample_t#length. < configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength.)
174 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&songcxx . . $ song.->sampleDatacxx . . $ module_t#sampleData.[s->offsetcxx . . $ moduleSample_t#offset. + s->lengthcxx . . $ moduleSample_t#length.], 0, configcxx . . $ config..maxSampleLengthcxx . . $ config_t#maxSampleLength. - s->lengthcxx . . $ moduleSample_t#length.);
175
176 editorcxx . . $ editor..sampleZerocxx . . $ editor_t#sampleZero. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
177 editorcxx . . $ editor..samplePoscxx . . $ editor_t#samplePos. = 0;
178
179 fixSampleBeepcxx . . $ fixSampleBeep(60146f4515acbace).(s);
180 fillSampleRedoBuffercxx . . $ fillSampleRedoBuffer(4af4fd0e2b26c4ac).(editorcxx . . $ editor..currSamplecxx . . $ editor_t#currSample.);
181
182 if (uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown.)
183 {
184 removeSamplingBoxcxx . . $ removeSamplingBox(49f6e7a06ebc5aa8).();
185 uicxx . . $ ui..samplingBoxShowncxx . . $ ui_t#samplingBoxShown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
186 }
187
188 updateCurrSamplecxx . . $ updateCurrSample(49f6e7a06ebc5aa8).();
189 updateWindowTitlecxx . . $ updateWindowTitle(b45ddcbc8423892c).(MOD_IS_MODIFIEDcxx . . $ MOD_IS_MODIFIED.);
190 }
191
192 return result;
193 }