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

Commit

Permalink
fix buffer not found error plus cleanup compile script
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Jul 24, 2020
1 parent 38de93b commit dd44e33
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
- name: Test
run: yarn lint
- name: Compile csound natively to wasm
run: nix build '(with import <nixpkgs> {}; import ./nix/native/compile.nix)' -o lib
run: yarn compile
- name: Build javascript bundle
run: nix build '(with import <nixpkgs> {}; import ./nix/nodejs/build.nix)' -o dist
run: yarn build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ libcsound.wasm
github-prefetch.json
src/worklet.bundle.js
result
result-dev
result_*
lib
dist
deps.js
Expand Down
13 changes: 13 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash


nix build '(with import <nixpkgs> {}; import ./nix/native/compile.nix)' -o result_compile &&
if [ -d "./lib" ]; then
printf '%s\n' "Cleaning directory lib"
rm -rf "./lib"
fi &&
mkdir lib &&
cp ./result_compile/* lib &&
chmod 0600 lib/*

printf '%s\n' "wasm binary ready in ./lib"
14 changes: 10 additions & 4 deletions nix/native/libcsound_objects.nix
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,24 @@ pkgs.callPackage
--replace 'static double timeResolutionSeconds = -1.0;' \
'static double timeResolutionSeconds = 0.000001;'
substituteInPlace InOut/libsnd.c \
--replace 'fullName = csoundFindOutputFile(csound, fName, "SFDIR");' \
'fullName = csoundFindOutputFile(csound, fName, "SFDIR"); printf("FULL NAME: %s fName: %s\n", fullName, fName);'
# substituteInPlace InOut/libsnd.c \
# --replace 'fullName = csoundFindOutputFile(csound, fName, "SFDIR");' \
# 'fullName = csoundConcatenatePaths(csound, "/csound", fName);'
# --replace 'char *csoundFindOutputFile(CSOUND *csound,' \
# 'char *csoundFindOutputFile_DISALBED(CSOUND *csound,' \
substituteInPlace Engine/envvar.c \
--replace 'fd = csoundFindFile_Fd(csound, &name_found, filename, 1, envList);' \
'fd = csoundFindFile_Fd(csound, &name_found, filename, 1, envList); printf("fd: %d envList %s \n", fd, envList);' \
--replace 'return name;' \
'char* fsPrefix = csound->Malloc(
csound, (size_t) strlen(name) + 9);
strcpy(fsPrefix, (name[0] == DIRSEP) ? "/csound" : "/csound/");
strcat(fsPrefix, name);
printf("FILENAME: %s FSPREFIX: %s\n", filename, fsPrefix);
return fsPrefix;' \
--replace 'fd = open(name, WR_OPTS);' \
'fd = open(name, O_RDWR);' \
--replace 'fd = open(name, RD_OPTS);' \
'fd = open(name, O_RDONLY);' \
--replace '#define RD_OPTS O_RDONLY | O_BINARY, 0' \
Expand Down
17 changes: 0 additions & 17 deletions nix/nodejs/build.nix

This file was deleted.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "csound-wasm",
"version": "6.14.0-alpha17",
"version": "6.14.0-alpha20",
"author": "Hlödver Sigurdsson <[email protected]>",
"license": "LGPL-3.0",
"main": "./dist/libcsound.mjs",
Expand All @@ -15,11 +15,9 @@
"wasi"
],
"scripts": {
"compile": "nix build '(with import <nixpkgs> {}; import ./nix/native/compile.nix)' -o lib",
"compile:debug": "nix-shell nix/native/compile.nix --arg debug true",
"compile:dev": "nix-shell nix/compile.nix --arg debug true --arg dev true",
"compile": "bash compile.sh",
"lint": "eslint 'src/**/*.js'",
"build": "nix build '(with import <nixpkgs> {}; import ./nix/nodejs/build.nix)' -o dist"
"build": "rollup -c"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as R from 'ramda';

const globals = {
comlink: 'Comlink',
buffer: 'Buffer',
};

const pluginsCommon = [
Expand Down
5 changes: 3 additions & 2 deletions src/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const wasmFs = new WasmFs();

export const preopens = {
'/': '/',
// '/csound': '/',
};

export const workerMessagePort = {
Expand Down Expand Up @@ -100,8 +101,8 @@ export async function mkdirp(filePath) {
});
}

export const intiFS = async () => {
await wasmFs.volume.mkdirSync('/csound');
export const initFS = async () => {
wasmFs.volume.mkdirSync('/csound');
createStdErrorStream();
createStdOutStream();
};
4 changes: 2 additions & 2 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { WASI } from '@wasmer/wasi';
import browserBindings from '@wasmer/wasi/lib/bindings/browser';
import { lowerI64Imports } from '@wasmer/wasm-transformer';
import { inflate } from 'pako';
import { intiFS, preopens, wasmFs } from '@root/filesystem';
import { initFS, preopens, wasmFs } from '@root/filesystem';
import * as path from 'path';

export const bindings = {
Expand All @@ -24,7 +24,7 @@ export default async function(wasmDataURI) {
const module = await WebAssembly.compile(transformedBinary);
const options = wasi.getImports(module);
const instance = await WebAssembly.instantiate(module, options);
intiFS();
wasi.start(instance);
await initFS();
return instance;
}
2 changes: 1 addition & 1 deletion src/workers/common.utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const handleCsoundStart = (workerMessagePort, libraryCsound, createRealtimeAudioThread) => arguments_ => {
const { csound } = arguments_;
// account for slash csound in wasi-memfs system
libraryCsound.csoundAppendEnv(csound, 'SFDIR', '/csound');
// libraryCsound.csoundAppendEnv(csound, 'SFDIR', '/csound');
const startError = libraryCsound.csoundStart(csound);
const outputName = libraryCsound.csoundGetOutputName(csound) || 'test.wav';

Expand Down
2 changes: 1 addition & 1 deletion src/workers/sab.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const sabCreateRealtimeAudioThread = ({ audioStateBuffer, audioStreamIn, audioSt
Atomics.store(audioStatePointer, AUDIO_STATE.IS_PERFORMING, 1);
workerMessagePort.broadcastPlayState('realtimePerformanceStarted');

while (Atomics.wait(audioStatePointer, AUDIO_STATE.ATOMIC_NOTIFY, 0) === 'ok') {
while (Atomics.wait(audioStatePointer, AUDIO_STATE.ATOMIC_NOTIFY, 0, 1000) === 'ok') {
if (Atomics.load(audioStatePointer, AUDIO_STATE.STOP) === 1) {
libraryCsound.csoundStop(csound);
// Trigger "performance ended"
Expand Down

0 comments on commit dd44e33

Please sign in to comment.