File: wasm_dsp_aux.cpp

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (635 lines) | stat: -rw-r--r-- 19,362 bytes parent folder | download
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
/************************************************************************
 ************************************************************************
    FAUST compiler
    Copyright (C) 2003-2014 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 2.1 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ************************************************************************
 ************************************************************************/

#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <sstream>

#ifdef WIN32
#pragma warning(disable : 4251 4275 4800)
#endif

#include "compatibility.hh"
#include "libfaust.h"
#include "wasm_dsp_aux.hh"

#include "faust/gui/JSONUIDecoder.h"

#ifdef EMCC
#include <emscripten.h>
#include <emscripten/bind.h>
using namespace emscripten;
#endif

using namespace std;

dsp_factory_table<SDsp_factory> wasm_dsp_factory::gWasmFactoryTable;

#ifdef EMCC

#ifndef FAUST_LIB
#include "faust/dsp/poly-wasm-dsp.h"
#endif

// #include "faust/gui/SoundUI.h"

LIBFAUST_API wasm_dsp_factory::wasm_dsp_factory(int instance, const string& json)
{
    fFactory  = nullptr;
    fInstance = instance;
    fDecoder  = createJSONUIDecoder(json);
    // fSoundUI = new SoundUI();
}

LIBFAUST_API wasm_dsp_factory::~wasm_dsp_factory()
{
    /* Deactivated for 'wasm' branch version
    // Empty the JS structures so that the instance can be GCed
#ifdef AUDIO_WORKLET
    EM_ASM({ AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0] = null; }, fInstance);
#else
    EM_ASM({ faust_module.faust.wasm_instance[$0] = null; }, fInstance);
#endif
    */
    delete fFactory;
    delete fDecoder;
    // delete fSoundUI;
}

LIBFAUST_API wasm_dsp_factory* wasm_dsp_factory::createWasmDSPFactory(int           instance,
                                                                      const string& json)
{
    wasm_dsp_factory* factory = new wasm_dsp_factory(instance, json);
    wasm_dsp_factory::gWasmFactoryTable.setFactory(factory);
    return factory;
}

/* Deactivated for 'wasm' branch version
// To keep 'wasmMemory' in the generated JS library
#ifdef AUDIO_WORKLET
EM_JS(void, connectMemory, (),
{
    AudioWorkletGlobalScope.faust_module.faust = AudioWorkletGlobalScope.faust_module.faust || {};
    AudioWorkletGlobalScope.faust_module.faust.memory =
AudioWorkletGlobalScope.faust_module.faust.memory || wasmMemory;
});
#else
EM_JS(void, connectMemory, (),
{
    faust_module.faust = faust_module.faust || {};
    faust_module.faust.memory = faust_module.faust.memory || wasmMemory;
});
#endif
*/

LIBFAUST_API string wasm_dsp_factory::extractJSON(const string& code)
{
    /* Deactivated for 'wasm' branch version
        connectMemory();
    */
    if (code != "") {
        WasmBinaryReader reader(code);
        reader.read();
        return reader.json;
    } else {
        return "";
    }
}

LIBFAUST_API wasm_dsp_factory* readWasmDSPFactoryFromMachine(const string& machine_code,
                                                             string&       error_msg)
{
    wasm_dsp_factory* factory =
        new wasm_dsp_factory(new text_dsp_factory_aux("MachineDSP", "", "", machine_code, ""));
    wasm_dsp_factory::gWasmFactoryTable.setFactory(factory);
    return factory;
}

LIBFAUST_API string writeWasmDSPFactoryToMachine(wasm_dsp_factory* factory)
{
    return factory->getBinaryCode();
}

