@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.
@@ -1426,6 +1426,8 @@ export declare class SoundfileReader {
1426
1426
  * @returns : the audio data
1427
1427
  */
1428
1428
  private static toAudioData;
1429
+ private static isWaveFile;
1430
+ private static decodeWaveFile;
1429
1431
  /**
1430
1432
  * Extract the URLs from the metadata.
1431
1433
  *
@@ -10453,6 +10453,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10453
10453
  audioBuffer: new Array(numberOfChannels).fill(null).map((v, i) => audioBuffer.getChannelData(i))
10454
10454
  };
10455
10455
  }
10456
+ static isWaveFile(buffer) {
10457
+ if (buffer.byteLength < 12) return false;
10458
+ const reader = new DataView(buffer);
10459
+ const riff = reader.getUint8(0) === 82 && reader.getUint8(1) === 73 && reader.getUint8(2) === 70 && reader.getUint8(3) === 70;
10460
+ const wave = reader.getUint8(8) === 87 && reader.getUint8(9) === 65 && reader.getUint8(10) === 86 && reader.getUint8(11) === 69;
10461
+ return riff && wave;
10462
+ }
10463
+ static decodeWaveFile(buffer) {
10464
+ const decoded = WavDecoder_default.decode(buffer);
10465
+ return {
10466
+ sampleRate: decoded.sampleRate,
10467
+ audioBuffer: decoded.channelData
10468
+ };
10469
+ }
10456
10470
  /**
10457
10471
  * Extract the URLs from the metadata.
10458
10472
  *
@@ -10464,7 +10478,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10464
10478
  const callback = (item) => {
10465
10479
  if (item.type === "soundfile") {
10466
10480
  const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
10467
- urls.filter((url) => url.trim().length > 0).forEach((url) => soundfiles[url] = null);
10481
+ urls.filter((url) => url.trim().length > 0).forEach(
10482
+ (url) => soundfiles[url] = null
10483
+ );
10468
10484
  }
10469
10485
  };
10470
10486
  FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
@@ -10485,6 +10501,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10485
10501
  `Failed to load sound file from ${url}: ${response.statusText}`
10486
10502
  );
10487
10503
  const arrayBuffer = await response.arrayBuffer();
10504
+ if (this.isWaveFile(arrayBuffer)) {
10505
+ try {
10506
+ return this.decodeWaveFile(arrayBuffer);
10507
+ } catch (error) {
10508
+ console.error(error);
10509
+ }
10510
+ }
10488
10511
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
10489
10512
  return this.toAudioData(audioBuffer);
10490
10513
  }