@@ -211,30 +211,17 @@ class SpectralAnalyzer
211211 #if lime_vorbis
212212 if (audioClip .streamed )
213213 {
214- var length = endFrame - startFrame ;
215- // trace(length);
216- // var buffer:Bytes = Bytes.alloc();
217-
218- // if (_vorbisBuffer == null || (_vorbisBuffer.length != length))
219- // {
220- // _vorbisBuffer = null;
221- // _vorbisBuffer = new UInt8Array(length);
222- // }
223-
224214 @:privateAccess
225215 var vorbisFile = audioSource .buffer .__srcVorbisFile ;
226216
227217 // reading from VorbisFile will automatically move the position
228218 // which causes issues with playback, so we keep old time to go back to it
229219 var prevPos = vorbisFile .pcmTell ();
230-
231- vorbisFile .pcmSeek (startFrame );
232220
233- @:privateAccess
234- // _vorbisBuffer = audioSource.__backend.readVorbisFileBuffer(vorbisFile, length);
235- _vorbisBuffer = readVorbisBuffer (vorbisFile , 0 , wantedLength );
221+ vorbisFile .pcmSeek (Std .int (startFrame / (numOctets + audioClip .audioBuffer .channels )));
236222
237- // trace('$startFrame - $endFrame');
223+ @:privateAccess
224+ _vorbisBuffer = readVorbisBuffer (vorbisFile , wantedLength );
238225
239226 vorbisFile .pcmSeek (prevPos );
240227
@@ -243,8 +230,6 @@ class SpectralAnalyzer
243230 else
244231 #end
245232 {
246-
247-
248233 var segment : UInt8Array = audioSource .buffer .data .subarray (startFrame , endFrame );
249234 signal = getSignal (segment , audioClip .audioBuffer .bitsPerSample );
250235 }
@@ -333,7 +318,9 @@ class SpectralAnalyzer
333318 }
334319
335320 #if lime_vorbis
336- function readVorbisBuffer (vorbisFile : VorbisFile , position : Int , length : Int ): UInt8Array
321+ // Pretty much copied from
322+ // https://github.com/openfl/lime/blob/develop/src/lime/_internal/backend/native/NativeAudioSource.hx#L212
323+ function readVorbisBuffer (vorbisFile : VorbisFile , length : Int ): UInt8Array
337324 {
338325 var buffer : UInt8Array = new UInt8Array (length );
339326
0 commit comments