From d2c52315193de57ce0b2a1f42844a477ff8e9a7f Mon Sep 17 00:00:00 2001 From: Gary Keeble Date: Sun, 3 Apr 2016 14:52:00 +0100 Subject: [PATCH] Analyse only active window width The analyser is now limited to the currently displayed window width so zoom is not considered in the samples. Note that the fat maxes out at zoom level 40% so any lower has no effect. Its a bit of a balance between speed and sample size; --- js/graph_spectrum.js | 19 ++++++++++++------- js/grapher.js | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/graph_spectrum.js b/js/graph_spectrum.js index 10a40dd0..daad18e2 100644 --- a/js/graph_spectrum.js +++ b/js/graph_spectrum.js @@ -13,7 +13,7 @@ var // inefficient; copied from grapher.js }; -var frameCount = 2048; +var frameCount = 4096; var AudioContext = window.AudioContext || window.webkitAudioContext; var audioCtx = new AudioContext(); @@ -30,7 +30,7 @@ var spectrumAnalyser = audioCtx.createAnalyser(); spectrumAnalyser.minDecibels = -120; spectrumAnalyser.maxDecibels = -20; -var bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve; +var bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, bufferWindowEndTime; var initialised = false; var analyserFieldName; // Name of the field being analysed @@ -39,7 +39,7 @@ source.connect(spectrumAnalyser); var audioIterations = 0; // variable to monitor spectrum processing -function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer) { +function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer, windowEndTime) { var chunkIndex, frameIndex; var i = 0; @@ -54,10 +54,13 @@ function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer) { var chunk = chunks[chunkIndex]; for (; frameIndex < chunk.frames.length; frameIndex++) { var fieldValue = chunk.frames[frameIndex][fieldIndex]; + var frameTime = chunk.frames[frameIndex][FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME] bufferData[i++] = (curve.lookupRaw(fieldValue)); - - if (i >= buffer.length) + + if (i >= buffer.length || frameTime >= windowEndTime) { + // console.log("Samples : " + i); break dataCollectionLoop; + } } frameIndex = 0; } @@ -147,16 +150,18 @@ function drawAxisLabel(axisLabel, X, Y, align) { It is only used to record the current curve positions, collect the data and draw the analyser on screen*/ -this.plotSpectrum = function (chunks, startFrameIndex, fieldIndex, curve, fieldName) { +this.plotSpectrum = function (chunks, startFrameIndex, fieldIndex, curve, fieldName, windowEndTime) { // Store the data pointers bufferChunks = chunks; bufferStartFrameIndex = startFrameIndex; bufferFieldIndex = fieldIndex; bufferCurve = curve; + bufferWindowEndTime = windowEndTime; + analyserFieldName = fieldName; if (audioBuffer) { - dataLoad(bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, audioBuffer); + dataLoad(bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, audioBuffer, bufferWindowEndTime); } draw(); // draw the analyser on the canvas.... } diff --git a/js/grapher.js b/js/grapher.js index c5d74caa..a1ab16bc 100755 --- a/js/grapher.js +++ b/js/grapher.js @@ -820,7 +820,7 @@ function FlightLogGrapher(flightLog, graphConfig, canvas, craftCanvas, options) try{ // If we do not select a graph/field, then the analyser is hidden var graph = graphs[graphConfig.selectedGraphIndex]; var field = graph.fields[graphConfig.selectedFieldIndex]; - analyser.plotSpectrum(chunks, startFrameIndex, field.index, field.curve, graphConfig.selectedFieldName); + analyser.plotSpectrum(chunks, startFrameIndex, field.index, field.curve, graphConfig.selectedFieldName, windowEndTime); } catch(err) {console.log('Cannot plot analyser');} } }