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,57 +18,82 @@
|
|||||||
|
|
||||||
var randomSupply = null;
|
var randomSupply = null;
|
||||||
|
|
||||||
const audioFakeRate = {
|
const getAudioFakeRate = function(){
|
||||||
"1": function(array){return 1;},
|
const audioFakeRate = {
|
||||||
"10": function(array){return 10;},
|
"1": function(array){return 1;},
|
||||||
"100": function(array){return 100;},
|
"10": function(array){return 10;},
|
||||||
"1000": function(array){return 1000;},
|
"100": function(array){return 100;},
|
||||||
"0.1%": function(array){return array.length / 1000;},
|
"1000": function(array){return 1000;},
|
||||||
"1%": function(array){return array.length / 100;},
|
"0.1%": function(array){return array.length / 1000;},
|
||||||
};
|
"1%": function(array){return array.length / 100;},
|
||||||
function getAudioFakeRate(array, prefs){
|
};
|
||||||
var func = audioFakeRate[prefs("audioFakeRate")];
|
return function getAudioFakeRate(array, prefs){
|
||||||
if (typeof func === "function"){
|
var func = audioFakeRate[prefs("audioFakeRate")];
|
||||||
return func(array);
|
if (typeof func === "function"){
|
||||||
}
|
return func(array);
|
||||||
else {
|
}
|
||||||
return 10;
|
else {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const audioNoiseLevel = {
|
|
||||||
"minimal": 0.0000001,
|
function forEachIndex(array, prefs, callback){
|
||||||
"low": 0.00001,
|
var l = array.length;
|
||||||
"medium": 0.001,
|
var rate = getAudioFakeRate(array, prefs);
|
||||||
"high": 0.01,
|
var indexRng = randomSupply.getIndexRng(rate, l, window);
|
||||||
"maximal": 0.1
|
var start = 0;
|
||||||
};
|
forEachFixedIndex(prefs, function(index){
|
||||||
function getAudioNoiseLevel(prefs){
|
callback(index, start);
|
||||||
return audioNoiseLevel[prefs("audioNoiseLevel")] || 0.0000001;
|
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