baasic csound output

This commit is contained in:
Felix Roos 2022-11-29 00:05:51 +01:00
parent 43aa2247f1
commit eab86840d3
4 changed files with 1495 additions and 284 deletions

1744
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
import { Pattern } from '@strudel.cycles/core';
import { Csound } from '@csound/browser'; // TODO: use dynamic import for code splitting..
import csd from './sounds.csd?raw';
import { getAudioContext } from '@strudel.cycles/webaudio';
let csoundLoader;
Pattern.prototype.csound = async function () {
if (!csoundLoader) {
csoundLoader = (async () => {
const csound = await Csound({ audioContext: getAudioContext() });
await csound.setOption('-m0');
await csound.compileCsdText(csd);
await csound.setControlChannel('main.note.amp', -12);
await csound.start();
return csound;
})();
}
const csound = await csoundLoader;
return this.onTrigger((time, hap, currentTime) => {
const { gain = 0.8 } = hap.value;
const deadline = time - currentTime;
const midi = toMidi(getPlayableNoteValue(hap));
// TODO: find out how to send a precise ctx based time
const ctime = `next_time(.000001)+${deadline.toFixed(6)}`;
// const ctime = `${deadline.toFixed(6)}`;
const cmidi = `cpsmidinn(${midi})`;
const cgain = gain ? `ampdbfs(-32 + 32*${gain})` : `0`;
const code = `schedule(1, ${ctime}, .125, ${cmidi}, ${cgain})`;
csound.evalCode(code);
});
};

View File

@ -2,7 +2,7 @@
"name": "@strudel.cycles/csound",
"version": "0.3.0",
"description": "csound bindings for strudel",
"main": "index.mjs",
"main": "csound.mjs",
"scripts": {
"test": "echo \"No tests present.\" && exit 0"
},

View File

@ -42,6 +42,7 @@ const modules = [
import('@strudel.cycles/osc'),
import('@strudel.cycles/serial'),
import('@strudel.cycles/soundfonts'),
import('@strudel.cycles/csound'),
];
evalScope(