Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
bump dependencies and add export for audiocontext getter
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Oct 14, 2020
1 parent 307c5b0 commit 5fe35e0
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 175 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,46 @@
"build:prod": "cross-env BUILD_TARGET=production rollup -c --environment production"
},
"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/core": "^7.12.0",
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
"@babel/plugin-transform-destructuring": "^7.10.4",
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"babel-plugin-add-module-exports": "^1.0.4",
"browser-or-node": "^1.3.0",
"cross-env": "^7.0.2",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint": "^7.11.0",
"eslint-config-prettier": "^6.12.0",
"eslint-config-standard": "^14.1.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-ramda": "^2.5.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-unicorn": "^21.0.0",
"ololog": "^1.1.161",
"rollup": "^2.26.8",
"eslint-plugin-unicorn": "^22.0.0",
"ololog": "^1.1.162",
"rollup": "^2.30.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-terser": "^7.0.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-pluginutils": "^2.8.2"
},
"dependencies": {
"@rollup/plugin-strip": "^2.0.0",
"@wasmer/wasi": "^0.11.2",
"@wasmer/wasm-transformer": "^0.11.2",
"@wasmer/wasmfs": "0.11.2",
"@wasmer/wasi": "^0.12.0",
"@wasmer/wasm-transformer": "^0.12.0",
"@wasmer/wasmfs": "0.12.0",
"buffer": "^5.6.0",
"comlink": "^4.3.0",
"pako": "^1.0.11",
"path-browserify": "^1.0.1",
"ramda": "^0.27.1",
"standardized-audio-context": "^25.1.0",
"standardized-audio-context": "^25.1.3",
"text-encoding-shim": "^1.0.5",
"unmute-ios-audio": "^3.1.0",
"web-midi-api": "^2.0.8"
Expand Down
34 changes: 18 additions & 16 deletions src/mains/sab.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ class SharedArrayBufferMainThread {
this.csoundPlayStateChangeCallbacks = [];

this.audioStateBuffer = new SharedArrayBuffer(
initialSharedState.length * Int32Array.BYTES_PER_ELEMENT
initialSharedState.length * Int32Array.BYTES_PER_ELEMENT,
);

this.audioStatePointer = new Int32Array(this.audioStateBuffer);

this.audioStreamIn = new SharedArrayBuffer(
MAX_CHANNELS * MAX_HARDWARE_BUFFER_SIZE * Float64Array.BYTES_PER_ELEMENT
MAX_CHANNELS * MAX_HARDWARE_BUFFER_SIZE * Float64Array.BYTES_PER_ELEMENT,
);
this.audioStreamOut = new SharedArrayBuffer(
MAX_CHANNELS * MAX_HARDWARE_BUFFER_SIZE * Float64Array.BYTES_PER_ELEMENT
MAX_CHANNELS * MAX_HARDWARE_BUFFER_SIZE * Float64Array.BYTES_PER_ELEMENT,
);

this.midiBufferSAB = new SharedArrayBuffer(
MIDI_BUFFER_SIZE * MIDI_BUFFER_PAYLOAD_SIZE * Int32Array.BYTES_PER_ELEMENT
MIDI_BUFFER_SIZE * MIDI_BUFFER_PAYLOAD_SIZE * Int32Array.BYTES_PER_ELEMENT,
);

this.midiBuffer = new Int32Array(this.midiBufferSAB);
Expand All @@ -57,7 +57,7 @@ class SharedArrayBufferMainThread {
handleMidiInput({ data: [status, data1, data2] }) {
const currentQueueLength = Atomics.load(
this.audioStatePointer,
AUDIO_STATE.AVAIL_RTMIDI_EVENTS
AUDIO_STATE.AVAIL_RTMIDI_EVENTS,
);
const rtmidiBufferIndex = Atomics.load(this.audioStatePointer, AUDIO_STATE.RTMIDI_INDEX);
const nextIndex =
Expand Down Expand Up @@ -132,7 +132,7 @@ class SharedArrayBufferMainThread {
case 'realtimePerformanceStarted': {
logSAB(
`event: realtimePerformanceStarted received,` +
` proceeding to call prepareRealtimePerformance`
` proceeding to call prepareRealtimePerformance`,
);
await this.prepareRealtimePerformance();
break;
Expand Down Expand Up @@ -163,7 +163,7 @@ class SharedArrayBufferMainThread {
console.error(error);
}

this.csoundPlayStateChangeCallbacks.forEach(callback => {
this.csoundPlayStateChangeCallbacks.forEach((callback) => {
try {
callback(newPlayState);
} catch (error) {
Expand All @@ -180,7 +180,7 @@ class SharedArrayBufferMainThread {
this.audioWorker.isRequestingInput = inputCount > 0;
this.audioWorker.isRequestingMidi = Atomics.load(
this.audioStatePointer,
AUDIO_STATE.IS_REQUESTING_RTMIDI
AUDIO_STATE.IS_REQUESTING_RTMIDI,
);

const sampleRate = Atomics.load(this.audioStatePointer, AUDIO_STATE.SAMPLE_RATE);
Expand Down Expand Up @@ -217,7 +217,7 @@ class SharedArrayBufferMainThread {
mainMessagePort.addEventListener('message', messageEventHandler(this));
mainMessagePortAudio.addEventListener('message', messageEventHandler(this));
logSAB(
`(postMessage) making a message channel from SABMain to SABWorker via workerMessagePort`
`(postMessage) making a message channel from SABMain to SABWorker via workerMessagePort`,
);
csoundWorker.postMessage({ msg: 'initMessagePort' }, [workerMessagePort]);

Expand All @@ -233,10 +233,10 @@ class SharedArrayBufferMainThread {
this.exportApi.setMessageCallback = this.setMessageCallback.bind(this);
this.exportApi.addMessageCallback = this.addMessageCallback.bind(this);
this.exportApi.setCsoundPlayStateChangeCallback = this.setCsoundPlayStateChangeCallback.bind(
this
this,
);
this.exportApi.addCsoundPlayStateChangeCallback = this.addCsoundPlayStateChangeCallback.bind(
this
this,
);

this.exportApi.csoundPause = this.csoundPause.bind(this);
Expand All @@ -248,6 +248,8 @@ class SharedArrayBufferMainThread {
this.exportApi.lsFs = makeProxyCallback(proxyPort, 'lsFs');
this.exportApi.rmrfFs = makeProxyCallback(proxyPort, 'rmrfFs');

this.exportApi.getAudioContext = async () => this.audioWorker.audioCtx;

for (const apiK of Object.keys(API)) {
const proxyCallback = makeProxyCallback(proxyPort, apiK);
const reference = API[apiK];
Expand All @@ -264,13 +266,13 @@ class SharedArrayBufferMainThread {
break;
}
case 'csoundStart': {
const csoundStart = async function(csound) {
const csoundStart = async function (csound) {
if (!csound || typeof csound !== 'number') {
console.error('csoundStart expects first parameter to be instance of Csound');
return -1;
}

await proxyCallback({
return await proxyCallback({
audioStateBuffer,
audioStreamIn,
audioStreamOut,
Expand All @@ -285,10 +287,10 @@ class SharedArrayBufferMainThread {
}

case 'csoundStop': {
const csoundStop = async csound => {
const csoundStop = async (csound) => {
logSAB(
"Checking if it's safe to call stop:",
stopableStates.has(this.currentPlayState)
stopableStates.has(this.currentPlayState),
);
if (stopableStates.has(this.currentPlayState)) {
logSAB("Marking SAB's state to STOP");
Expand All @@ -303,7 +305,7 @@ class SharedArrayBufferMainThread {
logSAB("stopping didn't cause the correct event to be triggered");
if (Atomics.load(this.audioStatePointer, AUDIO_STATE.STOP) === 0) {
logSAB(
'stopped state got reset to 0 (could be fatal, but also race condition)'
'stopped state got reset to 0 (could be fatal, but also race condition)',
);
Atomics.store(this.audioStatePointer, AUDIO_STATE.STOP, 1);
}
Expand Down
7 changes: 5 additions & 2 deletions src/mains/vanilla.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class VanillaWorkerMainThread {
this.exportApi.lsFs = makeProxyCallback(proxyPort, 'lsFs');
this.exportApi.rmrfFs = makeProxyCallback(proxyPort, 'rmrfFs');

this.exportApi.getAudioContext = async () => this.audioWorker.audioCtx;

for (const apiK of Object.keys(API)) {
const reference = API[apiK];
const proxyCallback = makeProxyCallback(proxyPort, apiK);
Expand All @@ -234,7 +236,7 @@ class VanillaWorkerMainThread {
]);
this.csoundWorker.postMessage({ msg: 'initRtMidiEventPort' }, [csoundWorkerRtMidiPort]);
logVAN(`4x message-ports sent to the worker`);
await proxyCallback({
return await proxyCallback({
audioStreamIn,
audioStreamOut,
midiBuffer,
Expand All @@ -256,7 +258,7 @@ class VanillaWorkerMainThread {
return -1;
}

await proxyCallback(csound);
const stopResult = await proxyCallback(csound);
if (this.currentPlayState === 'realtimePerformancePaused') {
try {
await proxyPort.callUncloned('csoundPerformKsmps', [csound]);
Expand All @@ -268,6 +270,7 @@ class VanillaWorkerMainThread {
if (this.currentPlayState !== 'realtimePerformanceEnded') {
await brodcastTheEnd();
}
return stopResult;
};
this.exportApi.csoundStop = csoundStop.bind(this);
csoundStop.toString = () => reference.toString();
Expand Down
Loading

0 comments on commit 5fe35e0

Please sign in to comment.