mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 12:50:36 +01:00
Added test for audio faking
This commit is contained in:
parent
d580c35898
commit
b4a8507140
16
test/audioTest.html
Normal file
16
test/audioTest.html
Normal file
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Audio test</title>
|
||||
<style></style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Audio test</h1>
|
||||
<div id="test">
|
||||
Hash: <span class="hash"></span><br>
|
||||
Sum: <span class="sum"></span>
|
||||
<button>refresh</button>
|
||||
</div>
|
||||
<script src="audioTest.js"></script>
|
||||
</body>
|
||||
</html>
|
66
test/audioTest.js
Normal file
66
test/audioTest.js
Normal file
@ -0,0 +1,66 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
function byteArrayToHex(arrayBuffer){
|
||||
var chunks = [];
|
||||
(new Uint32Array(arrayBuffer)).forEach(function(num){
|
||||
chunks.push(num.toString(16));
|
||||
});
|
||||
return chunks.map(function(chunk){
|
||||
return "0".repeat(8 - chunk.length) + chunk;
|
||||
}).join("");
|
||||
}
|
||||
|
||||
var container = document.getElementById("test");
|
||||
|
||||
var pxi_output;
|
||||
var pxi_full_buffer;
|
||||
function run_pxi_fp(){
|
||||
var context = new window.OfflineAudioContext(1, 44100, 44100);
|
||||
|
||||
// Create oscillator
|
||||
var pxi_oscillator = context.createOscillator();
|
||||
pxi_oscillator.type = "triangle";
|
||||
pxi_oscillator.frequency.value = 1e4;
|
||||
|
||||
// Create and configure compressor
|
||||
var pxi_compressor = context.createDynamicsCompressor();
|
||||
pxi_compressor.threshold && (pxi_compressor.threshold.value = -50);
|
||||
pxi_compressor.knee && (pxi_compressor.knee.value = 40);
|
||||
pxi_compressor.ratio && (pxi_compressor.ratio.value = 12);
|
||||
pxi_compressor.reduction && (pxi_compressor.reduction.value = -20);
|
||||
pxi_compressor.attack && (pxi_compressor.attack.value = 0);
|
||||
pxi_compressor.release && (pxi_compressor.release.value = .25);
|
||||
|
||||
// Connect nodes
|
||||
pxi_oscillator.connect(pxi_compressor);
|
||||
pxi_compressor.connect(context.destination);
|
||||
|
||||
// Start audio processing
|
||||
pxi_oscillator.start(0);
|
||||
context.startRendering();
|
||||
context.oncomplete = function(evnt) {
|
||||
var str = "";
|
||||
var copyTest = new Float32Array(44100);
|
||||
evnt.renderedBuffer.copyFromChannel(copyTest, 0);
|
||||
var getTest = evnt.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 sum = 0;
|
||||
for (var i = 4500; i < 5000; i += 1) {
|
||||
sum += Math.abs(getTest[i]);
|
||||
}
|
||||
container.querySelector(".sum").textContent = sum;
|
||||
pxi_compressor.disconnect();
|
||||
};
|
||||
}
|
||||
run_pxi_fp();
|
||||
container.querySelector("button").addEventListener("click", run_pxi_fp);
|
||||
}());
|
@ -8,6 +8,7 @@
|
||||
|
||||
<ul>
|
||||
<li><a href="test.html">Fingerprinting test</a></li>
|
||||
<li><a href="audioTest.html">Audio Fingerprint test</a></li>
|
||||
<li><a href="detectionTest.html">Detection test</a></li>
|
||||
<li><a href="performanceTest.html">Performance test</a></li>
|
||||
<li><a href="webGL-Test.html">Support for webGL</a></li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user