1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 04:26:35 +02:00

Added audio cache.

This commit is contained in:
kkapsner 2018-06-30 00:34:20 +02:00
parent f7a0990a29
commit 4d71d6bc02
7 changed files with 312 additions and 17 deletions

View file

@ -14,6 +14,7 @@
}
const logging = require("./logging");
const {sha256String: hashing} = require("./hash");
const getWrapped = require("sdk/getWrapped");
var randomSupply = null;
@ -77,30 +78,61 @@
}
}
const floatCache = Object.create(null);
const intCache = Object.create(null);
function fakeFloat32Array(array, window, prefs){
if (prefs("protectAudio")){
var rate = getAudioFakeRate(array, prefs);
var noiseLevel = getAudioNoiseLevel(prefs);
var rng = randomSupply.getRng(rate, window);
forEachIndex(array, prefs, function(index, i){
let value;
if (array[index] !== 0){
value = array[index] * (1 + (rng(i) / 0xffffffff - 0.5) * noiseLevel);
let cached = false;
let hash;
if (prefs("useAudioCache")){
hash = hashing(array);
cached = floatCache[hash];
}
if (!cached){
var rate = getAudioFakeRate(array, prefs);
var noiseLevel = getAudioNoiseLevel(prefs);
var rng = randomSupply.getRng(rate, window);
forEachIndex(array, prefs, function(index, i){
let value;
if (array[index] !== 0){
value = array[index] * (1 + (rng(i) / 0xffffffff - 0.5) * noiseLevel);
}
else {
value = Number.EPSILON * (rng(i) / 0xffffffff - 0.5) * noiseLevel;
}
array[index] = value;
});
if (prefs("useAudioCache")){
floatCache[hash] = new window.Float32Array(array);
}
else {
value = Number.EPSILON * (rng(i) / 0xffffffff - 0.5) * noiseLevel;
}
array[index] = value;
});
}
else {
array.set(cached);
}
}
}
function fakeUint8Array(array, window, prefs){
if (prefs("protectAudio")){
var rate = getAudioFakeRate(array, prefs);
var rng = randomSupply.getValueRng(rate, window);
forEachIndex(prefs, function(index, i){
array[index] = rng(array[index], i);
});
let cached = false;
let hash;
if (prefs("useAudioCache")){
hash = hashing(array);
cached = intCache[hash];
}
if (!cached){
var rate = getAudioFakeRate(array, prefs);
var rng = randomSupply.getValueRng(rate, window);
forEachIndex(prefs, function(index, i){
array[index] = rng(array[index], i);
});
if (prefs("useAudioCache")){
intCache[hash] = new window.Uint8Array(array);
}
}
else {
array.set(cached);
}
}
}