@grame/faustwasm 0.16.2 → 0.16.4

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 (43) hide show
  1. package/assets/standalone/faustwasm/index.d.ts +2 -0
  2. package/assets/standalone/faustwasm/index.js +25 -2
  3. package/assets/standalone/faustwasm/index.js.map +2 -2
  4. package/dist/cjs/index.d.ts +2 -0
  5. package/dist/cjs/index.js +25 -2
  6. package/dist/cjs/index.js.map +2 -2
  7. package/dist/cjs-bundle/index.d.ts +2 -0
  8. package/dist/cjs-bundle/index.js +32 -5
  9. package/dist/cjs-bundle/index.js.map +2 -2
  10. package/dist/esm/index.d.ts +2 -0
  11. package/dist/esm/index.js +25 -2
  12. package/dist/esm/index.js.map +2 -2
  13. package/dist/esm-bundle/index.d.ts +2 -0
  14. package/dist/esm-bundle/index.js +32 -5
  15. package/dist/esm-bundle/index.js.map +2 -2
  16. package/faustwasm-soundfile-wav-samplerate.patch +77 -0
  17. package/libfaust-wasm/libfaust-wasm.js +1 -1
  18. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  19. package/package.json +6 -3
  20. package/src/SoundfileReader.ts +37 -3
  21. package/src/instantiateFaustModuleFromFile.ts +2 -1
  22. package/test/faustlive-wasm/faustwasm/index.d.ts +2 -0
  23. package/test/faustlive-wasm/faustwasm/index.js +25 -2
  24. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  25. package/test/organ/create-node.js +253 -0
  26. package/test/organ/dsp-meta.json +132 -0
  27. package/test/organ/dsp-module.wasm +0 -0
  28. package/test/organ/faust-pwa.js +344 -0
  29. package/test/organ/faust-ui/index.css +442 -0
  30. package/test/organ/faust-ui/index.css.map +1 -0
  31. package/test/organ/faust-ui/index.d.ts +1 -0
  32. package/test/organ/faust-ui/index.js +3756 -0
  33. package/test/organ/faust-ui/index.js.map +1 -0
  34. package/test/organ/faustwasm/index.d.ts +1824 -0
  35. package/test/organ/faustwasm/index.js +6178 -0
  36. package/test/organ/faustwasm/index.js.map +7 -0
  37. package/test/organ/icon.png +0 -0
  38. package/test/organ/index.html +76 -0
  39. package/test/organ/index.js +69 -0
  40. package/test/organ/manifest.json +17 -0
  41. package/test/organ/service-worker.js +165 -0
  42. package/waw400 +0 -0
  43. package/waw400.dsp +7 -0
@@ -1419,6 +1419,8 @@ export declare class SoundfileReader {
1419
1419
  * @returns : the audio data
1420
1420
  */
1421
1421
  private static toAudioData;
1422
+ private static isWaveFile;
1423
+ private static decodeWaveFile;
1422
1424
  /**
1423
1425
  * Extract the URLs from the metadata.
1424
1426
  *
@@ -12,7 +12,7 @@ var instantiateFaustModuleFromFile = async (jsFile, dataFile = jsFile.replace(/c
12
12
  let FaustModule;
13
13
  let dataBinary;
14
14
  let wasmBinary;
15
- const jsCodeHead = /var (.+) = \(/;
15
+ const jsCodeHead = /var (\w+)\s*=\s*\(/;
16
16
  if (typeof window === "object") {
17
17
  let jsCode = await (await fetch(jsFile)).text();
18
18
  jsCode = `${jsCode}
@@ -4619,6 +4619,20 @@ var SoundfileReader = class {
4619
4619
  audioBuffer: new Array(numberOfChannels).fill(null).map((v, i) => audioBuffer.getChannelData(i))
4620
4620
  };
4621
4621
  }
4622
+ static isWaveFile(buffer) {
4623
+ if (buffer.byteLength < 12) return false;
4624
+ const reader = new DataView(buffer);
4625
+ const riff = reader.getUint8(0) === 82 && reader.getUint8(1) === 73 && reader.getUint8(2) === 70 && reader.getUint8(3) === 70;
4626
+ const wave = reader.getUint8(8) === 87 && reader.getUint8(9) === 65 && reader.getUint8(10) === 86 && reader.getUint8(11) === 69;
4627
+ return riff && wave;
4628
+ }
4629
+ static decodeWaveFile(buffer) {
4630
+ const decoded = WavDecoder_default.decode(buffer);
4631
+ return {
4632
+ sampleRate: decoded.sampleRate,
4633
+ audioBuffer: decoded.channelData
4634
+ };
4635
+ }
4622
4636
  /**
4623
4637
  * Extract the URLs from the metadata.
4624
4638
  *
@@ -4630,7 +4644,9 @@ var SoundfileReader = class {
4630
4644
  const callback = (item) => {
4631
4645
  if (item.type === "soundfile") {
4632
4646
  const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
4633
- urls.filter((url) => url.trim().length > 0).forEach((url) => soundfiles[url] = null);
4647
+ urls.filter((url) => url.trim().length > 0).forEach(
4648
+ (url) => soundfiles[url] = null
4649
+ );
4634
4650
  }
4635
4651
  };
4636
4652
  FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
@@ -4651,6 +4667,13 @@ var SoundfileReader = class {
4651
4667
  `Failed to load sound file from ${url}: ${response.statusText}`
4652
4668
  );
4653
4669
  const arrayBuffer = await response.arrayBuffer();
4670
+ if (this.isWaveFile(arrayBuffer)) {
4671
+ try {
4672
+ return this.decodeWaveFile(arrayBuffer);
4673
+ } catch (error) {
4674
+ console.error(error);
4675
+ }
4676
+ }
4654
4677
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
4655
4678
  return this.toAudioData(audioBuffer);
4656
4679
  }