mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-13 06:19:33 -04:00
working
This commit is contained in:
@@ -580,7 +580,7 @@ export const superdough = async (value, t, hapDuration, cps) => {
|
||||
// get source AudioNode
|
||||
let sourceNode;
|
||||
if (source) {
|
||||
sourceNode = source(t, value, hapDuration,cps);
|
||||
sourceNode = source(t, value, hapDuration, cps);
|
||||
} else if (getSound(s)) {
|
||||
const { onTrigger } = getSound(s);
|
||||
const onEnded = () => {
|
||||
|
||||
@@ -147,13 +147,9 @@ export function registerSynthSounds() {
|
||||
registerSound(
|
||||
'bytebeat',
|
||||
(begin, value, onended) => {
|
||||
const defaultBeats = [
|
||||
'(t%255 >= t/255%255)*255',
|
||||
'(t*(t*8%60 <= 300)|(-t)*(t*4%512 < 256))+t/400',
|
||||
't',
|
||||
]
|
||||
const { n } = value
|
||||
const { byteBeatExpression = defaultBeats[n % defaultBeats.length] } = value
|
||||
const defaultBeats = ['(t%255 >= t/255%255)*255', '(t*(t*8%60 <= 300)|(-t)*(t*4%512 < 256))+t/400', 't'];
|
||||
const { n } = value;
|
||||
const { byteBeatExpression = defaultBeats[n % defaultBeats.length] } = value;
|
||||
const ac = getAudioContext();
|
||||
|
||||
let { duration } = value;
|
||||
|
||||
@@ -767,11 +767,12 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||
super();
|
||||
this.codeText = '0';
|
||||
this.port.onmessage = (event) => {
|
||||
|
||||
this.codeText = event.data.trim().replace(
|
||||
/^eval\(unescape\(escape(?:`|\('|\("|\(`)(.*?)(?:`|'\)|"\)|`\)).replace\(\/u\(\.\.\)\/g,["'`]\$1%["'`]\)\)\)$/,
|
||||
(match, m1) => unescape(escape(m1).replace(/u(..)/g, '$1%')));
|
||||
|
||||
this.codeText = event.data
|
||||
.trim()
|
||||
.replace(
|
||||
/^eval\(unescape\(escape(?:`|\('|\("|\(`)(.*?)(?:`|'\)|"\)|`\)).replace\(\/u\(\.\.\)\/g,["'`]\$1%["'`]\)\)\)$/,
|
||||
(match, m1) => unescape(escape(m1).replace(/u(..)/g, '$1%')),
|
||||
);
|
||||
};
|
||||
this.virtualRate = 112600; // target sample rate
|
||||
// this.nativeRate = sampleRate; // actual context rate, e.g., 48000
|
||||
@@ -820,33 +821,30 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||
return false;
|
||||
}
|
||||
if (this.t == null) {
|
||||
this.t = params.begin[0] * this.virtualRate
|
||||
this.t = params.begin[0] * this.virtualRate;
|
||||
}
|
||||
|
||||
let codeText = this.codeText;
|
||||
this.func = Function('t', 'return ' + codeText);
|
||||
const output = outputs[0];
|
||||
const tIncrement = this.virtualRate / sampleRate
|
||||
|
||||
const tIncrement = this.virtualRate / sampleRate;
|
||||
|
||||
for (let i = 0; i < output[0].length; i++) {
|
||||
let t = Math.floor(this.t)
|
||||
let t = Math.floor(this.t);
|
||||
const detune = getParamValue(i, params.detune);
|
||||
const freq = applySemitoneDetuneToFrequency(getParamValue(i, params.frequency), detune / 100);
|
||||
|
||||
t = t / (this.virtualRate / 256) * freq
|
||||
t = (t / (this.virtualRate / 256)) * freq;
|
||||
|
||||
const funcValue = this.func(t)
|
||||
let signal = (funcValue & 255) / 127.5 - 1
|
||||
const funcValue = this.func(t);
|
||||
let signal = (funcValue & 255) / 127.5 - 1;
|
||||
const out = signal;
|
||||
for (let c = 0; c < output.length; c++) {
|
||||
output[c][i] = out;
|
||||
}
|
||||
this.t = this.t + tIncrement
|
||||
|
||||
this.t = this.t + tIncrement;
|
||||
}
|
||||
|
||||
|
||||
return true; // keep the audio processing going
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user