Added cache for getChannelData

Fixes #310
This commit is contained in:
kkapsner 2019-02-07 20:12:12 +01:00
parent 53cdf8347e
commit e47f726abb
4 changed files with 17 additions and 13 deletions

View File

@ -154,6 +154,7 @@
return status;
}
const getChannelDataAlreadyFakedArrays = new WeakMap();
// changed functions and their fakes
scope.changedFunctions = {
getFloatFrequencyData: {
@ -218,9 +219,12 @@
return function getChannelData(channel){
return checkerWrapper(checker, this, arguments, function(args, check){
var {prefs, notify, window, original} = check;
notify("fakedAudioReadout");
var ret = original.apply(this, window.Array.from(args));
fakeFloat32Array(ret, window, prefs);
if (!getChannelDataAlreadyFakedArrays.get(ret)){
notify("fakedAudioReadout");
fakeFloat32Array(ret, window, prefs);
getChannelDataAlreadyFakedArrays.set(ret, true);
}
return ret;
});
};

View File

@ -3,7 +3,7 @@ Version 0.5.8:
-
new features:
-
- Added cache for getChannelData
fixes:
- after reset the hidden settings and expanded views were not reset

View File

@ -7,7 +7,7 @@
<body>
<h1>Audio test</h1>
<div id="test">
Hash: <span class="hash"></span><br>
Hashes: <ul class="hash"></ul>
Sum: <span class="sum"></span>
<button>refresh</button>
</div>

View File

@ -16,7 +16,7 @@
var pxi_output;
var pxi_full_buffer;
function run_pxi_fp(){
var context = new window.OfflineAudioContext(1, 44100, 44100);
var context = new window.OfflineAudioContext(2, 44100, 44100);
// Create oscillator
var pxi_oscillator = context.createOscillator();
@ -44,14 +44,14 @@
var copyTest = new Float32Array(44100);
event.renderedBuffer.copyFromChannel(copyTest, 0);
var getTest = event.renderedBuffer.getChannelData(0);
Promise.all([
crypto.subtle.digest("SHA-256", getTest),
crypto.subtle.digest("SHA-256", copyTest),
]).then(function(hashes){
container.querySelector(".hash").textContent =
byteArrayToHex(hashes[0]) +
" / " +
byteArrayToHex(hashes[1]);
var getTest2 = event.renderedBuffer.getChannelData(0);
var getTest3 = event.renderedBuffer.getChannelData(1);
Promise.all([getTest, getTest2, getTest3, copyTest].map(function(array){
return crypto.subtle.digest("SHA-256", array);
})).then(function(hashes){
container.querySelector(".hash").innerHTML = hashes.map(byteArrayToHex).map(function(hash){
return "<li>" + hash + "</li>";
}).join("");
});
var sum = 0;
for (var i = 4500; i < 5000; i += 1) {