Pixel-Composer/scripts/node_FFT/node_FFT.gml

42 lines
1.1 KiB
Text
Raw Normal View History

2023-05-16 21:28:16 +02:00
function Node_FFT(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2024-03-28 14:18:02 +01:00
name = "FFT";
setDimension(96, 72);
2023-05-16 21:28:16 +02:00
2024-08-18 09:13:41 +02:00
newInput(0, nodeValue_Float("Data", self, []))
2023-05-16 21:28:16 +02:00
.setArrayDepth(1)
.setVisible(true, true);
2023-05-23 14:02:38 +02:00
2024-08-18 06:16:20 +02:00
newInput(1, nodeValue_Enum_Scroll("Preprocess Function", self, 0, [ "None", "Hann" ]));
2023-05-16 21:28:16 +02:00
2024-08-08 06:57:51 +02:00
outputs[0] = nodeValue_Output("Array", self, VALUE_TYPE.float, [])
2023-05-16 21:28:16 +02:00
.setArrayDepth(1);
2023-08-17 16:56:54 +02:00
static processData = function(_outSurf, _data, _output_index, _array_index) {
2023-05-16 21:28:16 +02:00
var _dat = _data[0];
2023-05-23 14:02:38 +02:00
var _pre = _data[1];
2023-05-16 21:28:16 +02:00
var _cmp = [];
2023-05-23 14:02:38 +02:00
var N = array_length(_dat);
for( var i = 0; i < N; i++ ) {
var val = _dat[i];
if(_pre == 1) val = 0.5 * (1 - cos(2 * pi * i / (N - 1)));
_cmp[i] = new Complex(val);
}
2023-05-16 21:28:16 +02:00
var _res = FFT(_cmp);
2023-05-23 14:02:38 +02:00
var _r = array_create(array_length(_res));
2023-05-16 21:28:16 +02:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(_res); i < n; i++ )
2023-05-22 20:31:55 +02:00
_r[i] = sqrt(sqr(_res[i].re) + sqr(_res[i].im));
2023-05-16 21:28:16 +02:00
return _r;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
2023-05-22 20:31:55 +02:00
draw_sprite_fit(s_node_FFT, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
2023-05-16 21:28:16 +02:00
}
}