immersive-home/app/lib/utils/sample_hold.gd

12 lines
407 B
GDScript3
Raw Normal View History

2024-03-17 01:14:31 +02:00
## Reduces the frequency of a signal by sampling and holding the data
2024-03-15 01:13:05 +02:00
static func sample_and_hold(data: PackedVector2Array, sample_rate: float) -> PackedFloat32Array:
var new_data: PackedFloat32Array = PackedFloat32Array()
new_data.resize(int(data.size() / sample_rate))
var counter = 0.0
for i in range(new_data.size()):
new_data[i] = data[int(counter)].y
counter += sample_rate
return new_data