mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
PR improvements
This commit is contained in:
parent
70c021fdf3
commit
a2d5d39ec4
@ -17,31 +17,25 @@
|
|||||||
.then((response) => response.arrayBuffer())
|
.then((response) => response.arrayBuffer())
|
||||||
.then((bytes) => WebAssembly.instantiate(bytes, { m: Math }))
|
.then((bytes) => WebAssembly.instantiate(bytes, { m: Math }))
|
||||||
.then(({ instance }) => {
|
.then(({ instance }) => {
|
||||||
const context = new AudioContext();
|
const context = new AudioContext({ sampleRate: 44100 });
|
||||||
|
|
||||||
let wasmBuffer = instance.exports.t.value
|
let frames = instance.exports.t.value
|
||||||
? new Int16Array(
|
? instance.exports.l.value / 4
|
||||||
instance.exports.m.buffer,
|
: instance.exports.l.value / 8;
|
||||||
instance.exports.s.value,
|
|
||||||
instance.exports.l.value / 2
|
|
||||||
)
|
|
||||||
: new Float32Array(
|
|
||||||
instance.exports.m.buffer,
|
|
||||||
instance.exports.s.value,
|
|
||||||
instance.exports.l.value / 4
|
|
||||||
);
|
|
||||||
|
|
||||||
const buffer = context.createBuffer(
|
let wasmBuffer = new Float32Array(
|
||||||
2,
|
instance.exports.m.buffer,
|
||||||
context.sampleRate * 2,
|
instance.exports.s.value,
|
||||||
context.sampleRate
|
frames * 2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const buffer = context.createBuffer(2, frames, context.sampleRate);
|
||||||
|
|
||||||
// convert wasm buffer to audio buffer
|
// convert wasm buffer to audio buffer
|
||||||
for (let channel = 0; channel < 2; channel++) {
|
for (let channel = 0; channel < 2; channel++) {
|
||||||
const buffering = buffer.getChannelData(channel);
|
const buffering = buffer.getChannelData(channel);
|
||||||
for (let i = 0; i < context.sampleRate * 2; i++) {
|
for (let i = 0; i < frames; i++) {
|
||||||
buffering[i] = wasmBuffer[i];
|
buffering[i] = wasmBuffer[i * 2 + channel];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user