@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.
- package/assets/standalone/faustwasm/index.d.ts +2 -0
- package/assets/standalone/faustwasm/index.js +24 -1
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +24 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +2 -0
- package/dist/cjs-bundle/index.js +24 -1
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +24 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +2 -0
- package/dist/esm-bundle/index.js +24 -1
- package/dist/esm-bundle/index.js.map +2 -2
- package/faustwasm-soundfile-wav-samplerate.patch +77 -0
- package/package.json +1 -1
- package/src/SoundfileReader.ts +37 -3
- package/test/faustlive-wasm/faustwasm/index.d.ts +2 -0
- package/test/faustlive-wasm/faustwasm/index.js +24 -1
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/waw400 +0 -0
- package/waw400.dsp +7 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
diff --git a/src/SoundfileReader.ts b/src/SoundfileReader.ts
|
|
2
|
+
index 0cc287f..43290e7 100644
|
|
3
|
+
--- a/src/SoundfileReader.ts
|
|
4
|
+
+++ b/src/SoundfileReader.ts
|
|
5
|
+
@@ -1,4 +1,5 @@
|
|
6
|
+
import { FaustBaseWebAudioDsp } from './FaustWebAudioDsp';
|
|
7
|
+
+import WavDecoder from './WavDecoder';
|
|
8
|
+
import type {
|
|
9
|
+
AudioData,
|
|
10
|
+
FaustDspMeta,
|
|
11
|
+
@@ -21,7 +22,8 @@ class SoundfileReader {
|
|
12
|
+
const origin = loc?.origin;
|
|
13
|
+
const parent = href ? this.getParentUrl(href) : null;
|
|
14
|
+
return [href, parent, origin].filter(
|
|
15
|
+
- (value): value is string => typeof value === 'string' && value.length > 0
|
|
16
|
+
+ (value): value is string =>
|
|
17
|
+
+ typeof value === 'string' && value.length > 0
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@@ -50,6 +52,30 @@ class SoundfileReader {
|
|
22
|
+
} as AudioData;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
+ private static isWaveFile(buffer: ArrayBuffer) {
|
|
26
|
+
+ if (buffer.byteLength < 12) return false;
|
|
27
|
+
+ const reader = new DataView(buffer);
|
|
28
|
+
+ const riff =
|
|
29
|
+
+ reader.getUint8(0) === 0x52 &&
|
|
30
|
+
+ reader.getUint8(1) === 0x49 &&
|
|
31
|
+
+ reader.getUint8(2) === 0x46 &&
|
|
32
|
+
+ reader.getUint8(3) === 0x46;
|
|
33
|
+
+ const wave =
|
|
34
|
+
+ reader.getUint8(8) === 0x57 &&
|
|
35
|
+
+ reader.getUint8(9) === 0x41 &&
|
|
36
|
+
+ reader.getUint8(10) === 0x56 &&
|
|
37
|
+
+ reader.getUint8(11) === 0x45;
|
|
38
|
+
+ return riff && wave;
|
|
39
|
+
+ }
|
|
40
|
+
+
|
|
41
|
+
+ private static decodeWaveFile(buffer: ArrayBuffer): AudioData {
|
|
42
|
+
+ const decoded = WavDecoder.decode(buffer);
|
|
43
|
+
+ return {
|
|
44
|
+
+ sampleRate: decoded.sampleRate,
|
|
45
|
+
+ audioBuffer: decoded.channelData
|
|
46
|
+
+ };
|
|
47
|
+
+ }
|
|
48
|
+
+
|
|
49
|
+
/**
|
|
50
|
+
* Extract the URLs from the metadata.
|
|
51
|
+
*
|
|
52
|
+
@@ -64,8 +90,9 @@ class SoundfileReader {
|
|
53
|
+
if (item.type === 'soundfile') {
|
|
54
|
+
const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
|
|
55
|
+
// soundfiles.map[item.label] = urls;
|
|
56
|
+
- urls.filter((url) => url.trim().length > 0)
|
|
57
|
+
- .forEach((url) => (soundfiles[url] = null));
|
|
58
|
+
+ urls.filter((url) => url.trim().length > 0).forEach(
|
|
59
|
+
+ (url) => (soundfiles[url] = null)
|
|
60
|
+
+ );
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
|
|
64
|
+
@@ -90,6 +117,13 @@ class SoundfileReader {
|
|
65
|
+
);
|
|
66
|
+
// Decode the audio data
|
|
67
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
68
|
+
+ if (this.isWaveFile(arrayBuffer)) {
|
|
69
|
+
+ try {
|
|
70
|
+
+ return this.decodeWaveFile(arrayBuffer);
|
|
71
|
+
+ } catch (error) {
|
|
72
|
+
+ console.error(error);
|
|
73
|
+
+ }
|
|
74
|
+
+ }
|
|
75
|
+
const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
|
|
76
|
+
return this.toAudioData(audioBuffer);
|
|
77
|
+
}
|
package/package.json
CHANGED
package/src/SoundfileReader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FaustBaseWebAudioDsp } from './FaustWebAudioDsp';
|
|
2
|
+
import WavDecoder from './WavDecoder';
|
|
2
3
|
import type {
|
|
3
4
|
AudioData,
|
|
4
5
|
FaustDspMeta,
|
|
@@ -21,7 +22,8 @@ class SoundfileReader {
|
|
|
21
22
|
const origin = loc?.origin;
|
|
22
23
|
const parent = href ? this.getParentUrl(href) : null;
|
|
23
24
|
return [href, parent, origin].filter(
|
|
24
|
-
(value): value is string =>
|
|
25
|
+
(value): value is string =>
|
|
26
|
+
typeof value === 'string' && value.length > 0
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -50,6 +52,30 @@ class SoundfileReader {
|
|
|
50
52
|
} as AudioData;
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
private static isWaveFile(buffer: ArrayBuffer) {
|
|
56
|
+
if (buffer.byteLength < 12) return false;
|
|
57
|
+
const reader = new DataView(buffer);
|
|
58
|
+
const riff =
|
|
59
|
+
reader.getUint8(0) === 0x52 &&
|
|
60
|
+
reader.getUint8(1) === 0x49 &&
|
|
61
|
+
reader.getUint8(2) === 0x46 &&
|
|
62
|
+
reader.getUint8(3) === 0x46;
|
|
63
|
+
const wave =
|
|
64
|
+
reader.getUint8(8) === 0x57 &&
|
|
65
|
+
reader.getUint8(9) === 0x41 &&
|
|
66
|
+
reader.getUint8(10) === 0x56 &&
|
|
67
|
+
reader.getUint8(11) === 0x45;
|
|
68
|
+
return riff && wave;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private static decodeWaveFile(buffer: ArrayBuffer): AudioData {
|
|
72
|
+
const decoded = WavDecoder.decode(buffer);
|
|
73
|
+
return {
|
|
74
|
+
sampleRate: decoded.sampleRate,
|
|
75
|
+
audioBuffer: decoded.channelData
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
53
79
|
/**
|
|
54
80
|
* Extract the URLs from the metadata.
|
|
55
81
|
*
|
|
@@ -64,8 +90,9 @@ class SoundfileReader {
|
|
|
64
90
|
if (item.type === 'soundfile') {
|
|
65
91
|
const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
|
|
66
92
|
// soundfiles.map[item.label] = urls;
|
|
67
|
-
urls.filter((url) => url.trim().length > 0)
|
|
68
|
-
|
|
93
|
+
urls.filter((url) => url.trim().length > 0).forEach(
|
|
94
|
+
(url) => (soundfiles[url] = null)
|
|
95
|
+
);
|
|
69
96
|
}
|
|
70
97
|
};
|
|
71
98
|
FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
|
|
@@ -90,6 +117,13 @@ class SoundfileReader {
|
|
|
90
117
|
);
|
|
91
118
|
// Decode the audio data
|
|
92
119
|
const arrayBuffer = await response.arrayBuffer();
|
|
120
|
+
if (this.isWaveFile(arrayBuffer)) {
|
|
121
|
+
try {
|
|
122
|
+
return this.decodeWaveFile(arrayBuffer);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error(error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
93
127
|
const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
|
|
94
128
|
return this.toAudioData(audioBuffer);
|
|
95
129
|
}
|
|
@@ -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(
|
|
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
|
}
|