11package funkin .vis .dsp ;
22
3- import lime .media .vorbis .VorbisFile ;
43import haxe .io .Bytes ;
54import lime .utils .UInt8Array ;
65import flixel .FlxG ;
@@ -11,6 +10,10 @@ import grig.audio.FFT;
1110import grig .audio .FFTVisualization ;
1211import lime .media .AudioSource ;
1312
13+ #if lime_vorbis
14+ import lime .media .vorbis .VorbisFile ;
15+ #end
16+
1417using grig .audio .lime .UInt8ArrayTools ;
1518
1619typedef Bar =
@@ -59,6 +62,9 @@ class SpectralAnalyzer
5962 private var barHistories = new Array <RecentPeakFinder >();
6063 private var blackmanWindow = new Array <Float >();
6164 #end
65+ #if lime_vorbis
66+ private var vorbisBuffer : UInt8Array ;
67+ #end
6268
6369 private function freqToBin (freq : Float , mathType : MathType = Round ): Int
6470 {
@@ -211,6 +217,8 @@ class SpectralAnalyzer
211217 #if lime_vorbis
212218 if (audioClip .streamed )
213219 {
220+ vorbisBuffer = null ;
221+
214222 @:privateAccess
215223 var vorbisFile = audioSource .buffer .__srcVorbisFile ;
216224
@@ -221,11 +229,11 @@ class SpectralAnalyzer
221229 vorbisFile .pcmSeek (Std .int (startFrame / (numOctets + audioClip .audioBuffer .channels )));
222230
223231 @:privateAccess
224- _vorbisBuffer = readVorbisBuffer (vorbisFile , wantedLength );
232+ vorbisBuffer = readVorbisFileBuffer (vorbisFile , wantedLength );
225233
226234 vorbisFile .pcmSeek (prevPos );
227235
228- signal = getSignal (_vorbisBuffer , audioClip .audioBuffer .bitsPerSample );
236+ signal = getSignal (vorbisBuffer , audioClip .audioBuffer .bitsPerSample );
229237 }
230238 else
231239 #end
@@ -284,8 +292,6 @@ class SpectralAnalyzer
284292 #end
285293 }
286294
287- var _vorbisBuffer : UInt8Array ;
288-
289295 // Prevents a memory leak by reusing array
290296 var _buffer : Array <Float > = [];
291297 function getSignal (data : lime.utils. UInt8Array , bitsPerSample : Int ): Array <Float >
@@ -320,7 +326,7 @@ class SpectralAnalyzer
320326 #if lime_vorbis
321327 // Pretty much copied from
322328 // https://github.com/openfl/lime/blob/develop/src/lime/_internal/backend/native/NativeAudioSource.hx#L212
323- function readVorbisBuffer (vorbisFile : VorbisFile , length : Int ): UInt8Array
329+ function readVorbisFileBuffer (vorbisFile : VorbisFile , length : Int ): UInt8Array
324330 {
325331 var buffer : UInt8Array = new UInt8Array (length );
326332
0 commit comments