@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
  *
@@ -10407,6 +10407,20 @@ var SoundfileReader = class {
10407
10407
  audioBuffer: new Array(numberOfChannels).fill(null).map((v, i) => audioBuffer.getChannelData(i))
10408
10408
  };
10409
10409
  }
10410
+ static isWaveFile(buffer) {
10411
+ if (buffer.byteLength < 12) return false;
10412
+ const reader = new DataView(buffer);
10413
+ const riff = reader.getUint8(0) === 82 && reader.getUint8(1) === 73 && reader.getUint8(2) === 70 && reader.getUint8(3) === 70;
10414
+ const wave = reader.getUint8(8) === 87 && reader.getUint8(9) === 65 && reader.getUint8(10) === 86 && reader.getUint8(11) === 69;
10415
+ return riff && wave;
10416
+ }
10417
+ static decodeWaveFile(buffer) {
10418
+ const decoded = WavDecoder_default.decode(buffer);
10419
+ return {
10420
+ sampleRate: decoded.sampleRate,
10421
+ audioBuffer: decoded.channelData
10422
+ };
10423
+ }
10410
10424
  /**
10411
10425
  * Extract the URLs from the metadata.
10412
10426
  *
@@ -10418,7 +10432,9 @@ var SoundfileReader = class {
10418
10432
  const callback = (item) => {
10419
10433
  if (item.type === "soundfile") {
10420
10434
  const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
10421
- urls.filter((url) => url.trim().length > 0).forEach((url) => soundfiles[url] = null);
10435
+ urls.filter((url) => url.trim().length > 0).forEach(
10436
+ (url) => soundfiles[url] = null
10437
+ );
10422
10438
  }
10423
10439
  };
10424
10440
  FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
@@ -10439,6 +10455,13 @@ var SoundfileReader = class {
10439
10455
  `Failed to load sound file from ${url}: ${response.statusText}`
10440
10456
  );
10441
10457
  const arrayBuffer = await response.arrayBuffer();
10458
+ if (this.isWaveFile(arrayBuffer)) {
10459
+ try {
10460
+ return this.decodeWaveFile(arrayBuffer);
10461
+ } catch (error) {
10462
+ console.error(error);
10463
+ }
10464
+ }
10442
10465
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
10443
10466
  return this.toAudioData(audioBuffer);
10444
10467
  }