LIBFAUST_API wasm_dsp_factory* readWasmDSPFactoryFromMachineFile(const string& machine_code_path,
                                                                 string&       error_msg)
{
    ifstream infile;
    infile.open(machine_code_path, ifstream::in | ifstream::binary);

    if (infile.is_open()) {
        // get length of file:
        infile.seekg(0, infile.end);
        int length = infile.tellg();
        infile.seekg(0, infile.beg);

        // read code
        char* machine_code = new char[length];
        infile.read(machine_code, length);

        // create factory
        wasm_dsp_factory* factory = readWasmDSPFactoryFromMachine(
            string(machine_code, length), error_msg);  // Keep the binary string

        infile.close();
        delete[] machine_code;

        return factory;
    } else {
        error_msg = "ERROR : cannot open '" + machine_code_path + "' file\n";
        return nullptr;
    }
}

LIBFAUST_API void writeWasmDSPFactoryToMachineFile(wasm_dsp_factory* factory,
                                                   const string&     machine_code_path)
{
    ofstream outfile;
    outfile.open(machine_code_path, ofstream::out | ofstream::binary);
    if (outfile.is_open()) {
        outfile << factory->getBinaryCode();
        outfile.close();
    } else {
        cerr << "writeWasmDSPFactoryToMachineFile : cannot open '" << machine_code_path
             << "' file\n";
    }
}

LIBFAUST_API wasm_dsp::wasm_dsp(wasm_dsp_factory* factory) : fFactory(factory)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        fDSP = EM_ASM_INT({ return AudioWorkletGlobalScope.faust_module._malloc($0); },
    fFactory->getDecoder()->getDSPSize()); #else fDSP = EM_ASM_INT({ return
    faust_module._malloc($0); }, fFactory->getDecoder()->getDSPSize()); #endif
    */
    // First instance builds the map
    if (fFactory->fMapUI.getParamsCount() == 0) {
        buildUserInterface(&fFactory->fMapUI);
    }
    // buildUserInterface(factory->fSoundUI);
}

LIBFAUST_API wasm_dsp::~wasm_dsp()
{
    /* Deactivated for 'wasm' branch version
        // Free the DSP memory
    #ifdef AUDIO_WORKLET
        EM_ASM({ AudioWorkletGlobalScope.faust_module._free($0); }, fDSP);
    #else
        EM_ASM({ faust_module._free($0); }, fDSP);
    #endif
    */
    wasm_dsp_factory::gWasmFactoryTable.removeDSP(fFactory, this);
}

LIBFAUST_API int wasm_dsp::getNumInputs()
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        return EM_ASM_INT({ return
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.getNumInputs($1); },
    fFactory->fInstance, fDSP); #else return EM_ASM_INT({ return
    faust_module.faust.wasm_instance[$0].exports.getNumInputs($1); }, fFactory->fInstance, fDSP);
    #endif
    */
    return -1;
}

LIBFAUST_API int wasm_dsp::getNumOutputs()
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        return EM_ASM_INT({ return
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.getNumOutputs($1); },
    fFactory->fInstance, fDSP); #else return EM_ASM_INT({ return
    faust_module.faust.wasm_instance[$0].exports.getNumOutputs($1); }, fFactory->fInstance, fDSP);
    #endif
    */
    return -1;
}

LIBFAUST_API void wasm_dsp::buildUserInterface(UI* ui_interface)
{
    fFactory->getDecoder()->buildUserInterface(ui_interface, reinterpret_cast<char*>(fDSP));
}

LIBFAUST_API int wasm_dsp::getSampleRate()
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        return EM_ASM_INT({ return
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.getSampleRate($1); },
    fFactory->fInstance, fDSP); #else return EM_ASM_INT({ return
    faust_module.faust.wasm_instance[$0].exports.getSampleRate($1); }, fFactory->fInstance, fDSP);
    #endif
    */
    return -1;
}

LIBFAUST_API void wasm_dsp::init(int sample_rate)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({ AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.init($1, $2);
    }, fFactory->fInstance, fDSP, sample_rate); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.init($1, $2); }, fFactory->fInstance, fDSP,
    sample_rate); #endif
    */
}

LIBFAUST_API void wasm_dsp::instanceInit(int sample_rate)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.instanceInit($1, $2); },
    fFactory->fInstance, fDSP, sample_rate); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.instanceInit($1, $2); }, fFactory->fInstance, fDSP,
    sample_rate); #endif
    */
}

LIBFAUST_API void wasm_dsp::instanceConstants(int sample_rate)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.instanceConstants($1, $2);
    }, fFactory->fInstance, fDSP, sample_rate); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.instanceConstants($1, $2); }, fFactory->fInstance,
    fDSP, sample_rate); #endif
    */
}

LIBFAUST_API void wasm_dsp::instanceResetUserInterface()
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.instanceResetUserInterface($1);
    }, fFactory->fInstance, fDSP); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.instanceResetUserInterface($1); },
    fFactory->fInstance, fDSP); #endif
    */
}

LIBFAUST_API void wasm_dsp::instanceClear()
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({
    AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.instanceClear($1); },
    fFactory->fInstance, fDSP); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.instanceClear($1); }, fFactory->fInstance, fDSP);
    #endif
    */
}

LIBFAUST_API wasm_dsp* wasm_dsp::clone()
{
    return fFactory->createDSPInstance();
}

LIBFAUST_API void wasm_dsp::metadata(Meta* m)
{
    fFactory->getDecoder()->metadata(m);
}

LIBFAUST_API void wasm_dsp::computeJS(int count, uintptr_t inputs, uintptr_t outputs)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({ AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.compute($1,
    $2, $3, $4); }, fFactory->fInstance, fDSP, count, inputs, outputs); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.compute($1, $2, $3, $4); }, fFactory->fInstance,
    fDSP, count, inputs, outputs); #endif
    */
}

LIBFAUST_API void wasm_dsp::compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs)
{
    /* Deactivated for 'wasm' branch version
    #ifdef AUDIO_WORKLET
        EM_ASM({ AudioWorkletGlobalScope.faust_module.faust.wasm_instance[$0].exports.compute($1,
    $2, $3, $4); }, fFactory->fInstance, fDSP, count, reinterpret_cast<uintptr_t>(inputs),
    reinterpret_cast<uintptr_t>(outputs)); #else EM_ASM({
    faust_module.faust.wasm_instance[$0].exports.compute($1, $2, $3, $4); }, fFactory->fInstance,
    fDSP, count, reinterpret_cast<uintptr_t>(inputs), reinterpret_cast<uintptr_t>(outputs)); #endif
    */
}

LIBFAUST_API void wasm_dsp::setParamValue(const string& path, FAUSTFLOAT value)
{
    fFactory->fMapUI.setParamValue(path, value);
}

LIBFAUST_API FAUSTFLOAT wasm_dsp::getParamValue(const string& path)
{
    return fFactory->fMapUI.getParamValue(path);
}

EMSCRIPTEN_BINDINGS(CLASS_wasm_dsp_factory)
{
    class_<wasm_dsp_factory>("wasm_dsp_factory")
        .constructor()
        .function("createDSPInstance", &wasm_dsp_factory::createDSPInstance, allow_raw_pointers())
        .function("deleteDSPInstance", &wasm_dsp_factory::deleteDSPInstance, allow_raw_pointers())
        .class_function("readWasmDSPFactoryFromMachineFile2",
                        &wasm_dsp_factory::readWasmDSPFactoryFromMachineFile2, allow_raw_pointers())
        .class_function("readWasmDSPFactoryFromMachine2",
                        &wasm_dsp_factory::readWasmDSPFactoryFromMachine2, allow_raw_pointers())
        .class_function("createWasmDSPFactory", &wasm_dsp_factory::createWasmDSPFactory,
                        allow_raw_pointers())
        .class_function("deleteWasmDSPFactory", &wasm_dsp_factory::deleteWasmDSPFactory2,
                        allow_raw_pointers())
        .class_function("getErrorMessage", &wasm_dsp_factory::getErrorMessage)
        .class_function("extractJSON", &wasm_dsp_factory::extractJSON, allow_raw_pointers());
}

EMSCRIPTEN_BINDINGS(CLASS_wasm_dsp)
{
    class_<wasm_dsp>("wasm_dsp")
        .constructor()
        // DSP API
        .function("getNumInputs", &wasm_dsp::getNumInputs, allow_raw_pointers())
        .function("getNumOutputs", &wasm_dsp::getNumOutputs, allow_raw_pointers())
        .function("getSampleRate", &wasm_dsp::getSampleRate, allow_raw_pointers())
        .function("init", &wasm_dsp::init, allow_raw_pointers())
        .function("instanceInit", &wasm_dsp::instanceInit, allow_raw_pointers())
        .function("instanceConstants", &wasm_dsp::instanceConstants, allow_raw_pointers())
        .function("instanceResetUserInterface", &wasm_dsp::instanceResetUserInterface,
                  allow_raw_pointers())
        .function("instanceClear", &wasm_dsp::instanceClear, allow_raw_pointers())
        .function("clone", &wasm_dsp::clone, allow_raw_pointers())
        .function("compute", &wasm_dsp::computeJS, allow_raw_pointers())
        // Additional JSON based API
        .function("setParamValue", &wasm_dsp::setParamValue, allow_raw_pointers())
        .function("getParamValue", &wasm_dsp::getParamValue, allow_raw_pointers());
}

#else

LIBFAUST_API wasm_dsp_factory::wasm_dsp_factory(int instance, const string& json)
{
    fFactory  = nullptr;
    fInstance = instance;
    fDecoder  = createJSONUIDecoder(json);
}

LIBFAUST_API wasm_dsp_factory::~wasm_dsp_factory()
{
    delete fFactory;
    delete fDecoder;
}

LIBFAUST_API wasm_dsp_factory* wasm_dsp_factory::createWasmDSPFactory(int           instance,
                                                                      const string& json)
{
    return nullptr;
}

LIBFAUST_API string wasm_dsp_factory::extractJSON(const string& code)
{
    return "";
}

LIBFAUST_API wasm_dsp_factory* readWasmDSPFactoryFromMachine(const string& machine_code,
                                                             string&       error_msg)
{
    return nullptr;
}

LIBFAUST_API string writeWasmDSPFactoryToMachine(wasm_dsp_factory* factory)
{
    return "";
}

LIBFAUST_API wasm_dsp_factory* readWasmDSPFactoryFromMachineFile(const string& machine_code_path,
                                                                 string&       error_msg)
{
    return nullptr;
}

LIBFAUST_API void writeWasmDSPFactoryToMachineFile(wasm_dsp_factory* factory,
                                                   const string&     machine_code_path)
{
}

LIBFAUST_API wasm_dsp::wasm_dsp(wasm_dsp_factory* factory) : fFactory(factory)
{
}

LIBFAUST_API wasm_dsp::~wasm_dsp()
{
    wasm_dsp_factory::gWasmFactoryTable.removeDSP(fFactory, this);
}

LIBFAUST_API int wasm_dsp::getNumInputs()
{
    return -1;
}

LIBFAUST_API int wasm_dsp::getNumOutputs()
{
    return -1;
}

LIBFAUST_API void wasm_dsp::buildUserInterface(UI* ui_interface)
{
}

LIBFAUST_API int wasm_dsp::getSampleRate()
{
    return -1;
}

LIBFAUST_API void wasm_dsp::init(int sample_rate)
{
}

LIBFAUST_API void wasm_dsp::instanceInit(int sample_rate)
{
}

LIBFAUST_API void wasm_dsp::instanceConstants(int sample_rate)
{
}

LIBFAUST_API void wasm_dsp::instanceResetUserInterface()
{
}

LIBFAUST_API void wasm_dsp::instanceClear()
{
}

LIBFAUST_API wasm_dsp* wasm_dsp::clone()
{
    return nullptr;
}

LIBFAUST_API void wasm_dsp::metadata(Meta* m)
{
}

LIBFAUST_API void wasm_dsp::compute(int count, FAUSTFLOAT** input, FAUSTFLOAT** output)
{
}

LIBFAUST_API void wasm_dsp::computeJS(int count, uintptr_t input, uintptr_t output)
{
}

LIBFAUST_API void wasm_dsp::setParamValue(const string& path, FAUSTFLOAT value)
{
}

LIBFAUST_API FAUSTFLOAT wasm_dsp::getParamValue(const string& path)
{
    return -1;
}

#endif

LIBFAUST_API wasm_dsp_factory::wasm_dsp_factory(dsp_factory_base* factory)
{
    fFactory = factory;
    fDecoder = nullptr;
}

LIBFAUST_API string wasm_dsp_factory::getName()
{
    return fFactory->getName();
}

LIBFAUST_API string wasm_dsp_factory::getSHAKey()
{
    return fFactory->getSHAKey();
}
LIBFAUST_API void wasm_dsp_factory::setSHAKey(const string& sha_key)
{
    fFactory->setSHAKey(sha_key);
}

LIBFAUST_API string wasm_dsp_factory::getDSPCode()
{
    return fFactory->getDSPCode();
}
LIBFAUST_API void wasm_dsp_factory::setDSPCode(const string& code)
{
    fFactory->setDSPCode(code);
}

LIBFAUST_API string wasm_dsp_factory::getCompileOptions()
{
    return fDecoder->getCompileOptions();
}

LIBFAUST_API vector<string> wasm_dsp_factory::getLibraryList()
{
    return fDecoder->getLibraryList();
}

LIBFAUST_API vector<string> wasm_dsp_factory::getIncludePathnames()
{
    return fDecoder->getIncludePathnames();
}

LIBFAUST_API vector<string> wasm_dsp_factory::getWarningMessages()
{
    return gWarningMessages;
}

LIBFAUST_API void wasm_dsp_factory::setMemoryManager(dsp_memory_manager* manager)
{
}

LIBFAUST_API dsp_memory_manager* wasm_dsp_factory::getMemoryManager()
{
    return nullptr;
}

LIBFAUST_API void wasm_dsp_factory::write(ostream* out, bool binary, bool small)
{
    fFactory->write(out, binary, small);
}

LIBFAUST_API void wasm_dsp_factory::writeHelper(ostream* out, bool binary, bool small)
{
    fFactory->writeHelper(out, binary, small);
}

LIBFAUST_API string wasm_dsp_factory::getBinaryCode()
{
    return fFactory->getBinaryCode();
}

LIBFAUST_API wasm_dsp* wasm_dsp_factory::createDSPInstance()
{
    wasm_dsp* dsp = new wasm_dsp(this);
    wasm_dsp_factory::gWasmFactoryTable.addDSP(this, dsp);
    return dsp;
}

LIBFAUST_API void wasm_dsp_factory::deleteDSPInstance(wasm_dsp* dsp)
{
    delete dsp;
}

// Static constructor

string wasm_dsp_factory::gErrorMessage = "";

LIBFAUST_API const string& wasm_dsp_factory::getErrorMessage()
{
    return wasm_dsp_factory::gErrorMessage;
}

LIBFAUST_API wasm_dsp_factory* wasm_dsp_factory::readWasmDSPFactoryFromMachineFile2(
    const string& machine_code_path)
{
    return readWasmDSPFactoryFromMachineFile(machine_code_path, wasm_dsp_factory::gErrorMessage);
}

LIBFAUST_API wasm_dsp_factory* wasm_dsp_factory::readWasmDSPFactoryFromMachine2(
    const string& machine_code)
{
    return readWasmDSPFactoryFromMachine(machine_code, wasm_dsp_factory::gErrorMessage);
}

LIBFAUST_API bool wasm_dsp_factory::deleteWasmDSPFactory2(wasm_dsp_factory* factory)
{
    return (factory) ? wasm_dsp_factory::gWasmFactoryTable.deleteDSPFactory(factory) : false;
}

// C++ API

LIBFAUST_API bool deleteWasmDSPFactory(wasm_dsp_factory* factory)
{
    return (factory) ? wasm_dsp_factory::gWasmFactoryTable.deleteDSPFactory(factory) : false;
}

LIBFAUST_API void deleteAllWasmDSPFactories()
{
    wasm_dsp_factory::gWasmFactoryTable.deleteAllDSPFactories();
}