Skip to content

Commit

Permalink
Analyse only active window width
Browse files Browse the repository at this point in the history
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;
  • Loading branch information
Gary Keeble committed Apr 3, 2016
1 parent 532d38c commit d2c5231
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions js/graph_spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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....
}
Expand Down
2 changes: 1 addition & 1 deletion js/grapher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');}
}
}
Expand Down

0 comments on commit d2c5231

Please sign in to comment.