-
Notifications
You must be signed in to change notification settings - Fork 0
/
efx_cabsim.js
103 lines (87 loc) · 3.66 KB
/
efx_cabsim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function flexfx_create( tag )
{
var x = "";
x += "<p>";
x += "Stereo Cabinet Simulator using impulse responses. Impulse responses to upload must be ";
x += "stored in a wave file (RIFF/WAV format) and have a sampling frequency of 48 kHz. Both ";
x += "mono and stereo source data is supported. Stereo can also be employed by specifying two ";
x += "separate mono WAV files.";
x += "</p>";
x += "<table class='flexfx'>";
x += "<thead>";
x += "<tr><th>Preset</th><th>Left/Mono</th><th>Right/Stereo</th><th>File Name(s)</th></tr>";
x += "</thead>";
x += "<tbody>";
for( var p = 1; p <= 9; ++p ) {
x += "<tr><td class='preset' id='"+tag+"_preset"+p+"'>"+p+"</td>";
x += "<td><input type='file' style='display:none' id='"+tag+"_input"+p+"L'/><button id='"+tag+"_button"+p+"L'>Select IR</button></td>";
x += "<td><input type='file' style='display:none' id='"+tag+"_input"+p+"R'/><button id='"+tag+"_button"+p+"R'>Select IR</button></td>";
x += "<td><div style='display:inline-block'>";
x += "<div id='"+tag+"_text"+p+"L'>Celestion G12H Ann 152 Open Room.wav</div>";
x += "<div id='"+tag+"_text"+p+"R'>Celestion G12H Ann 152 Open Room.wav</div>";
x += "</div></td>"; x += "</tr>"; }
x += "</tbody></table>";
return x;
}
function flexfx_initialize( tag )
{
for( var i = 1; i <= 9; ++i )
{
$(tag+"_preset"+i).onclick = _on_cabsim_select;
$(tag+"_button"+i+"L").onclick = _on_cabsim_button;
$(tag+"_button"+i+"R").onclick = _on_cabsim_button;
$(tag+"_input"+i+"L").onchange = _on_cabsim_input;
$(tag+"_input"+i+"R").onchange = _on_cabsim_input;
}
return _on_property_received;
}
function _on_cabsim_select( event )
{
var tag = flexfx_get_tag( event.target.id );
if( event.target.innerHTML[0] == '[' ) preset = parseInt( event.target.innerHTML[1] );
else preset = parseInt( event.target.innerHTML );
parent = $(tag+"_preset"+preset).parentNode.parentNode;
for( var i = 1; i <= 9; ++i ) parent.children[i-1].children[0].innerHTML = i;
parent.children[preset-1].children[0].innerHTML = "[" + preset + "]";
//flexfx_send_property( tag, property );
}
function _on_cabsim_input( event )
{
var tag = flexfx_get_tag( event.target.id );
var unit = parseInt( event.target.id[(tag+"_input").length+0] );
var preset = parseInt( event.target.id[(tag+"_input").length+1] );
var side = event.target.id[(tag+"_input").length+2];
var file = $(tag+"_input"+unit+""+preset+side).files[0];
$(tag+"_text"+unit+""+preset+side).textContent = file.name;
var reader = new FileReader();
reader.onload = function(e)
{
var samples = flexfx_wave_to_samples( new Uint8Array( reader.result ));
console.log( samples.length );
var offset = 0;
while( offset < 1200 ) {
if( samples.length >= 4 ) {
var property = [ 0x01018000+offset/5, samples[0],samples[1],samples[2],samples[3],samples[4] ];
samples = samples.slice( 5 );
flexfx_property = [0,0,0,0,0,0];
flexfx_send_property( tag, property );
}
while( 1 ) { if( flexfx_property[0] == 0x01018000+offset/5 ) break; }
offset += 5;
}
}
reader.readAsArrayBuffer( file );
}
function _on_cabsim_button( event )
{
var tag = flexfx_get_tag( event.target.id );
var preset = parseInt( event.target.id[(tag+"_button").length+0] );
var side = event.target.id[(tag+"_button").length+1];
$(tag+"_input"+preset+""+side).click();
}
function _on_property_received( property )
{
}
function _on_firmware_status( status )
{
}