Skip to content

Commit 6a24435

Browse files
committed
Merge branch 'Analyser-Tweaks'
2 parents a04602e + 4432ba7 commit 6a24435

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

index.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,18 @@ <h4>Log sync</h4>
292292
<canvas width="0" height="0" id="craftCanvas"></canvas>
293293
<div class="analyser">
294294
<canvas width="0" height="0" id="analyserCanvas"></canvas>
295-
<input id="analyserZoomX" type="range" name="analyserZoomX" value="100" min="100" max="500" step="100" title=""/>
296-
<input id="analyserZoomY" type="range" name="analyserZoomY" value="100" min="10" max="1000" step="10"/>
295+
<input id="analyserZoomX" type="range" name="analyserZoomX" value="100" min="100" max="500" step="10" title="" list="analyserZoomXTicks"/>
296+
<input id="analyserZoomY" type="range" name="analyserZoomY" value="100" min="10" max="1000" step="10" list="analyserZoomYTicks"/>
297+
<datalist id="analyserZoomXTicks">
298+
<option>100</option>
299+
<option>200</option>
300+
<option>300</option>
301+
<option>400</option>
302+
<option>500</option>
303+
</datalist>
304+
<datalist id="analyserZoomYTicks">
305+
<option>100</option>
306+
</datalist>
297307
</div>
298308
<canvas width="0" height="0" id="analyserStickCanvas"></canvas>
299309
<span class="log-open-legend-dialog glyphicon glyphicon-cog" data-toggle="tooltip" title="Show the legend"></span>
@@ -1314,7 +1324,10 @@ <h4 class="modal-title">Advanced User Settings</h4>
13141324
<div class="spacer_box_title">Analyser Settings</div>
13151325
</div>
13161326
<div class="spacer_box">
1317-
<table>
1327+
<div>
1328+
<label class="option">Hanning<input class="analyser-hanning ios-switch" type="checkbox"/><div><div></div></div><span>Use Hanning Window for Analyser</span></label>
1329+
</div>
1330+
<table>
13181331
<tr>
13191332
<td>
13201333
<label>Position</label>

js/graph_spectrum.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,22 @@ try {
138138
var samples = new Float64Array(MAX_ANALYSER_LENGTH/1000);
139139

140140
// Loop through all the samples in the chunks and assign them to a sample array ready to pass to the FFT.
141-
var sampleIndex = 0;
141+
fftData.samples = 0;
142142
for (var chunkIndex = 0; chunkIndex < allChunks.length; chunkIndex++) {
143143
var chunk = allChunks[chunkIndex];
144144
for (var frameIndex = 0; frameIndex < chunk.frames.length; frameIndex++) {
145-
samples[sampleIndex++] = (dataBuffer.curve.lookupRaw(chunk.frames[frameIndex][dataBuffer.fieldIndex]));
145+
samples[fftData.samples++] = (dataBuffer.curve.lookupRaw(chunk.frames[frameIndex][dataBuffer.fieldIndex]));
146146
}
147147
}
148148

149-
//calculate fft
149+
if(userSettings.analyserHanning) {
150+
// apply hanning window function
151+
for(var i=0; i<fftData.samples; i++) {
152+
samples[i] *= 0.5 * (1-Math.cos((2*Math.PI*i)/(fftData.samples - 1)));
153+
}
154+
}
155+
156+
//calculate fft
150157
var fftLength = samples.length;
151158
var fftOutput = new Float64Array(fftLength * 2);
152159
var fft = new FFT.complex(fftLength, false);
@@ -212,10 +219,10 @@ try {
212219
var x = 0;
213220

214221
var barGradient = canvasCtx.createLinearGradient(0,HEIGHT,0,0);
215-
barGradient.addColorStop(0, 'rgba(0,255,0,0.2)');
216-
barGradient.addColorStop(0.15, 'rgba(128,255,0,0.2)');
217-
barGradient.addColorStop(0.45, 'rgba(255,0,0,0.5)');
218-
barGradient.addColorStop(1, 'rgba(255,128,128,1.0)');
222+
barGradient.addColorStop(constrain(0/analyserZoomY,0,1), 'rgba(0,255,0,0.2)');
223+
barGradient.addColorStop(constrain(0.15/analyserZoomY,0,1), 'rgba(128,255,0,0.2)');
224+
barGradient.addColorStop(constrain(0.45/analyserZoomY,0,1), 'rgba(255,0,0,0.5)');
225+
barGradient.addColorStop(constrain(1/analyserZoomY, 0, 1), 'rgba(255,128,128,1.0)');
219226
canvasCtx.fillStyle = barGradient; //'rgba(0,255,0,0.3)'; //green
220227

221228
var fftScale = HEIGHT / (analyserZoomY*100);

js/user_settings_dialog.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
5555
graphSmoothOverride : false, // Ability to toggle smoothing off=normal/ on=force 0%
5656
graphExpoOverride : false, // Ability to toggle Expo off=normal/ on=force 100%
5757
graphGridOverride : false, // Ability to toggle Expo off=normal/ on=force 100%
58-
59-
6058
analyserSampleRate : 2000/*Hz*/, // the loop time for the log
59+
analyserHanning : false, // use a hanning window on the analyser sample data
6160
eraseBackground : true, // Set to false if you want the graph to draw on top of an existing canvas image
6261
craft : {
6362
left : '15%', // position from left (as a percentage of width)
@@ -288,6 +287,10 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
288287
currentSettings.stickInvertYaw = $(this).is(":checked");
289288
});
290289

290+
$(".analyser-hanning").click(function() {
291+
currentSettings.analyserHanning = $(this).is(":checked");
292+
});
293+
291294
// Load Custom Logo
292295
function readURL(input) {
293296
if (input.files && input.files[0]) {
@@ -348,6 +351,11 @@ function UserSettingsDialog(dialog, onLoad, onSave) {
348351
$(".invert-yaw").prop('checked', currentSettings.stickInvertYaw);
349352
}
350353

354+
if(currentSettings.analyserHanning!=null) {
355+
// set the toggle switch
356+
$(".analyser-hanning").prop('checked', currentSettings.analyserHanning);
357+
}
358+
351359
mixerListSelection(currentSettings.mixerConfiguration); // select current mixer configuration
352360
stickModeSelection(currentSettings.stickMode);
353361

0 commit comments

Comments
 (0)