mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-02-03 00:35:14 +01:00
Load audio from buffer instead of byte read.
This commit is contained in:
parent
be9dc15065
commit
f29208b0b2
6 changed files with 62 additions and 41 deletions
|
@ -27,13 +27,13 @@ function Node_Color_RGB(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
|
||||||
var _nor = inputs[| 3].getValue();
|
var _nor = inputs[| 3].getValue();
|
||||||
|
|
||||||
if(_nor) {
|
if(_nor) {
|
||||||
inputs[| 0].type = VALUE_TYPE.integer;
|
inputs[| 0].type = VALUE_TYPE.float;
|
||||||
inputs[| 0].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
inputs[| 0].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
||||||
|
|
||||||
inputs[| 1].type = VALUE_TYPE.integer;
|
inputs[| 1].type = VALUE_TYPE.float;
|
||||||
inputs[| 1].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
inputs[| 1].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
||||||
|
|
||||||
inputs[| 2].type = VALUE_TYPE.integer;
|
inputs[| 2].type = VALUE_TYPE.float;
|
||||||
inputs[| 2].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
inputs[| 2].setDisplay(VALUE_DISPLAY.slider, [0, 1, 0.01]);
|
||||||
} else {
|
} else {
|
||||||
inputs[| 0].type = VALUE_TYPE.integer;
|
inputs[| 0].type = VALUE_TYPE.integer;
|
||||||
|
|
|
@ -859,7 +859,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
|
||||||
if(PANEL_GRAPH.show_dimension) {
|
if(PANEL_GRAPH.show_dimension) {
|
||||||
var txt = string(getNodeDimension(_s > 0.65));
|
var txt = string(getNodeDimension(_s > 0.65));
|
||||||
draw_text(round(tx), round(ty), txt);
|
draw_text(round(tx), round(ty), txt);
|
||||||
ty += string_height(txt) - 4 * _s;
|
ty += string_height(txt) - 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PANEL_GRAPH.show_compute) {
|
if(PANEL_GRAPH.show_compute) {
|
||||||
|
|
|
@ -107,6 +107,9 @@ function Node_WAV_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
||||||
var ch = content.channels;
|
var ch = content.channels;
|
||||||
if(ch == 0) return;
|
if(ch == 0) return;
|
||||||
|
|
||||||
|
if(!struct_has(content, "sound")) return;
|
||||||
|
if(array_length(content.sound) < 1) return;
|
||||||
|
|
||||||
var len = array_length(content.sound[0]);
|
var len = array_length(content.sound[0]);
|
||||||
if(len == 0) return;
|
if(len == 0) return;
|
||||||
|
|
||||||
|
@ -179,7 +182,7 @@ function Node_WAV_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
||||||
insp1UpdateTooltip = get_text("panel_inspector_refresh", "Refresh");
|
insp1UpdateTooltip = get_text("panel_inspector_refresh", "Refresh");
|
||||||
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
|
insp1UpdateIcon = [ THEME.refresh, 1, COLORS._main_value_positive ];
|
||||||
|
|
||||||
insp2UpdateTooltip = get_text("play", "Play");
|
insp2UpdateTooltip = get_text("play_with_timeline", "Play with timeline");
|
||||||
insp2UpdateIcon = [ THEME.play_sound, 1, COLORS._main_icon_light ];
|
insp2UpdateIcon = [ THEME.play_sound, 1, COLORS._main_icon_light ];
|
||||||
attributes[? "play"] = true;
|
attributes[? "play"] = true;
|
||||||
|
|
||||||
|
@ -239,6 +242,9 @@ function Node_WAV_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
||||||
|
|
||||||
//print($"{amp_ind}: {amp_st} - {amp_ed}")
|
//print($"{amp_ind}: {amp_st} - {amp_ed}")
|
||||||
|
|
||||||
|
if(!struct_has(content, "sound")) return;
|
||||||
|
if(array_length(content.sound) < 1) return;
|
||||||
|
|
||||||
var dec = 0;
|
var dec = 0;
|
||||||
for( var i = amp_st; i < amp_ed; i++ )
|
for( var i = amp_st; i < amp_ed; i++ )
|
||||||
dec += content.sound[0][i] == 0? 0 : 20 * log10(abs(content.sound[0][i]));
|
dec += content.sound[0][i] == 0? 0 : 20 * log10(abs(content.sound[0][i]));
|
||||||
|
@ -291,6 +297,9 @@ function Node_WAV_File_Read(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
||||||
var _am = content.packet / _st;
|
var _am = content.packet / _st;
|
||||||
var ox, oy, nx, ny;
|
var ox, oy, nx, ny;
|
||||||
|
|
||||||
|
if(!struct_has(content, "sound")) return;
|
||||||
|
if(array_length(content.sound) < 1) return;
|
||||||
|
|
||||||
for( var i = 0; i <= _am; i++ ) {
|
for( var i = 0; i <= _am; i++ ) {
|
||||||
var _dat = content.sound[0][min(i * _st, content.packet - 1)];
|
var _dat = content.sound[0][min(i * _st, content.packet - 1)];
|
||||||
nx = _shf + i * _s;
|
nx = _shf + i * _s;
|
||||||
|
|
|
@ -16,8 +16,8 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
|
||||||
bgColor : COLORS.panel_bg_clear,
|
bgColor : COLORS.panel_bg_clear,
|
||||||
|
|
||||||
gridEnable : false,
|
gridEnable : false,
|
||||||
gridColor : c_white,
|
gridColor : targetPanel.grid_color,
|
||||||
gridAlpha : 0.05,
|
gridAlpha : targetPanel.grid_opacity,
|
||||||
|
|
||||||
borderPad : 0,
|
borderPad : 0,
|
||||||
borderColor : c_white,
|
borderColor : c_white,
|
||||||
|
@ -140,15 +140,16 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
|
||||||
sc_settings.draw(sx, sy, mx - sx, my - sy);
|
sc_settings.draw(sx, sy, mx - sx, my - sy);
|
||||||
|
|
||||||
if(is_surface(surface)) {
|
if(is_surface(surface)) {
|
||||||
|
var txt = "Export...";
|
||||||
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
|
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
|
||||||
var _bw = string_width("Export") + ui(32);
|
var _bw = string_width(txt) + ui(32);
|
||||||
var _bh = string_height("Export") + ui(12);
|
var _bh = string_height(txt) + ui(12);
|
||||||
bx = w - padding - _bw;
|
bx = w - padding - _bw;
|
||||||
by = h - padding - _bh;
|
by = h - padding - _bh;
|
||||||
|
|
||||||
b_export.setActiveFocus(pFOCUS, pHOVER);
|
b_export.setActiveFocus(pFOCUS, pHOVER);
|
||||||
b_export.draw(bx, by, _bw, _bh, _m);
|
b_export.draw(bx, by, _bw, _bh, _m);
|
||||||
draw_text(bx + ui(16), by + ui(6), "Export");
|
draw_text(bx + ui(16), by + ui(6), txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,14 +81,11 @@
|
||||||
var v1 = getVal(l, inp);
|
var v1 = getVal(l, inp);
|
||||||
var v2 = getVal(r, inp, symbol == "|");
|
var v2 = getVal(r, inp, symbol == "|");
|
||||||
|
|
||||||
//print("symbol " + string(symbol));
|
|
||||||
//print("l : " + string(l));
|
|
||||||
//print("r : " + string(r));
|
|
||||||
//print("v1 : " + string(v1));
|
|
||||||
//print("v2 : " + string(v2));
|
|
||||||
//print("====================");
|
|
||||||
|
|
||||||
//print($"{string(v1)} {symbol} {string(v2)}");
|
//print($"{string(v1)} {symbol} {string(v2)}");
|
||||||
|
//print($"symbol : {symbol}");
|
||||||
|
//print($"l : {l}");
|
||||||
|
//print($"r : {r}");
|
||||||
|
//print("====================");
|
||||||
|
|
||||||
switch(symbol) {
|
switch(symbol) {
|
||||||
|
|
||||||
|
@ -212,15 +209,22 @@
|
||||||
|
|
||||||
switch(operator) {
|
switch(operator) {
|
||||||
case "-": //deal with preceeding megative number -5
|
case "-": //deal with preceeding megative number -5
|
||||||
if(ds_stack_size(vl) >= 2) return new __funcTree("-", ds_stack_pop(vl), ds_stack_pop(vl));
|
if(ds_stack_size(vl) >= 2) {
|
||||||
else return new __funcTree("-", ds_stack_pop(vl), 0);
|
var _v1 = ds_stack_pop(vl);
|
||||||
|
var _v2 = ds_stack_pop(vl);
|
||||||
|
return new __funcTree("-", _v2, _v1);
|
||||||
|
} else return new __funcTree("-", ds_stack_pop(vl), 0);
|
||||||
|
|
||||||
case "+": //binary operators
|
case "+": //binary operators
|
||||||
case "*":
|
case "*":
|
||||||
case "^":
|
case "^":
|
||||||
case "/":
|
case "/":
|
||||||
case "|":
|
case "|":
|
||||||
if(ds_stack_size(vl) >= 2) return new __funcTree(operator, ds_stack_pop(vl), ds_stack_pop(vl));
|
if(ds_stack_size(vl) >= 2) {
|
||||||
|
var _v1 = ds_stack_pop(vl);
|
||||||
|
var _v2 = ds_stack_pop(vl);
|
||||||
|
return new __funcTree(operator, _v2, _v1);
|
||||||
|
}
|
||||||
|
|
||||||
default: return new __funcTree(operator, ds_stack_pop(vl));
|
default: return new __funcTree(operator, ds_stack_pop(vl));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
function file_read_ASCII(file, amo = 1) {
|
function file_read_ASCII(file, amo = 1) {
|
||||||
var b = "";
|
var b = "";
|
||||||
repeat(amo)
|
repeat(amo)
|
||||||
b += chr(file_bin_read_byte(file));
|
b += chr(buffer_read(file, buffer_u8));
|
||||||
|
//b += chr(file_bin_read_byte(file));
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +10,8 @@ function file_read_bytes(file, amo = 1, signed = false, little_endian = true) {
|
||||||
var b = 0;
|
var b = 0;
|
||||||
var m = little_endian? 1 : 1 << ((amo - 1) * 8);
|
var m = little_endian? 1 : 1 << ((amo - 1) * 8);
|
||||||
repeat(amo) {
|
repeat(amo) {
|
||||||
b += file_bin_read_byte(file) * m;
|
//b += file_bin_read_byte(file) * m;
|
||||||
|
b += buffer_read(file, buffer_u8) * m;
|
||||||
m = little_endian? m * 256 : m / 256;
|
m = little_endian? m * 256 : m / 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,37 +27,39 @@ function file_read_bytes(file, amo = 1, signed = false, little_endian = true) {
|
||||||
global.FLAG.wav_import = true;
|
global.FLAG.wav_import = true;
|
||||||
|
|
||||||
function file_read_wav(path) {
|
function file_read_wav(path) {
|
||||||
wav_file_reader = file_bin_open(path, 0);
|
wav_file_reader = buffer_load(path);
|
||||||
wav_file_reading = true;
|
wav_file_reading = true;
|
||||||
wav_file_prg = 0;
|
wav_file_prg = 0;
|
||||||
|
|
||||||
|
wav_file_load_time = current_time;
|
||||||
|
|
||||||
//RIFF
|
//RIFF
|
||||||
printIf(global.FLAG.wav_import, "-- RIFF --")
|
printIf(global.FLAG.wav_import, "-- RIFF --")
|
||||||
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
||||||
var l = file_read_bytes(wav_file_reader, 4); printIf(global.FLAG.wav_import, $"Packages: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u32); printIf(global.FLAG.wav_import, $"Packages: {l}");
|
||||||
var w = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, w);
|
var w = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, w);
|
||||||
|
|
||||||
//FORMAT
|
//FORMAT
|
||||||
printIf(global.FLAG.wav_import, "-- FORMAT --")
|
printIf(global.FLAG.wav_import, "-- FORMAT --")
|
||||||
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
||||||
var l = file_read_bytes(wav_file_reader, 4); printIf(global.FLAG.wav_import, $"Length: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u32); printIf(global.FLAG.wav_import, $"Length: {l}");
|
||||||
|
|
||||||
if(l != 16) {
|
if(l != 16) {
|
||||||
noti_waning("File format not supported, the audio file need to be 8, 16 bit PCM wav with no extension.");
|
noti_warning("File format not supported, the audio file need to be 8, 16 bit PCM wav with no extension.");
|
||||||
return;
|
return noone;
|
||||||
}
|
}
|
||||||
|
|
||||||
var l = file_read_bytes(wav_file_reader, 2); printIf(global.FLAG.wav_import, $"0x01: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u16); printIf(global.FLAG.wav_import, $"0x01: {l}");
|
||||||
var ch = file_read_bytes(wav_file_reader, 2); printIf(global.FLAG.wav_import, $"Channels: {ch}");
|
var ch = buffer_read(wav_file_reader, buffer_u16); printIf(global.FLAG.wav_import, $"Channels: {ch}");
|
||||||
var sm = file_read_bytes(wav_file_reader, 4); printIf(global.FLAG.wav_import, $"Sample: {sm}");
|
var sm = buffer_read(wav_file_reader, buffer_u32); printIf(global.FLAG.wav_import, $"Sample: {sm}");
|
||||||
var l = file_read_bytes(wav_file_reader, 4); printIf(global.FLAG.wav_import, $"BPS: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u32); printIf(global.FLAG.wav_import, $"BPS: {l}");
|
||||||
var br = file_read_bytes(wav_file_reader, 2); printIf(global.FLAG.wav_import, $"Bitrate: {br}");
|
var br = buffer_read(wav_file_reader, buffer_u16); printIf(global.FLAG.wav_import, $"Bitrate: {br}");
|
||||||
var l = file_read_bytes(wav_file_reader, 2); printIf(global.FLAG.wav_import, $"Bit/Sam: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u16); printIf(global.FLAG.wav_import, $"Bit/Sam: {l}");
|
||||||
|
|
||||||
//DATA
|
//DATA
|
||||||
printIf(global.FLAG.wav_import, "-- DATA --")
|
printIf(global.FLAG.wav_import, "-- DATA --")
|
||||||
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
var b = file_read_ASCII(wav_file_reader, 4); printIf(global.FLAG.wav_import, b);
|
||||||
var l = file_read_bytes(wav_file_reader, 4); printIf(global.FLAG.wav_import, $"Length: {l}");
|
var l = buffer_read(wav_file_reader, buffer_u32); printIf(global.FLAG.wav_import, $"Length: {l}");
|
||||||
|
|
||||||
var bpc = br / ch;
|
var bpc = br / ch;
|
||||||
var bits = l / br;
|
var bits = l / br;
|
||||||
|
@ -87,23 +91,26 @@ function file_read_wav(path) {
|
||||||
function file_read_wav_step() {
|
function file_read_wav_step() {
|
||||||
if(!wav_file_reading) return false;
|
if(!wav_file_reading) return false;
|
||||||
|
|
||||||
var bpc = content.bit_depth / 8;
|
|
||||||
var lim = 1 << (8 * bpc - 2);
|
|
||||||
var t = current_time;
|
var t = current_time;
|
||||||
|
var bf_type, lim;
|
||||||
|
if(content.bit_depth == 8) { bf_type = buffer_u8; lim = 255; }
|
||||||
|
else if(content.bit_depth == 16) { bf_type = buffer_s16; lim = 32_768; }
|
||||||
|
else if(content.bit_depth == 32) { bf_type = buffer_s32; lim = 2_147_483_648; }
|
||||||
|
|
||||||
for(; wav_file_prg < content.packet; wav_file_prg++ ) {
|
for(; wav_file_prg < content.packet; wav_file_prg++ ) {
|
||||||
for( var j = 0; j < content.channels; j++ )
|
for( var j = 0; j < content.channels; j++ )
|
||||||
content.sound[j][wav_file_prg] = file_read_bytes(wav_file_reader, bpc, bpc == 2) / lim;
|
content.sound[j][wav_file_prg] = buffer_read(wav_file_reader, bf_type) / lim;
|
||||||
|
|
||||||
wav_file_range[0] = min(wav_file_range[0], content.sound[0][wav_file_prg]);
|
//wav_file_range[0] = min(wav_file_range[0], content.sound[0][wav_file_prg]);
|
||||||
wav_file_range[1] = max(wav_file_range[1], content.sound[0][wav_file_prg]);
|
//wav_file_range[1] = max(wav_file_range[1], content.sound[0][wav_file_prg]);
|
||||||
|
|
||||||
if(current_time - t > 1000 / 30) return false;
|
if(current_time - t > 1000 / 30) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printIf(global.FLAG.wav_import, $"Wav range: {wav_file_range}");
|
//printIf(global.FLAG.wav_import, $"Wav range: {wav_file_range}");
|
||||||
|
printIf(global.FLAG.wav_import, $"Load file complete in: {(current_time - wav_file_load_time) / 1000} s.");
|
||||||
|
|
||||||
wav_file_reading = false;
|
wav_file_reading = false;
|
||||||
file_bin_close(wav_file_reader);
|
buffer_delete(wav_file_reader);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
Reference in a new issue