diff --git a/lib/modifiedAudioAPI.js b/lib/modifiedAudioAPI.js
index 969af66..1b5219d 100644
--- a/lib/modifiedAudioAPI.js
+++ b/lib/modifiedAudioAPI.js
@@ -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;
});
};
diff --git a/releaseNotes.txt b/releaseNotes.txt
index d26b70a..d3e54b2 100644
--- a/releaseNotes.txt
+++ b/releaseNotes.txt
@@ -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
diff --git a/test/audioTest.html b/test/audioTest.html
index e056759..f54c8fa 100644
--- a/test/audioTest.html
+++ b/test/audioTest.html
@@ -7,7 +7,7 @@
Audio test
- Hash:
+ Hashes:
Sum:
diff --git a/test/audioTest.js b/test/audioTest.js
index 57d7244..02cfdc6 100644
--- a/test/audioTest.js
+++ b/test/audioTest.js
@@ -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 "" + hash + "";
+ }).join("");
});
var sum = 0;
for (var i = 4500; i < 5000; i += 1) {