Pixel-Composer/scripts/wav_file_object/wav_file_object.gml
MakhamDev 0311e2eeb6 - [Audio] Now use audioBit datatype instead of pure array to improve performance.
- [Audio File In] Add mono conversion property.
- [Audio window] Now only accept audioBit datatype.
2023-10-03 09:29:58 +07:00

52 lines
1.2 KiB
Plaintext

function audioObject(sample = 8, channel = 2) constructor {
self.sound = [];
self.soundF = [];
self.sample = sample;
self.channels = channel;
self.bit_depth = 32;
self.duration = 0;
self.packet = 0;
self.mono = false;
preview_surface = noone;
static checkPreview = function(w, h, force = false) {
if(!force && is_surface(preview_surface)) return preview_surface;
print($"--- Creating preview surface [{w}, {h}] ---");
var ch = channels;
if(ch == 0) return;
if(array_length(sound) < 1) return;
var len = array_length(sound[0]);
if(len == 0) return;
var spc = min(w, len);
var stp = len / spc;
preview_surface = surface_verify(preview_surface, w, h);
surface_set_target(preview_surface);
draw_clear_alpha(c_white, 0);
draw_set_color(c_white);
var ox, oy, nx, ny;
for( var i = 0; i < len; i += stp ) {
nx = i / len * 320;
ny = h / 2 + sound[0][i] * h;
if(i) draw_line_width(ox, oy, nx, ny, 4);
ox = nx;
oy = ny;
}
surface_reset_target();
return preview_surface;
}
static getChannel = function() { return mono? 1 : channels; }
static getData = function() { return mono? soundF : sound; }
}