aboutsummaryrefslogtreecommitdiffstats
path: root/static/wav.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/wav.js')
-rw-r--r--static/wav.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/static/wav.js b/static/wav.js
index ada6302..b83fae2 100644
--- a/static/wav.js
+++ b/static/wav.js
@@ -34,6 +34,14 @@ export function encodeWav(samples, rate) {
return buf;
}
+// The loudest sample of a 16-bit WAV from encodeWav, to tell silence.
+export function peak(wav) {
+ const v = new DataView(wav);
+ let p = 0;
+ for (let i = 44; i + 1 < wav.byteLength; i += 2) p = Math.max(p, Math.abs(v.getInt16(i, true)));
+ return p;
+}
+
export async function toWav(blob, rate = 16000) {
const ctx = new AudioContext();
try {