From 33e87cf443f77e9a648f5abecf41f55034e84eb4 Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Sun, 5 May 2024 15:17:13 -0400 Subject: [PATCH] change sample collection timer offset --- index.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 64a9dd8..2564415 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ var receivedData = []; var MAX_DATA = 300; var pauseTimeoutId; var sampleIntervalIds = []; -const SAMPLING_INTERVAL_COUNT = 3; var TEXT_TO_SEND = "U"; var RANDOM_COUNT = 128; @@ -31,6 +30,7 @@ var HAMMING_ERROR_CORRECTION = true; var LAST_STREAM_STARTED; var SAMPLE_DELAY_MS = 1; +const SAMPLING_INTERVAL_COUNT = 2; var frequencyOverTime = []; var bitStart = []; var samplesPerBit = []; @@ -402,7 +402,10 @@ function stopGraph() { function startCollectingSamples() { for(let i = 0; i < SAMPLING_INTERVAL_COUNT; i++) { if(sampleIntervalIds[i]) continue; - sampleIntervalIds[i] = window.setInterval(collectSample, SAMPLE_DELAY_MS); + sampleIntervalIds[i] = window.setInterval( + collectSample, + SAMPLE_DELAY_MS + (i/SAMPLING_INTERVAL_COUNT) + ); } } function stopCollectingSamples() { @@ -423,21 +426,6 @@ function resumeGraph() { PAUSE = false; } } -function getInteger(start, end, samples) { - let value = 0; - let valueIndex = 0; - for(let i = 0; i < samples.length; i++) { - for(let j = 0; j < samples[i].pairs.length; j++) { - if(b >= start) { - value += getBit(samples[i].pairs[j]) << valueIndex++; - if(b >= end) return bits; - } - b++; - } - } - return bits; -} - function collectSample() { const time = performance.now(); if(frequencyOverTime.length !== 0) { @@ -445,6 +433,7 @@ function collectSample() { if(time === frequencyOverTime[0].time) return; } const frequencies = new Uint8Array(analyser.frequencyBinCount); + analyser.getByteFrequencyData(frequencies); const length = audioContext.sampleRate / analyser.fftSize; let processSegment = false; const { @@ -453,7 +442,6 @@ function collectSample() { streamEnded: priorStreamEnded = -1, segmentIndex: priorSegmentIndex = -1 } = frequencyOverTime[0] ?? {} - analyser.getByteFrequencyData(frequencies); const data = { time, frequencies: [...frequencies],