From dc4ca962599eec4f07e460b6c64458c764c64b6c Mon Sep 17 00:00:00 2001 From: Lewis Moten Date: Wed, 1 May 2024 15:02:31 -0400 Subject: [PATCH] bits based on frequency pairs highest amplitude --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2e7a690..bef2285 100644 --- a/index.js +++ b/index.js @@ -141,14 +141,16 @@ function analyzeAudio() { var i = Math.round(hz / length); return frequencyData[i] > FREQUENCY_THRESHOLD; } + function amplitude(hz) { + var length = (audioContext.sampleRate / analyser.fftSize); + var i = Math.round(hz / length); + return frequencyData[i]; + } var high = canHear(FREQUENCY_HIGH); var low = canHear(FREQUENCY_LOW); if(high || low) { - if(high && low) listen += '['; - if(high) listen += '1'; - if(low) listen += '0'; - if(high && low) listen += ']'; + listen += amplitude(FREQUENCY_HIGH) > amplitude(FREQUENCY_LOW) ? '1' : '0'; } else { if(listen !== '') { receivedDataTextarea.value += listen + '\n';