mirror of
https://github.com/XProger/OpenLara.git
synced 2025-02-24 15:32:30 +01:00
#9 force resample web audio api to 44.1kHz
This commit is contained in:
parent
831e0765db
commit
95f5794a83
@ -49,18 +49,18 @@
|
|||||||
if (!AudioContext) return;
|
if (!AudioContext) return;
|
||||||
var ctx = new (window.AudioContext || window.webkitAudioContext)();
|
var ctx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
var count = 2048;
|
var count = 2048;
|
||||||
var frames = Module._malloc(count * 4); // interleaved short L, R
|
var rate = 44100 / ctx.sampleRate;
|
||||||
|
var framesCount = Math.ceil(count * rate);
|
||||||
|
var frames = Module._malloc(framesCount * 4); // interleaved short L, R
|
||||||
var proc = ctx.createScriptProcessor(count, 2, 2);
|
var proc = ctx.createScriptProcessor(count, 2, 2);
|
||||||
|
|
||||||
proc.onaudioprocess = function(e) {
|
proc.onaudioprocess = function(e) {
|
||||||
var L = e.outputBuffer.getChannelData(0),
|
var L = e.outputBuffer.getChannelData(0),
|
||||||
R = e.outputBuffer.getChannelData(1);
|
R = e.outputBuffer.getChannelData(1);
|
||||||
Module.ccall('snd_fill', 'null', ['number', 'number'], [frames, count]);
|
Module.ccall('snd_fill', 'null', ['number', 'number'], [frames, framesCount]);
|
||||||
var index = frames;
|
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
|
var index = frames + Math.floor(i * rate) * 4; // 4 is sample frame stride in bytes
|
||||||
L[i] = Module.getValue(index , 'i16') / 0x8000;
|
L[i] = Module.getValue(index , 'i16') / 0x8000;
|
||||||
R[i] = Module.getValue(index + 2, 'i16') / 0x8000;
|
R[i] = Module.getValue(index + 2, 'i16') / 0x8000;
|
||||||
index += 4;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proc.connect(ctx.destination);
|
proc.connect(ctx.destination);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user