@@ -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 ) ;
0 commit comments