sync without cyclist changes

This commit is contained in:
Jade (Rose) Rowland 2025-07-06 00:59:39 -04:00
parent 077556e7cb
commit d9e44dcda6
8 changed files with 261 additions and 82 deletions

View file

@ -45,6 +45,8 @@ export function setGainCurve(newGainCurveFunc) {
gainCurveFunc = newGainCurveFunc;
}
function aliasBankMap(aliasMap) {
// Make all bank keys lower case for case insensitivity
for (const key in aliasMap) {
@ -325,12 +327,29 @@ function getDelay(orbit, delaytime, delayfeedback, t, channels) {
return delays[orbit];
}
export function getLfo(audioContext, time, end, properties = {}) {
export function getLfo(audioContext, begin, end, properties = {}) {
return getWorklet(audioContext, 'lfo-processor', {
frequency: 1,
depth: 1,
skew: 0,
phaseoffset: 0,
time: begin,
begin,
end,
shape: 1,
dcoffset: -0.5,
...properties,
});
}
export function getSyncedLfo(audioContext, time, end, cps, cycle, properties = {}) {
const frequency = cycle/cps
return getWorklet(audioContext, 'lfo-processor', {
frequency,
depth: 1,
skew: 0,
phaseoffset: 0,
time,
end,
shape: 1,
@ -450,9 +469,10 @@ function mapChannelNumbers(channels) {
return (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1);
}
export const superdough = async (value, t, hapDuration, cps = 0.5) => {
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle) => {
// new: t is always expected to be the absolute target onset time
const ac = getAudioContext();
let { stretch } = value;
if (stretch != null) {
//account for phase vocoder latency
@ -707,11 +727,12 @@ export const superdough = async (value, t, hapDuration, cps = 0.5) => {
coarse !== undefined && chain.push(getWorklet(ac, 'coarse-processor', { coarse }));
crush !== undefined && chain.push(getWorklet(ac, 'crush-processor', { crush }));
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape, postgain: shapevol }));
distort !== undefined && chain.push(getWorklet(ac, 'distort-processor', { distort, postgain: distortvol }));
// distort !== undefined && chain.push(getWorklet(ac, 'distort-processor', { distort, postgain: distortvol }));
// am !== undefined &&
// chain.push(
// getWorklet(ac, 'am-processor', {
// speed: am,
// begin: t,
// depth: amdepth,
// skew: amskew,
// phaseoffset: amphase,
@ -724,12 +745,21 @@ export const superdough = async (value, t, hapDuration, cps = 0.5) => {
if (am !== undefined) {
const amGain = new GainNode(ac, { gain: 1 });
const frequency = cycleToSeconds(am, cps)
const frequency = cps / am
const phaseoffset = cycleToSeconds(amphase, cps)
const time = cycle / cps
// console.info(cycle, time, frequency)
const lfo = getLfo(ac, t, t + hapDuration, {
skew: amskew,
frequency: am * cps,
depth: amdepth,
frequency,
depth: amdepth,
time,
// dcoffset: 0,
shape: amshape,
phaseoffset

View file

@ -85,6 +85,7 @@ const waveShapeNames = Object.keys(waveshapes);
class LFOProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [
{ name: 'begin', defaultValue: 0 },
{ name: 'time', defaultValue: 0 },
{ name: 'end', defaultValue: 0 },
{ name: 'frequency', defaultValue: 0.5 },
@ -109,10 +110,14 @@ class LFOProcessor extends AudioWorkletProcessor {
}
process(inputs, outputs, parameters) {
const begin = parameters['begin'][0]
// eslint-disable-next-line no-undef
if (currentTime >= parameters.end[0]) {
return false;
}
if (currentTime <= begin) {
return true;
}
const output = outputs[0];
const frequency = parameters['frequency'][0];
@ -159,6 +164,8 @@ class CoarseProcessor extends AudioWorkletProcessor {
const input = inputs[0];
const output = outputs[0];
const hasInput = !(input[0] === undefined);
if (this.started && !hasInput) {
return false;
@ -899,6 +906,7 @@ registerProcessor('byte-beat-processor', ByteBeatProcessor);
class AMProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [
{ name: 'begin', defaultValue: 0 },
{ name: 'cps', defaultValue: 0.5 },
{ name: 'speed', defaultValue: 0.5 },
{ name: 'cycle', defaultValue: 0 },
@ -925,10 +933,15 @@ class AMProcessor extends AudioWorkletProcessor {
const input = inputs[0];
const output = outputs[0];
const hasInput = !(input[0] === undefined);
if (this.started && !hasInput) {
return false;
}
this.started = hasInput;
if (currentTime <= parameters.begin[0]) {
return true;
}
const speed = parameters['speed'][0];
const cps = parameters['cps'][0];
@ -937,7 +950,7 @@ class AMProcessor extends AudioWorkletProcessor {
const skew = parameters['skew'][0];
const phaseoffset = parameters['phaseoffset'][0];
const frequency = speed * cps;
const frequency = cps / speed
if (this.phase == null) {
const secondsPassed = cycle / cps;
this.phase = _mod(secondsPassed * frequency + phaseoffset, 1);