spessasynth_core 4.0.20 → 4.0.22
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/README.md +15 -16
- package/dist/index.d.ts +1009 -983
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -206,16 +206,16 @@ It allows you to:
|
|
|
206
206
|
### Short example: MIDI to wav converter
|
|
207
207
|
|
|
208
208
|
```ts
|
|
209
|
-
import * as fs from "
|
|
209
|
+
import * as fs from "fs/promises";
|
|
210
210
|
import {
|
|
211
211
|
audioToWav,
|
|
212
212
|
BasicMIDI,
|
|
213
213
|
SoundBankLoader,
|
|
214
214
|
SpessaSynthProcessor,
|
|
215
215
|
SpessaSynthSequencer
|
|
216
|
-
} from "
|
|
216
|
+
} from "spessasynth_core";
|
|
217
217
|
|
|
218
|
-
//
|
|
218
|
+
// Process arguments
|
|
219
219
|
const args = process.argv.slice(2);
|
|
220
220
|
if (args.length !== 3) {
|
|
221
221
|
console.info(
|
|
@@ -223,8 +223,8 @@ if (args.length !== 3) {
|
|
|
223
223
|
);
|
|
224
224
|
process.exit();
|
|
225
225
|
}
|
|
226
|
-
const sf = fs.
|
|
227
|
-
const mid = fs.
|
|
226
|
+
const sf = await fs.readFile(args[0]);
|
|
227
|
+
const mid = await fs.readFile(args[1]);
|
|
228
228
|
const midi = BasicMIDI.fromArrayBuffer(mid.buffer);
|
|
229
229
|
const sampleRate = 44100;
|
|
230
230
|
const sampleCount = Math.ceil(44100 * (midi.duration + 2));
|
|
@@ -232,8 +232,9 @@ const synth = new SpessaSynthProcessor(sampleRate, {
|
|
|
232
232
|
enableEventSystem: false,
|
|
233
233
|
enableEffects: false
|
|
234
234
|
});
|
|
235
|
-
synth.soundBankManager.
|
|
236
|
-
SoundBankLoader.fromArrayBuffer(sf.buffer)
|
|
235
|
+
synth.soundBankManager.addSoundBank(
|
|
236
|
+
SoundBankLoader.fromArrayBuffer(sf.buffer),
|
|
237
|
+
"main"
|
|
237
238
|
);
|
|
238
239
|
await synth.processorInitialized;
|
|
239
240
|
const seq = new SpessaSynthSequencer(synth);
|
|
@@ -244,20 +245,20 @@ const outLeft = new Float32Array(sampleCount);
|
|
|
244
245
|
const outRight = new Float32Array(sampleCount);
|
|
245
246
|
const start = performance.now();
|
|
246
247
|
let filledSamples = 0;
|
|
247
|
-
//
|
|
248
|
+
// Note: buffer size is recommended to be very small, as this is the interval between modulator updates and LFO updates
|
|
248
249
|
const BUFFER_SIZE = 128;
|
|
249
250
|
let i = 0;
|
|
250
|
-
const durationRounded = Math.floor(seq.midiData
|
|
251
|
+
const durationRounded = Math.floor(seq.midiData!.duration * 100) / 100;
|
|
251
252
|
const outputArray = [outLeft, outRight];
|
|
252
253
|
while (filledSamples < sampleCount) {
|
|
253
|
-
//
|
|
254
|
+
// Process sequencer
|
|
254
255
|
seq.processTick();
|
|
255
|
-
//
|
|
256
|
+
// Render
|
|
256
257
|
const bufferSize = Math.min(BUFFER_SIZE, sampleCount - filledSamples);
|
|
257
258
|
synth.renderAudio(outputArray, [], [], filledSamples, bufferSize);
|
|
258
259
|
filledSamples += bufferSize;
|
|
259
260
|
i++;
|
|
260
|
-
//
|
|
261
|
+
// Log progress
|
|
261
262
|
if (i % 100 === 0) {
|
|
262
263
|
console.info(
|
|
263
264
|
"Rendered",
|
|
@@ -274,10 +275,8 @@ console.info(
|
|
|
274
275
|
`ms (${Math.floor(((midi.duration * 1000) / rendered) * 100) / 100}x)`
|
|
275
276
|
);
|
|
276
277
|
const wave = audioToWav([outLeft, outRight], sampleRate);
|
|
277
|
-
fs.writeFile(args[2], new Uint8Array(wave)
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
|
|
278
|
+
await fs.writeFile(args[2], new Uint8Array(wave));
|
|
279
|
+
console.info(`File written to ${args[2]}`);
|
|
281
280
|
```
|
|
282
281
|
|
|
283
282
|
### Building
|