/usr/share/faust/webaudio/webaudio-asm-poly-emcc.js is in faust-common 0.9.95~repack1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | /*
faust2webaudio
Primarily written by Myles Borins
During the Spring 2013 offering of Music 420b with Julius Smith
A bit during the Summer of 2013 with the help of Joshua Kit Clayton
And finally a sprint during the late fall of 2013 to get everything working
A Special thanks to Yann Orlarey and Stéphane Letz
faust2webaudio is distributed under the terms the MIT or GPL2 Licenses.
Choose the license that best suits your project. The text of the MIT and GPL
licenses are at the root directory.
Additional code : GRAME 2014-2016
*/
'use strict';
var faust = faust || {};
// Polyphonic DSP : has to have 'freq', 'gate', 'gain' parameters to be possibly triggered with keyOn, keyOff events.
var DSP_poly_constructor = Module.cwrap('DSP_poly_constructor', 'number', ['number']);
var DSP_poly_destructor = Module.cwrap('DSP_poly_destructor', null, ['number']);
var DSP_poly_getSampleRate = Module.cwrap('DSP_poly_getSampleRate', 'number', ['number']);
var DSP_poly_init = Module.cwrap('DSP_poly_init', 'number', ['number','number']);
var DSP_poly_instanceInit = Module.cwrap('DSP_poly_instanceInit', 'number', ['number','number']);
var DSP_poly_instanceConstants = Module.cwrap('DSP_poly_instanceConstants', 'number', ['number','number']);
var DSP_poly_instanceResetUserInterface = Module.cwrap('DSP_poly_instanceResetUserInterface', 'number', ['number']);
var DSP_poly_instanceClear = Module.cwrap('DSP_poly_instanceClear', 'number', ['number']);
var DSP_poly_compute = Module.cwrap('DSP_poly_compute', null, ['number', 'number', 'number', 'number']);
var DSP_poly_getNumInputs = Module.cwrap('DSP_poly_getNumInputs', 'number', ['number']);
var DSP_poly_getNumOutputs = Module.cwrap('DSP_poly_getNumOutputs', 'number', ['number']);
var DSP_poly_getJSON = Module.cwrap('DSP_poly_getJSON', 'number', ['number']);
var DSP_poly_setParamValue = Module.cwrap('DSP_poly_setParamValue', null, ['number', 'number', 'number']);
var DSP_poly_getParamValue = Module.cwrap('DSP_poly_getParamValue', 'number', ['number', 'number']);
var DSP_poly_keyOn = Module.cwrap('DSP_poly_keyOn', null, ['number', 'number', 'number', 'number']);
var DSP_poly_keyOff = Module.cwrap('DSP_poly_keyOff', null, ['number', 'number', 'number', 'number']);
var DSP_poly_allNotesOff = Module.cwrap('DSP_poly_allNotesOff', null, ['number']);
var DSP_poly_ctrlChange = Module.cwrap('DSP_poly_ctrlChange', null, ['number', 'number', 'number', 'number']);
var DSP_poly_pitchWheel = Module.cwrap('DSP_poly_pitchWheel', null, ['number', 'number', 'number']);
faust.DSP_poly = function (context, buffer_size, max_polyphony, callback) {
var handler = null;
var ins, outs;
var numIn, numOut;
var compute_callback = callback;
var scriptProcessor;
var dspInChannnels = [];
var dspOutChannnels = [];
// Path string
var path_ptr = Module._malloc(512);
// bargraph
var ouputs_timer = 5;
var ouputs_items = [];
// input items
var inputs_items = [];
var ptr = DSP_poly_constructor(max_polyphony);
DSPP_poly_init(ptr, context.sampleRate);
function update_outputs ()
{
if (ouputs_items.length > 0 && handler && ouputs_timer-- === 0) {
ouputs_timer = 5;
for (var i = 0; i < ouputs_items.length; i++) {
Module.writeStringToMemory(ouputs_items[i], path_ptr);
handler(ouputs_items[i], DSP_poly_getParamValue(ptr, path_ptr));
}
}
}
// JSON parsing
function parse_ui (ui)
{
for (var i = 0; i < ui.length; i++) {
parse_group(ui[i]);
}
}
function parse_group (group)
{
if (group.items) {
parse_items(group.items);
}
}
function parse_items (items)
{
for (var i = 0; i < items.length; i++) {
parse_item(items[i]);
}
}
function parse_item (item)
{
if (item.type === "vgroup" || item.type === "hgroup" || item.type === "tgroup") {
parse_items(item.items);
} else if (item.type === "hbargraph" || item.type === "vbargraph") {
// Keep bargraph adresses
ouputs_items.push(item.address);
} else if (item.type === "vslider" || item.type === "hslider" || item.type === "button" || item.type === "checkbox" || item.type === "nentry") {
// Keep inputs adresses
inputs_items.push(item.address);
}
}
function compute (e)
{
// Read inputs
for (var i = 0; i < numIn; i++) {
var input = e.inputBuffer.getChannelData(i);
var dspInput = dspInChannnels[i];
for (var j = 0; j < input.length; j++) {
dspInput[j] = input[j];
}
}
// Possibly call an externally given callback (for instance to play a MIDIFile...)
if (compute_callback) {
compute_callback(buffer_size);
}
// Compute
DSP_poly_compute(ptr, buffer_size, ins, outs);
// Update bargraph
update_outputs();
// Write outputs
for (var i = 0; i < numOut; i++) {
var output = e.outputBuffer.getChannelData(i);
var dspOutput = dspOutChannnels[i];
for (var j = 0; j < output.length; j++) {
output[j] = dspOutput[j];
}
}
}
function init ()
{
var i;
var ptr_size = 4; //assuming pointer in emscripten are 32bits
var sample_size = 4;
// Get input / output counts
numIn = DSP_poly_getNumInputs(ptr);
numOut = DSP_poly_getNumOutputs(ptr);
// Setup web audio context
scriptProcessor = context.createScriptProcessor(buffer_size, numIn, numOut);
scriptProcessor.onaudioprocess = compute;
if (numIn > 0) {
ins = Module._malloc(ptr_size * numIn);
for (i = 0; i < numIn; i++) {
HEAP32[(ins >> 2) + i] = Module._malloc(buffer_size * sample_size);
}
// Prepare Ins buffer tables
var dspInChans = HEAP32.subarray(ins >> 2, (ins + numIn * ptr_size) >> 2);
for (i = 0; i < numIn; i++) {
dspInChannnels[i] = HEAPF32.subarray(dspInChans[i] >> 2, (dspInChans[i] + buffer_size * sample_size) >> 2);
}
}
if (numOut > 0) {
outs = Module._malloc(ptr_size * numOut);
for (i = 0; i < numOut; i++) {
HEAP32[(outs >> 2) + i] = Module._malloc(buffer_size * sample_size);
}
// Prepare Outs buffer tables
var dspOutChans = HEAP32.subarray(outs >> 2, (outs + numOut * ptr_size) >> 2);
for (i = 0; i < numOut; i++) {
dspOutChannnels[i] = HEAPF32.subarray(dspOutChans[i] >> 2, (dspOutChans[i] + buffer_size * sample_size) >> 2);
}
}
// bargraph
parse_ui(JSON.parse(Pointer_stringify(DSP_poly_getJSON(ptr))).ui);
}
init();
// External API
return {
getNumInputs : function ()
{
return DSP_poly_getNumInputs(ptr);
},
getNumOutputs : function()
{
return DSP_poly_getNumOutputs(ptr);
},
getSampleRate : function ()
{
return DSP_poly_getSampleRate(ptr);
},
init : function (sample_rate)
{
DSP_init(ptr, sample_rate);
},
instanceInit : function (sample_rate)
{
DSP_poly_instanceInit(ptr, sample_rate);
},
instanceConstants : function (sample_rate)
{
DSP_poly_instanceConstants(ptr, sample_rate);
},
instanceResetUserInterface : function ()
{
DSP_poly_instanceResetUserInterface(ptr);
},
instanceClear : function ()
{
DSP_poly_instanceClear(ptr);
},
keyOn : function (channel, pitch, velocity)
{
DSP_poly_keyOn(ptr, channel, pitch, velocity);
},
keyOff : function (channel, pitch, velocity)
{
DSP_poly_keyOff(ptr, channel, pitch, velocity);
},
allNotesOff : function ()
{
DSP_poly_allNotesOff(ptr);
},
ctrlChange : function (channel, ctrl, value)
{
DSP_poly_ctrlChange(ptr, channel, ctrl, value);
},
pitchWheel : function (channel, pitchWheel)
{
DSP_poly_pitchWheel(ptr, channel, pitchWheel);
},
destroy : function ()
{
DSP_poly_destructor(ptr);
if (numIn > 0) {
for (var i = 0; i < numIn; i++) {
Module._free(HEAP32[(ins >> 2) + i]);
}
Module._free(ins);
}
if (numOut > 0) {
for (var i = 0; i < numOut; i++) {
Module._free(HEAP32[(outs >> 2) + i]);
}
Module._free(outs);
}
Module._free(path_ptr);
},
// Connect/disconnect to another node
connect : function (node)
{
if (node.getProcessor !== undefined) {
scriptProcessor.connect(node.getProcessor());
} else {
scriptProcessor.connect(node);
}
},
disconnect : function (node)
{
if (node.getProcessor !== undefined) {
scriptProcessor.disconnect(node.getProcessor());
} else {
scriptProcessor.disconnect(node);
}
},
setHandler: function (hd)
{
handler = hd;
},
start : function ()
{
scriptProcessor.connect(context.destination);
},
stop : function ()
{
scriptProcessor.disconnect(context.destination);
},
setParamValue : function (path, val)
{
Module.writeStringToMemory(path, path_ptr);
DSP_poly_setParamValue(ptr, path_ptr, val);
},
getParamValue : function (path)
{
Module.writeStringToMemory(path, path_ptr);
return DSP_poly_getParamValue(ptr, path_ptr);
},
controls : function ()
{
return inputs_items;
},
json : function ()
{
return Pointer_stringify(DSP_poly_getJSON(ptr));
},
getSampleRate : function ()
{
return context.sampleRate;
},
setComputeCallback : function (callback) {
compute_callback = callback;
},
getComputeCallback : function () {
return compute_callback;
},
getProcessor : function ()
{
return scriptProcessor;
}
};
};
|