sf2-json 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/package.json +52 -52
  2. package/src/sf2-json.js +36 -36
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
- {
2
- "name": "sf2-json",
3
- "version": "1.0.0",
4
- "description": "SF2 to JSON Converter for WebAudioFonts",
5
- "keywords": [
6
- "sf2",
7
- "json",
8
- "webaudiofont",
9
- "music",
10
- "sound",
11
- "soundfont",
12
- "midi",
13
- "midiplayer",
14
- "midi-player",
15
- "instruments",
16
- "sound",
17
- "soundbank"
18
- ],
19
- "homepage": "https://github.com/ZmotriN/sf2-json#readme",
20
- "bugs": {
21
- "url": "https://github.com/ZmotriN/sf2-json/issues"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/ZmotriN/sf2-json.git"
26
- },
27
- "license": "MIT",
28
- "author": "Maxime Larrivée-Roy",
29
- "type": "module",
30
- "files": [
31
- "src/",
32
- "index.js",
33
- "index.d.ts"
34
- ],
35
- "main": "index.js",
36
- "types": "index.d.ts",
37
- "exports": {
38
- ".": {
39
- "types": "./index.d.ts",
40
- "import": "./index.js"
41
- }
42
- },
43
- "scripts": {
44
- "test": "echo \"Error: no test specified\" && exit 1"
45
- },
46
- "bin": {
47
- "sf2tojson": "./bin/cli.js"
48
- },
49
- "dependencies": {
50
- "@marmooo/soundfont-parser": "^0.1.8",
51
- "ffmpeg-static": "^5.3.0"
52
- }
1
+ {
2
+ "name": "sf2-json",
3
+ "version": "1.0.1",
4
+ "description": "SF2 to JSON Converter for WebAudioFonts",
5
+ "keywords": [
6
+ "sf2",
7
+ "json",
8
+ "webaudiofont",
9
+ "music",
10
+ "sound",
11
+ "soundfont",
12
+ "midi",
13
+ "midiplayer",
14
+ "midi-player",
15
+ "instruments",
16
+ "sound",
17
+ "soundbank"
18
+ ],
19
+ "homepage": "https://github.com/WebAudioFonts/sf2-json#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/WebAudioFonts/sf2-json/issues"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/WebAudioFonts/sf2-json.git"
26
+ },
27
+ "license": "MIT",
28
+ "author": "Maxime Larrivée-Roy",
29
+ "type": "module",
30
+ "files": [
31
+ "src/",
32
+ "index.js",
33
+ "index.d.ts"
34
+ ],
35
+ "main": "index.js",
36
+ "types": "index.d.ts",
37
+ "exports": {
38
+ ".": {
39
+ "types": "./index.d.ts",
40
+ "import": "./index.js"
41
+ }
42
+ },
43
+ "scripts": {
44
+ "test": "echo \"Error: no test specified\" && exit 1"
45
+ },
46
+ "bin": {
47
+ "sf2tojson": "./bin/cli.js"
48
+ },
49
+ "dependencies": {
50
+ "@marmooo/soundfont-parser": "^0.1.8",
51
+ "ffmpeg-static": "^5.3.0"
52
+ }
53
53
  }
package/src/sf2-json.js CHANGED
@@ -69,7 +69,7 @@ function encodeOpus(wavBuffer, bitrate = 128, sampleRate = 32000) {
69
69
  '-i', 'pipe:0',
70
70
  '-ar', String(sampleRate),
71
71
  '-ac', '1',
72
- '-af', "highpass=f=100,lowpass=f=8000,firequalizer=gain='if(lt(f,100),-2,if(lt(f,400),-3,if(lt(f,3000),2,if(lt(f,8000),1,-5))))':gain_entry='entry(0,-10);entry(100,0);entry(400,-2);entry(3000,2);entry(8000,1);entry(20000,-15)'",
72
+ '-af', "highpass=f=100,lowpass=f=8000",
73
73
  '-b:a', `${bitrate}k`,
74
74
  '-c:a', 'libopus',
75
75
  '-id3v2_version', '0',
@@ -147,23 +147,23 @@ function buildWavBuffer(audioData) {
147
147
  else throw new Error(`buildWavBuffer: type '${type}' non supporté (SF3 compressé).`);
148
148
  pcm16 = normalizeBuffer(pcm16);
149
149
 
150
- const loopLen = loopEnd - loopStart;
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
+ // const loopLen = loopEnd - loopStart;
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
+ // }
167
167
 
168
168
  const numChannels = 1;
169
169
  const bitsPerSample = 16;
@@ -233,24 +233,24 @@ function extractZones(soundFont, parsed, presetHeaderIndex) {
233
233
  zones.push({ generators: merged, sampleHeader, sample: parsed.samples[sampleId] });
234
234
  }
235
235
  }
236
-
237
- const byKeyRange = new Map();
238
- for (const zone of zones) {
239
- const lo = zone.generators.keyRange?.lo ?? 0;
240
- const hi = zone.generators.keyRange?.hi ?? 127;
241
- const key = `${lo}-${hi}`;
242
- if (!byKeyRange.has(key)) {
243
- byKeyRange.set(key, zone);
244
- } else {
245
- const center = (lo + hi) / 2;
246
- const existing = byKeyRange.get(key);
247
- const existingDist = Math.abs(existing.sampleHeader.originalPitch - center);
248
- const newDist = Math.abs(zone.sampleHeader.originalPitch - center);
249
- if (newDist < existingDist) byKeyRange.set(key, zone);
250
- }
251
- }
252
-
253
- return Array.from(byKeyRange.values());
236
+ return zones;
237
+
238
+ // const byKeyRange = new Map();
239
+ // for (const zone of zones) {
240
+ // const lo = zone.generators.keyRange?.lo ?? 0;
241
+ // const hi = zone.generators.keyRange?.hi ?? 127;
242
+ // const key = `${lo}-${hi}`;
243
+ // if (!byKeyRange.has(key)) {
244
+ // byKeyRange.set(key, zone);
245
+ // } else {
246
+ // const center = (lo + hi) / 2;
247
+ // const existing = byKeyRange.get(key);
248
+ // const existingDist = Math.abs(existing.sampleHeader.originalPitch - center);
249
+ // const newDist = Math.abs(zone.sampleHeader.originalPitch - center);
250
+ // if (newDist < existingDist) byKeyRange.set(key, zone);
251
+ // }
252
+ // }
253
+ // return Array.from(byKeyRange.values());
254
254
  }
255
255
 
256
256