sf2-json 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/sf2-json.js +62 -77
package/package.json
CHANGED
package/src/sf2-json.js
CHANGED
|
@@ -147,23 +147,7 @@ function buildWavBuffer(audioData) {
|
|
|
147
147
|
else throw new Error(`buildWavBuffer: type '${type}' non supporté (SF3 compressé).`);
|
|
148
148
|
pcm16 = normalizeBuffer(pcm16);
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
// const MIN_LOOP_SAMPLES = Math.ceil(2 * 1152 * sampleRate / RESAMPLE_RATE);
|
|
152
|
-
// if (loopLen > 0 && loopLen < MIN_LOOP_SAMPLES) {
|
|
153
|
-
// const preLoop = pcm16.slice(0, loopStart * 2);
|
|
154
|
-
// const loopData = pcm16.slice(loopStart * 2, loopEnd * 2);
|
|
155
|
-
// const postLoop = pcm16.slice(loopEnd * 2);
|
|
156
|
-
// const repeats = Math.ceil(MIN_LOOP_SAMPLES / loopLen);
|
|
157
|
-
// const loopRepeated = Buffer.concat(Array(repeats).fill(loopData));
|
|
158
|
-
// pcm16 = Buffer.concat([preLoop, loopRepeated, postLoop]);
|
|
159
|
-
// }
|
|
160
|
-
|
|
161
|
-
// const minSamples = Math.ceil(4 * 1152 * sampleRate / RESAMPLE_RATE);
|
|
162
|
-
// const minBytes = minSamples * 2;
|
|
163
|
-
// if (pcm16.byteLength < minBytes) {
|
|
164
|
-
// const pad = Buffer.alloc(minBytes - pcm16.byteLength);
|
|
165
|
-
// pcm16 = Buffer.concat([pcm16, pad]);
|
|
166
|
-
// }
|
|
150
|
+
|
|
167
151
|
|
|
168
152
|
const numChannels = 1;
|
|
169
153
|
const bitsPerSample = 16;
|
|
@@ -190,67 +174,68 @@ function buildWavBuffer(audioData) {
|
|
|
190
174
|
}
|
|
191
175
|
|
|
192
176
|
|
|
193
|
-
function extractZones(soundFont, parsed, presetHeaderIndex) {
|
|
194
|
-
const presetGeneratorsList = soundFont.getPresetGenerators(presetHeaderIndex);
|
|
195
|
-
const zones = [];
|
|
196
|
-
const seenSampleIds = new Set();
|
|
197
|
-
let globalPresetGen = null;
|
|
198
|
-
|
|
199
|
-
for (const rawGenList of presetGeneratorsList) {
|
|
200
|
-
const presetGen = createPresetGeneratorObject(rawGenList);
|
|
201
|
-
if (presetGen.instrument === undefined) {
|
|
202
|
-
globalPresetGen = presetGen;
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
177
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
function extractZones(soundFont, parsed, presetHeaderIndex) {
|
|
187
|
+
const presetGeneratorsList = soundFont.getPresetGenerators(presetHeaderIndex);
|
|
188
|
+
const zones = [];
|
|
189
|
+
let globalPresetGen = null;
|
|
190
|
+
|
|
191
|
+
for (const rawGenList of presetGeneratorsList) {
|
|
192
|
+
const presetGen = createPresetGeneratorObject(rawGenList);
|
|
193
|
+
if (presetGen.instrument === undefined) {
|
|
194
|
+
globalPresetGen = presetGen;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const instrId = presetGen.instrument;
|
|
199
|
+
const instrGeneratorsList = soundFont.getInstrumentGenerators(instrId);
|
|
200
|
+
const defaults = convertToInstrumentGeneratorParams(DefaultInstrumentZone);
|
|
201
|
+
let globalInstrGen = null;
|
|
202
|
+
|
|
203
|
+
for (const rawInstrGenList of instrGeneratorsList) {
|
|
204
|
+
const instrGen = createInstrumentGeneratorObject(rawInstrGenList);
|
|
205
|
+
|
|
206
|
+
if (instrGen.sampleID === undefined) {
|
|
207
|
+
globalInstrGen = instrGen;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const merged = { ...defaults };
|
|
212
|
+
if (globalInstrGen) Object.assign(merged, globalInstrGen);
|
|
213
|
+
Object.assign(merged, instrGen);
|
|
214
|
+
|
|
215
|
+
const applyPresetOffsets = (gen) => {
|
|
216
|
+
if (!gen) return;
|
|
217
|
+
for (const [key, val] of Object.entries(gen)) {
|
|
218
|
+
if (key === 'keyRange' || key === 'velRange' || key === 'instrument' || key === 'sampleID') continue;
|
|
219
|
+
if (key in merged && typeof val === 'number') merged[key] += val;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
applyPresetOffsets(globalPresetGen);
|
|
224
|
+
applyPresetOffsets(presetGen);
|
|
225
|
+
|
|
226
|
+
const sampleId = merged.sampleID;
|
|
227
|
+
const sampleHeader = parsed.sampleHeaders[sampleId];
|
|
228
|
+
|
|
229
|
+
if (!sampleHeader || sampleHeader.isEnd) continue;
|
|
230
|
+
|
|
231
|
+
zones.push({
|
|
232
|
+
generators: merged,
|
|
233
|
+
sampleHeader,
|
|
234
|
+
sample: parsed.samples[sampleId]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return zones;
|
|
254
239
|
}
|
|
255
240
|
|
|
256
241
|
|