From eea614b4f5c39e9767c92110b4cdb390b13510dd Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 29 Nov 2023 05:49:59 -0500 Subject: [PATCH] samples stability --- source/funkin/audio/visualize/PolygonSpectogram.hx | 9 ++++++++- .../funkin/ui/debug/charting/ChartEditorState.hx | 14 ++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/funkin/audio/visualize/PolygonSpectogram.hx b/source/funkin/audio/visualize/PolygonSpectogram.hx index 604bc910b..04eed7f43 100644 --- a/source/funkin/audio/visualize/PolygonSpectogram.hx +++ b/source/funkin/audio/visualize/PolygonSpectogram.hx @@ -73,10 +73,17 @@ class PolygonSpectogram extends MeshRender start = Math.max(start, 0); + // gets how many samples to generate var samplesToGen:Int = Std.int(sampleRate * seconds); + + if (samplesToGen == 0) return; // gets which sample to start at var startSample:Int = Std.int(FlxMath.remapToRange(start, 0, vis.snd.length, 0, numSamples)); + // Check if startSample and samplesToGen are within the bounds of the audioData array + if (startSample < 0 || startSample >= numSamples) return; + if (samplesToGen <= 0 || startSample + samplesToGen > numSamples) samplesToGen = numSamples - startSample; + var prevPoint:FlxPoint = new FlxPoint(); var funnyPixels:Int = Std.int(daHeight); // sorta redundant but just need it for different var... @@ -123,7 +130,7 @@ class PolygonSpectogram extends MeshRender curTime = vis.snd.time; - generateSection(vis.snd.time, realtimeVisLenght); + if (vis.snd.time < vis.snd.length - realtimeVisLenght) generateSection(vis.snd.time, realtimeVisLenght); } } } diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 9676f1a30..41c67c857 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -111,6 +111,7 @@ import haxe.ui.events.UIEvent; import haxe.ui.focus.FocusManager; import openfl.display.BitmapData; import funkin.audio.visualize.PolygonSpectogram; +import flixel.group.FlxGroup.FlxTypedGroup; using Lambda; @@ -1328,6 +1329,10 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState */ // ============================== + /** + * The group containing the visulizers! */ + var visulizerGrps:FlxTypedGroup = null; + /** * The IMAGE used for the grid. Updated by ChartEditorThemeHandler. */ @@ -1871,6 +1876,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState healthIconBF.flipX = true; add(healthIconBF); healthIconBF.zIndex = 30; + + visulizerGrps = new FlxTypedGroup(); + add(visulizerGrps); } function buildNotePreview():Void @@ -2226,11 +2234,9 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState #if sys menubarItemGoToBackupsFolder.onClick = _ -> this.openBackupsFolder(); #else - // Disable the menu item if we're not on a desktop platform. var menubarItemGoToBackupsFolder = findComponent('menubarItemGoToBackupsFolder', MenuItem); if (menubarItemGoToBackupsFolder != null) menubarItemGoToBackupsFolder.disabled = true; - #end menubarItemUserGuide.onClick = _ -> this.openUserGuideDialog(); @@ -5054,8 +5060,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState } var vis:PolygonSpectogram = new PolygonSpectogram(audioInstTrack); - vis.generateSection(0, 4); - add(vis); + vis.realtimeVisLenght = 1; + visulizerGrps.add(vis); } else {