Smoothing PoolByteArray data ? how to

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By uriel

Hi, here is the problem i have to simplify my array:

first, i must talk about the context, i got an audiostreamplayer with a stream data.
the complete data.size() = 1 102 192 !
from those data, i want to draw some lines…
as you can imagine, i cannot use so much data, so i try to simplify by getting 1/1000.

here is the code:

func _draw():
	var vibe = $AudioStreamPlayer
	var data =

	var x = 15

	for i in data: 
			# draw = (from..., to..., color, width)
			draw_line(Vector2(x,400), Vector2(x,i/2), Color(0,0,0,1), 2)
			x +=3

here i show my code with all data ! which make the draw function unusable. and this is only from my test soundfiles, i would get some larger ones, so i need to find the way to smooth/reduce.

how can i reduce the amount of data to be drawn ?

I don’t think there is a built in method for that, but you can have a look at Savitzky-Golay algorithm.

It is a way of smoothing curves with the principle of moving average.

Matt_UV | 2019-10-10 21:27

i did add: data.resize(1000) before the loop !
so the 2D lines are now 1000, much better than a milion … but this is not what i want.
this only limit the length… still looking for the answer :wink:


uriel | 2019-10-10 21:48