Skip to content

Commit d2c5231

Browse files
author
Gary Keeble
committed
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;
1 parent 532d38c commit d2c5231

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

js/graph_spectrum.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var // inefficient; copied from grapher.js
1313
};
1414

1515

16-
var frameCount = 2048;
16+
var frameCount = 4096;
1717

1818
var AudioContext = window.AudioContext || window.webkitAudioContext;
1919
var audioCtx = new AudioContext();
@@ -30,7 +30,7 @@ var spectrumAnalyser = audioCtx.createAnalyser();
3030
spectrumAnalyser.minDecibels = -120;
3131
spectrumAnalyser.maxDecibels = -20;
3232

33-
var bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve;
33+
var bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, bufferWindowEndTime;
3434
var initialised = false;
3535
var analyserFieldName; // Name of the field being analysed
3636

@@ -39,7 +39,7 @@ source.connect(spectrumAnalyser);
3939

4040
var audioIterations = 0; // variable to monitor spectrum processing
4141

42-
function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer) {
42+
function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer, windowEndTime) {
4343

4444
var chunkIndex, frameIndex;
4545
var i = 0;
@@ -54,10 +54,13 @@ function dataLoad(chunks, startFrameIndex, fieldIndex, curve, buffer) {
5454
var chunk = chunks[chunkIndex];
5555
for (; frameIndex < chunk.frames.length; frameIndex++) {
5656
var fieldValue = chunk.frames[frameIndex][fieldIndex];
57+
var frameTime = chunk.frames[frameIndex][FlightLogParser.prototype.FLIGHT_LOG_FIELD_INDEX_TIME]
5758
bufferData[i++] = (curve.lookupRaw(fieldValue));
58-
59-
if (i >= buffer.length)
59+
60+
if (i >= buffer.length || frameTime >= windowEndTime) {
61+
// console.log("Samples : " + i);
6062
break dataCollectionLoop;
63+
}
6164
}
6265
frameIndex = 0;
6366
}
@@ -147,16 +150,18 @@ function drawAxisLabel(axisLabel, X, Y, align) {
147150
It is only used to record the current curve positions, collect the data and draw the
148151
analyser on screen*/
149152

150-
this.plotSpectrum = function (chunks, startFrameIndex, fieldIndex, curve, fieldName) {
153+
this.plotSpectrum = function (chunks, startFrameIndex, fieldIndex, curve, fieldName, windowEndTime) {
151154
// Store the data pointers
152155
bufferChunks = chunks;
153156
bufferStartFrameIndex = startFrameIndex;
154157
bufferFieldIndex = fieldIndex;
155158
bufferCurve = curve;
159+
bufferWindowEndTime = windowEndTime;
160+
156161
analyserFieldName = fieldName;
157162

158163
if (audioBuffer) {
159-
dataLoad(bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, audioBuffer);
164+
dataLoad(bufferChunks, bufferStartFrameIndex, bufferFieldIndex, bufferCurve, audioBuffer, bufferWindowEndTime);
160165
}
161166
draw(); // draw the analyser on the canvas....
162167
}

js/grapher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ function FlightLogGrapher(flightLog, graphConfig, canvas, craftCanvas, options)
820820
try{ // If we do not select a graph/field, then the analyser is hidden
821821
var graph = graphs[graphConfig.selectedGraphIndex];
822822
var field = graph.fields[graphConfig.selectedFieldIndex];
823-
analyser.plotSpectrum(chunks, startFrameIndex, field.index, field.curve, graphConfig.selectedFieldName);
823+
analyser.plotSpectrum(chunks, startFrameIndex, field.index, field.curve, graphConfig.selectedFieldName, windowEndTime);
824824
} catch(err) {console.log('Cannot plot analyser');}
825825
}
826826
}

0 commit comments

Comments
 (0)