Working version of supersaw, almost on wavetable
This commit is contained in:
parent
600ab0a83e
commit
6610713018
4 changed files with 22 additions and 5 deletions
|
|
@ -38,6 +38,10 @@ export const releaseNodeToPool = (node) => {
|
||||||
// not reusable
|
// not reusable
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (node[IS_WORKLET_DEAD]) {
|
||||||
|
// Worklet already terminated, don't pool it
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Fallback to a type-based key if the node was not created via getNodeFromPool
|
// Fallback to a type-based key if the node was not created via getNodeFromPool
|
||||||
const key = node[POOL_KEY];
|
const key = node[POOL_KEY];
|
||||||
if (key == null) return;
|
if (key == null) return;
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,9 @@ export function registerSynthSounds() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
o.port.postMessage({ type: 'initialize' });
|
o.port.postMessage({ type: 'initialize' });
|
||||||
o.port.onMessage = (e) => {
|
o.port.onmessage = (e) => {
|
||||||
if (e.data.type === 'died') markWorkletAsDead(o);
|
if (e.data.type === 'died') markWorkletAsDead(o);
|
||||||
|
o.port.onmessage = null;
|
||||||
};
|
};
|
||||||
const gainAdjustment = 1 / Math.sqrt(voices);
|
const gainAdjustment = 1 / Math.sqrt(voices);
|
||||||
getPitchEnvelope(o.parameters.get('detune'), value, begin, holdend);
|
getPitchEnvelope(o.parameters.get('detune'), value, begin, holdend);
|
||||||
|
|
|
||||||
|
|
@ -244,8 +244,9 @@ export async function onTriggerSynth(t, value, onended, tables, cps, frameLen) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
source.port.postMessage({ type: 'initialize', payload });
|
source.port.postMessage({ type: 'initialize', payload });
|
||||||
source.port.onMessage = (e) => {
|
source.port.onmessage = (e) => {
|
||||||
if (e.data.type === 'died') markWorkletAsDead(source);
|
if (e.data.type === 'died') markWorkletAsDead(source);
|
||||||
|
source.port.onmessage = null;
|
||||||
};
|
};
|
||||||
if (ac.currentTime > t) {
|
if (ac.currentTime > t) {
|
||||||
logger(`[wavetable] still loading sound "${s}:${n}"`, 'highlight');
|
logger(`[wavetable] still loading sound "${s}:${n}"`, 'highlight');
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,7 @@ registerProcessor('distort-processor', DistortProcessor);
|
||||||
class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
this.isAlive = true; // used internally to prevent multiple death messages
|
||||||
this.port.onmessage = (e) => {
|
this.port.onmessage = (e) => {
|
||||||
const { type, payload } = e.data || {};
|
const { type, payload } = e.data || {};
|
||||||
if (type === 'initialize') {
|
if (type === 'initialize') {
|
||||||
|
|
@ -519,6 +520,10 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
process(_input, outputs, params) {
|
process(_input, outputs, params) {
|
||||||
if (currentTime >= params.end[0]) {
|
if (currentTime >= params.end[0]) {
|
||||||
// should terminate
|
// should terminate
|
||||||
|
if (this.isAlive) {
|
||||||
|
this.port.postMessage({ type: 'died' });
|
||||||
|
this.isAlive = false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (currentTime <= params.begin[0]) {
|
if (currentTime <= params.begin[0]) {
|
||||||
|
|
@ -1144,6 +1149,7 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
this.isAlive = true; // used internally to prevent multiple death messages
|
||||||
this.port.onmessage = (e) => {
|
this.port.onmessage = (e) => {
|
||||||
const { type, payload } = e.data || {};
|
const { type, payload } = e.data || {};
|
||||||
if (type === 'initialize') {
|
if (type === 'initialize') {
|
||||||
|
|
@ -1153,8 +1159,9 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
initialize(options) {
|
initialize(options) {
|
||||||
this.frameLen = 0;
|
this.table = null;
|
||||||
this.numFrames = 0;
|
this.frameLen = null;
|
||||||
|
this.numFrames = null;
|
||||||
this.phase = [];
|
this.phase = [];
|
||||||
if (options?.frames) {
|
if (options?.frames) {
|
||||||
const key = options.key;
|
const key = options.key;
|
||||||
|
|
@ -1311,6 +1318,10 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
|
|
||||||
process(_inputs, outputs, parameters) {
|
process(_inputs, outputs, parameters) {
|
||||||
if (currentTime >= parameters.end[0]) {
|
if (currentTime >= parameters.end[0]) {
|
||||||
|
if (this.isAlive) {
|
||||||
|
this.port.postMessage({ type: 'died' });
|
||||||
|
this.isAlive = false;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (currentTime <= parameters.begin[0]) {
|
if (currentTime <= parameters.begin[0]) {
|
||||||
|
|
@ -1318,7 +1329,7 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
|
||||||
}
|
}
|
||||||
const outL = outputs[0][0];
|
const outL = outputs[0][0];
|
||||||
const outR = outputs[0][1] || outputs[0][0];
|
const outR = outputs[0][1] || outputs[0][0];
|
||||||
if (!this.tables) {
|
if (!this.table) {
|
||||||
outL.fill(0);
|
outL.fill(0);
|
||||||
if (outR !== outL) outR.set(outL);
|
if (outR !== outL) outR.set(outL);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue