diff --git a/index.html b/index.html index 3b4042b..ea715f3 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ Last Bit Percent: %
FFT Size: 2^
Frequency Resolution: N/A
+ Frequency Count: N/A
Smoothing Time Constant:
diff --git a/index.js b/index.js index a6d6d6b..f5bf990 100644 --- a/index.js +++ b/index.js @@ -79,10 +79,10 @@ function handleWindowLoad() { document.getElementById('fft-size-power-text').addEventListener('input', (event) => { FFT_POWER = parseInt(event.target.value); if(analyser) analyser.fftSize = 2 ** FFT_POWER; - document.getElementById('frequency-resolution').innerText = (getAudioContext().sampleRate / 2 ** FFT_POWER).toFixed(2); + updateFrequencyResolution(); resetGraphData(); }); - document.getElementById('frequency-resolution').innerText = (getAudioContext().sampleRate / 2 ** FFT_POWER).toFixed(2); + updateFrequencyResolution(); document.getElementById('smoothing-time-constant-text').addEventListener('input', event => { SMOOTHING_TIME_CONSTANT = parseFloat(event.target.value); if(analyser) analyser.smoothingTimeConstant = SMOOTHING_TIME_CONSTANT; @@ -95,6 +95,15 @@ function handleWindowLoad() { showSpeed(); } +function updateFrequencyResolution() { + const sampleRate = getAudioContext().sampleRate; + const fftSize = 2 ** FFT_POWER; + const frequencyResolution = sampleRate / fftSize; + const frequencyCount = (sampleRate/2) / frequencyResolution; + document.getElementById('frequency-resolution').innerText = frequencyResolution.toFixed(2); + document.getElementById('frequency-count').innerText = frequencyCount.toFixed(2); +} + function showSpeed() { const baud = 1000 / FREQUENCY_DURATION; const bytes = baud / 8;