mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
Refined audio faking procedure.
This commit is contained in:
parent
c13a6f88b3
commit
df5109bbf6
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
var randomSupply = null;
|
var randomSupply = null;
|
||||||
|
|
||||||
|
const getAudioFakeRate = function(){
|
||||||
const audioFakeRate = {
|
const audioFakeRate = {
|
||||||
"1": function(array){return 1;},
|
"1": function(array){return 1;},
|
||||||
"10": function(array){return 10;},
|
"10": function(array){return 10;},
|
||||||
@ -26,7 +27,7 @@
|
|||||||
"0.1%": function(array){return array.length / 1000;},
|
"0.1%": function(array){return array.length / 1000;},
|
||||||
"1%": function(array){return array.length / 100;},
|
"1%": function(array){return array.length / 100;},
|
||||||
};
|
};
|
||||||
function getAudioFakeRate(array, prefs){
|
return function getAudioFakeRate(array, prefs){
|
||||||
var func = audioFakeRate[prefs("audioFakeRate")];
|
var func = audioFakeRate[prefs("audioFakeRate")];
|
||||||
if (typeof func === "function"){
|
if (typeof func === "function"){
|
||||||
return func(array);
|
return func(array);
|
||||||
@ -34,41 +35,65 @@
|
|||||||
else {
|
else {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const audioNoiseLevel = {
|
|
||||||
"minimal": 0.0000001,
|
|
||||||
"low": 0.00001,
|
|
||||||
"medium": 0.001,
|
|
||||||
"high": 0.01,
|
|
||||||
"maximal": 0.1
|
|
||||||
};
|
};
|
||||||
function getAudioNoiseLevel(prefs){
|
}();
|
||||||
return audioNoiseLevel[prefs("audioNoiseLevel")] || 0.0000001;
|
const getAudioNoiseLevel = function(){
|
||||||
|
const audioNoiseLevel = {
|
||||||
|
"minimal": 0.0001,
|
||||||
|
"low": 0.0005,
|
||||||
|
"medium": 0.001,
|
||||||
|
"high": 0.005,
|
||||||
|
"maximal": 0.01
|
||||||
|
};
|
||||||
|
return function getAudioNoiseLevel(prefs){
|
||||||
|
return audioNoiseLevel[prefs("audioNoiseLevel")] || 0.0001;
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
function forEachFixedIndex(prefs, callback){
|
||||||
|
if (prefs("audioUseFixedIndices")){
|
||||||
|
prefs("audioFixedIndices")
|
||||||
|
.split(",")
|
||||||
|
.map(function(str){
|
||||||
|
return parseInt(str, 10);
|
||||||
|
}).filter(function(num){
|
||||||
|
return !isNaN(num);
|
||||||
|
}).filter(function(num, i, array){
|
||||||
|
return array.indexOf(num) === i;
|
||||||
|
}).forEach(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function forEachIndex(array, prefs, callback){
|
||||||
|
var l = array.length;
|
||||||
|
var rate = getAudioFakeRate(array, prefs);
|
||||||
|
var indexRng = randomSupply.getIndexRng(rate, l, window);
|
||||||
|
var start = 0;
|
||||||
|
forEachFixedIndex(prefs, function(index){
|
||||||
|
callback(index, start);
|
||||||
|
start += 1;
|
||||||
|
});
|
||||||
|
for (var i = start; i < rate; i += 1){
|
||||||
|
callback(indexRng(i), i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fakeFloat32Array(array, window, prefs){
|
function fakeFloat32Array(array, window, prefs){
|
||||||
if (prefs("protectAudio")){
|
if (prefs("protectAudio")){
|
||||||
var l = array.length;
|
|
||||||
var rate = getAudioFakeRate(array, prefs);
|
var rate = getAudioFakeRate(array, prefs);
|
||||||
var noiseLevel = getAudioNoiseLevel(prefs);
|
var noiseLevel = getAudioNoiseLevel(prefs);
|
||||||
var indexRng = randomSupply.getIndexRng(rate, l, window);
|
|
||||||
var rng = randomSupply.getRng(rate, window);
|
var rng = randomSupply.getRng(rate, window);
|
||||||
for (var i = 0; i < rate; i += 1){
|
forEachIndex(array, prefs, function(index, i){
|
||||||
var index = indexRng(i);
|
array[index] *= 1 + (rng(i) / 0xffffffff - 0.5) * noiseLevel;
|
||||||
array[index] += (rng(i) / 0xffffffff - 0.5) * noiseLevel;
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function fakeUint8Array(array, window, prefs){
|
function fakeUint8Array(array, window, prefs){
|
||||||
if (prefs("protectAudio")){
|
if (prefs("protectAudio")){
|
||||||
var l = array.length;
|
|
||||||
var rate = getAudioFakeRate(array, prefs);
|
var rate = getAudioFakeRate(array, prefs);
|
||||||
var indexRng = randomSupply.getIndexRng(rate, l, window);
|
|
||||||
var rng = randomSupply.getValueRng(rate, window);
|
var rng = randomSupply.getValueRng(rate, window);
|
||||||
for (var i = 0; i < rate; i += 1){
|
forEachIndex(prefs, function(index, i){
|
||||||
var index = indexRng(i);
|
|
||||||
array[index] = rng(array[index], i);
|
array[index] = rng(array[index], i);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "audioNoiseLevel",
|
name: "audioNoiseLevel",
|
||||||
defaultValue: "low",
|
defaultValue: "minimal",
|
||||||
options: ["minimal", "low", "medium", "high", "maximal"]
|
options: ["minimal", "low", "medium", "high", "maximal"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user