1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-03 12:06:31 +02:00

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

@ -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) {