@grame/faustwasm 0.16.2 → 0.16.3

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.
@@ -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
  *
package/dist/cjs/index.js CHANGED
@@ -4648,6 +4648,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4648
4648
  audioBuffer: new Array(numberOfChannels).fill(null).map((v, i) => audioBuffer.getChannelData(i))
4649
4649
  };
4650
4650
  }
4651
+ static isWaveFile(buffer) {
4652
+ if (buffer.byteLength < 12) return false;
4653
+ const reader = new DataView(buffer);
4654
+ const riff = reader.getUint8(0) === 82 && reader.getUint8(1) === 73 && reader.getUint8(2) === 70 && reader.getUint8(3) === 70;
4655
+ const wave = reader.getUint8(8) === 87 && reader.getUint8(9) === 65 && reader.getUint8(10) === 86 && reader.getUint8(11) === 69;
4656
+ return riff && wave;
4657
+ }
4658
+ static decodeWaveFile(buffer) {
4659
+ const decoded = WavDecoder_default.decode(buffer);
4660
+ return {
4661
+ sampleRate: decoded.sampleRate,
4662
+ audioBuffer: decoded.channelData
4663
+ };
4664
+ }
4651
4665
  /**
4652
4666
  * Extract the URLs from the metadata.
4653
4667
  *
@@ -4659,7 +4673,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4659
4673
  const callback = (item) => {
4660
4674
  if (item.type === "soundfile") {
4661
4675
  const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
4662
- urls.filter((url) => url.trim().length > 0).forEach((url) => soundfiles[url] = null);
4676
+ urls.filter((url) => url.trim().length > 0).forEach(
4677
+ (url) => soundfiles[url] = null
4678
+ );
4663
4679
  }
4664
4680
  };
4665
4681
  FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
@@ -4680,6 +4696,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4680
4696
  `Failed to load sound file from ${url}: ${response.statusText}`
4681
4697
  );
4682
4698
  const arrayBuffer = await response.arrayBuffer();
4699
+ if (this.isWaveFile(arrayBuffer)) {
4700
+ try {
4701
+ return this.decodeWaveFile(arrayBuffer);
4702
+ } catch (error) {
4703
+ console.error(error);
4704
+ }
4705
+ }
4683
4706
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
4684
4707
  return this.toAudioData(audioBuffer);
4685
4708
  }