working
This commit is contained in:
parent
366637026b
commit
63f4f202f1
3 changed files with 17 additions and 23 deletions
|
|
@ -580,7 +580,7 @@ export const superdough = async (value, t, hapDuration, cps) => {
|
||||||
// get source AudioNode
|
// get source AudioNode
|
||||||
let sourceNode;
|
let sourceNode;
|
||||||
if (source) {
|
if (source) {
|
||||||
sourceNode = source(t, value, hapDuration,cps);
|
sourceNode = source(t, value, hapDuration, cps);
|
||||||
} else if (getSound(s)) {
|
} else if (getSound(s)) {
|
||||||
const { onTrigger } = getSound(s);
|
const { onTrigger } = getSound(s);
|
||||||
const onEnded = () => {
|
const onEnded = () => {
|
||||||
|
|
|
||||||
|
|
@ -147,13 +147,9 @@ export function registerSynthSounds() {
|
||||||
registerSound(
|
registerSound(
|
||||||
'bytebeat',
|
'bytebeat',
|
||||||
(begin, value, onended) => {
|
(begin, value, onended) => {
|
||||||
const defaultBeats = [
|
const defaultBeats = ['(t%255 >= t/255%255)*255', '(t*(t*8%60 <= 300)|(-t)*(t*4%512 < 256))+t/400', 't'];
|
||||||
'(t%255 >= t/255%255)*255',
|
const { n } = value;
|
||||||
'(t*(t*8%60 <= 300)|(-t)*(t*4%512 < 256))+t/400',
|
const { byteBeatExpression = defaultBeats[n % defaultBeats.length] } = value;
|
||||||
't',
|
|
||||||
]
|
|
||||||
const { n } = value
|
|
||||||
const { byteBeatExpression = defaultBeats[n % defaultBeats.length] } = value
|
|
||||||
const ac = getAudioContext();
|
const ac = getAudioContext();
|
||||||
|
|
||||||
let { duration } = value;
|
let { duration } = value;
|
||||||
|
|
|
||||||
|
|
@ -767,11 +767,12 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||||
super();
|
super();
|
||||||
this.codeText = '0';
|
this.codeText = '0';
|
||||||
this.port.onmessage = (event) => {
|
this.port.onmessage = (event) => {
|
||||||
|
this.codeText = event.data
|
||||||
this.codeText = event.data.trim().replace(
|
.trim()
|
||||||
/^eval\(unescape\(escape(?:`|\('|\("|\(`)(.*?)(?:`|'\)|"\)|`\)).replace\(\/u\(\.\.\)\/g,["'`]\$1%["'`]\)\)\)$/,
|
.replace(
|
||||||
(match, m1) => unescape(escape(m1).replace(/u(..)/g, '$1%')));
|
/^eval\(unescape\(escape(?:`|\('|\("|\(`)(.*?)(?:`|'\)|"\)|`\)).replace\(\/u\(\.\.\)\/g,["'`]\$1%["'`]\)\)\)$/,
|
||||||
|
(match, m1) => unescape(escape(m1).replace(/u(..)/g, '$1%')),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
this.virtualRate = 112600; // target sample rate
|
this.virtualRate = 112600; // target sample rate
|
||||||
// this.nativeRate = sampleRate; // actual context rate, e.g., 48000
|
// this.nativeRate = sampleRate; // actual context rate, e.g., 48000
|
||||||
|
|
@ -820,33 +821,30 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.t == null) {
|
if (this.t == null) {
|
||||||
this.t = params.begin[0] * this.virtualRate
|
this.t = params.begin[0] * this.virtualRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
let codeText = this.codeText;
|
let codeText = this.codeText;
|
||||||
this.func = Function('t', 'return ' + codeText);
|
this.func = Function('t', 'return ' + codeText);
|
||||||
const output = outputs[0];
|
const output = outputs[0];
|
||||||
const tIncrement = this.virtualRate / sampleRate
|
const tIncrement = this.virtualRate / sampleRate;
|
||||||
|
|
||||||
|
|
||||||
for (let i = 0; i < output[0].length; i++) {
|
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 detune = getParamValue(i, params.detune);
|
||||||
const freq = applySemitoneDetuneToFrequency(getParamValue(i, params.frequency), detune / 100);
|
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)
|
const funcValue = this.func(t);
|
||||||
let signal = (funcValue & 255) / 127.5 - 1
|
let signal = (funcValue & 255) / 127.5 - 1;
|
||||||
const out = signal;
|
const out = signal;
|
||||||
for (let c = 0; c < output.length; c++) {
|
for (let c = 0; c < output.length; c++) {
|
||||||
output[c][i] = out;
|
output[c][i] = out;
|
||||||
}
|
}
|
||||||
this.t = this.t + tIncrement
|
this.t = this.t + tIncrement;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true; // keep the audio processing going
|
return true; // keep the audio processing going
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue