Skip to content

Commit

Permalink
Merge pull request #3 from olilarkin/master
Browse files Browse the repository at this point in the history
A few tidy-ings
  • Loading branch information
jariseon authored Sep 16, 2018
2 parents fa1f8e6 + 889c76c commit 3aaa9af
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
46 changes: 23 additions & 23 deletions wamsdk/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,54 @@ using namespace WAM;

EMSCRIPTEN_KEEPALIVE const char* Processor::init(uint32_t bufsize, uint32_t sr, void* desc)
{
m_bufsize = bufsize;
m_sr = sr;
return 0; // custom descriptor not defined at DSP side
m_bufsize = bufsize;
m_sr = sr;
return 0; // custom descriptor not defined at DSP side
}

// JavaScript glue
extern "C"
{
EMSCRIPTEN_KEEPALIVE const char* wam_init(Processor* proc, uint32_t bufsize, uint32_t sr, void* desc) { return proc->init(bufsize,sr,desc); }
EMSCRIPTEN_KEEPALIVE void wam_terminate(Processor* proc) { proc->terminate(); }
EMSCRIPTEN_KEEPALIVE void wam_resize(Processor* proc, uint32_t bufsize) { proc->resize(bufsize); }
EMSCRIPTEN_KEEPALIVE void wam_onparam(Processor* proc, uint32_t idparam, float value) { proc->onParam(idparam, value); }
EMSCRIPTEN_KEEPALIVE void wam_onmidi(Processor* proc, byte status, byte data1, byte data2) { proc->onMidi(status, data1, data2); }
EMSCRIPTEN_KEEPALIVE void wam_onsysex(Processor* proc, byte* msg, uint32_t size) { proc->onSysex(msg, size); }
EMSCRIPTEN_KEEPALIVE void wam_onprocess(Processor* proc, AudioBus* audio, void* data) { proc->onProcess(audio, data); }
EMSCRIPTEN_KEEPALIVE void wam_onpatch(Processor* proc, void* data, uint32_t size) { proc->onPatch(data, size); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageN(Processor* proc, char* verb, char* res, double data) { proc->onMessage(verb, res, data); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageS(Processor* proc, char* verb, char* res, char* data) { proc->onMessage(verb, res, data); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageA(Processor* proc, char* verb, char* res, void* data, uint32_t size) { proc->onMessage(verb, res, data, size); }
EMSCRIPTEN_KEEPALIVE const char* wam_init(Processor* proc, uint32_t bufsize, uint32_t sr, void* desc) { return proc->init(bufsize,sr,desc); }
EMSCRIPTEN_KEEPALIVE void wam_terminate(Processor* proc) { proc->terminate(); }
EMSCRIPTEN_KEEPALIVE void wam_resize(Processor* proc, uint32_t bufsize) { proc->resize(bufsize); }
EMSCRIPTEN_KEEPALIVE void wam_onparam(Processor* proc, uint32_t idparam, float value) { proc->onParam(idparam, value); }
EMSCRIPTEN_KEEPALIVE void wam_onmidi(Processor* proc, byte status, byte data1, byte data2) { proc->onMidi(status, data1, data2); }
EMSCRIPTEN_KEEPALIVE void wam_onsysex(Processor* proc, byte* msg, uint32_t size) { proc->onSysex(msg, size); }
EMSCRIPTEN_KEEPALIVE void wam_onprocess(Processor* proc, AudioBus* audio, void* data) { proc->onProcess(audio, data); }
EMSCRIPTEN_KEEPALIVE void wam_onpatch(Processor* proc, void* data, uint32_t size) { proc->onPatch(data, size); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageN(Processor* proc, char* verb, char* res, double data) { proc->onMessage(verb, res, data); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageS(Processor* proc, char* verb, char* res, char* data) { proc->onMessage(verb, res, data); }
EMSCRIPTEN_KEEPALIVE void wam_onmessageA(Processor* proc, char* verb, char* res, void* data, uint32_t size) { proc->onMessage(verb, res, data, size); }
}

void Processor::postMessage(const char* verb, const char* prop, const char* data)
{
EM_ASM({
var msg = {};
msg.verb = Module.Pointer_stringify($0);
msg.prop = Module.Pointer_stringify($1);
msg.data = Module.Pointer_stringify($2);
msg.verb = Module.Pointer_stringify($0);
msg.prop = Module.Pointer_stringify($1);
msg.data = Module.Pointer_stringify($2);
Module.port.postMessage(msg);
}, verb, prop, data);
}

void Processor::postMessage(const char* verb, const char* prop, void* data, uint32_t length)
void Processor::postMessage(const char* verb, const char* prop, const void* data, uint32_t length)
{
EM_ASM({
var arr = new Uint8Array($3);
arr.set(Module.HEAP8.subarray($2,$2+$3));
var msg = {};
msg.verb = Module.Pointer_stringify($0);
msg.prop = Module.Pointer_stringify($1);
msg.data = arr.buffer;
msg.verb = Module.Pointer_stringify($0);
msg.prop = Module.Pointer_stringify($1);
msg.data = arr.buffer;
Module.port.postMessage(msg);
}, verb, prop, data, length);
}

// for debugging
extern "C"
{
void wam_logs(const char* s) { EM_ASM_INT(Module.print(Pointer_stringify($0)), s); }
void wam_logi(int i) { EM_ASM_INT(Module.print($0), i); }
void wam_logs(const char* s) { EM_ASM_INT(Module.print(Pointer_stringify($0)), s); }
void wam_logi(int i) { EM_ASM_INT(Module.print($0), i); }
}
54 changes: 27 additions & 27 deletions wamsdk/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,56 @@
#include <stdint.h>

namespace WAM {
typedef unsigned char byte;
typedef struct
{
float** inputs;
float** outputs;
float** inputs;
float** outputs;
} AudioBus;


class Processor
{
// -- lifecycle
public:
Processor() {}
virtual const char* init(uint32_t bufsize, uint32_t sr, void* desc);
virtual void terminate() {}
virtual void resize(uint32_t bufsize) {}
virtual ~Processor() {}
Processor() {}
virtual const char* init(uint32_t bufsize, uint32_t sr, void* desc);
virtual void terminate() {}
virtual void resize(uint32_t bufsize) {}
virtual ~Processor() {}

// -- audio and data streams
public:
virtual void onProcess(WAM::AudioBus* audio, void* data) = 0;
virtual void onMidi(byte status, byte data1, byte data2) {}
virtual void onSysex(byte* msg, uint32_t size) {}
virtual void onMessage(char* verb, char* res, double data) {}
virtual void onMessage(char* verb, char* res, char* data) {}
virtual void onMessage(char* verb, char* res, void* data, uint32_t size) {}
virtual void onParam(uint32_t idparam, double value) {} // todo: other datatypes
virtual void onProcess(WAM::AudioBus* audio, void* data) = 0;
virtual void onMidi(byte status, byte data1, byte data2) {}
virtual void onSysex(byte* msg, uint32_t size) {}
virtual void onMessage(char* verb, char* res, double data) {}
virtual void onMessage(char* verb, char* res, char* data) {}
virtual void onMessage(char* verb, char* res, void* data, uint32_t size) {}
virtual void onParam(uint32_t idparam, double value) {} // todo: other datatypes
// -- patches
public:
virtual void onPatch(void* data, uint32_t size) {}
virtual void onPatch(void* data, uint32_t size) {}
// -- controller interface
protected:
void postMessage(const char* verb, const char* prop, const char* data);
void postMessage(const char* verb, const char* prop, void* data, uint32_t length);
void postMessage(const char* verb, const char* prop, const char* data);
void postMessage(const char* verb, const char* prop, const void* data, uint32_t length);
protected:
uint32_t m_bufsize;
uint32_t m_sr;
int m_inChannels;
int m_outChannels;
uint32_t m_bufsize;
uint32_t m_sr;
int m_inChannels;
int m_outChannels;
};

// for debugging
extern "C"
{
void wam_logs(const char* s);
void wam_logi(int i);
void wam_logs(const char* s);
void wam_logi(int i);
}

} // namespace WAM
Expand Down
10 changes: 5 additions & 5 deletions wamsdk/wam-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WAMProcessor extends AudioWorkletProcessor
if (options.numberOfInputs === undefined) options.numberOfInputs = 0;
if (options.numberOfOutputs === undefined) options.numberOfOutputs = 1;
if (options.inputChannelCount === undefined) options.inputChannelCount = [];
if (options.outputChannelCount === undefined) options.outputChannelCount = [1];
if (options.outputChannelCount === undefined) options.outputChannelCount = [2];
if (options.inputChannelCount.length != options.numberOfInputs) throw new Error("InvalidArgumentException");
if (options.outputChannelCount.length != options.numberOfOutputs) throw new Error("InvalidArgumentException");

Expand Down Expand Up @@ -70,7 +70,7 @@ class WAMProcessor extends AudioWorkletProcessor
this.audiobufs[0].push(buf/4);
}
for (var i=0; i<this.numOutputs; i++) {
var numChannels = 2; // this.numOutChannels[i];
var numChannels = this.numOutChannels[i];
for (var c=0; c<numChannels; c++) {
var buf = WAM._malloc( this.bufsize*4 );
WAM.setValue(obufs + (i*numChannels+c)*4, buf, 'i32');
Expand Down Expand Up @@ -137,14 +137,14 @@ class WAMProcessor extends AudioWorkletProcessor
WAM._free(buf);
}

onsysex (data) {
onsysex (data) {
var WAM = this.WAM;
var buf = WAM._malloc(data.length);
for (var i = 0; i < data.length; i++)
WAM.setValue(buf+i, data[i], 'i8');
this.wam_onsysex(this.inst, buf, data.length);
this.wam_onsysex(this.inst, buf, data.length);
WAM._free(buf);
}
}

process (inputs,outputs,params) {
var WAM = this.WAM;
Expand Down

0 comments on commit 3aaa9af

Please sign in to comment.