Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 3d37c73

Browse files
committed
fixed
1 parent 1d18976 commit 3d37c73

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

packages/core/controls.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,9 @@ export const { byteBeatExpression, bbexpr } = registerControl('byteBeatExpressio
464464
* @name byteBeatStartTime
465465
* @synonyms bbst
466466
*
467-
* @param {number | Pattern} byteBeatStartTime in seconds
467+
* @param {number | Pattern} byteBeatStartTime in samples (t)
468468
* @example
469-
* note("{c g a b c d}%16").s("bytebeat").bbexpr('t&t>>8').bbst("<0 300>")
469+
* note("c3!8".add("{0 0 12 0 7 5 3}%8")).s("bytebeat:5").bbst("<3 1>".mul(10000))._scope()
470470
*
471471
*/
472472
export const { byteBeatStartTime, bbst } = registerControl('byteBeatStartTime', 'bbst');

packages/superdough/synth.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function registerSynthSounds() {
192192
},
193193
);
194194

195-
o.port.postMessage({ codeText: byteBeatExpression, startTimeSeconds: byteBeatStartTime, frequency });
195+
o.port.postMessage({ codeText: byteBeatExpression, byteBeatStartTime, frequency });
196196

197197
let envGain = gainNode(1);
198198
envGain = o.connect(envGain);

packages/superdough/worklets.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,10 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
811811
super();
812812
this.port.onmessage = (event) => {
813813
let { codeText } = event.data;
814-
const { startTimeSeconds, frequency } = event.data;
815-
if (startTimeSeconds != null) {
816-
const t = startTimeSeconds * sampleRate;
817-
this.t = t;
818-
this.t = (t / (sampleRate / 256)) * frequency;
814+
const { byteBeatStartTime } = event.data;
815+
if (byteBeatStartTime != null) {
816+
this.t = 0
817+
this.initialOffset = Math.floor(byteBeatStartTime)
819818
}
820819

821820
//Optimization pulled from dollchan.net: https://github.com/Chasyxx/EnBeat_NEW, it seemed important
@@ -829,6 +828,7 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
829828

830829
this.func = getByteBeatFunc(codeText);
831830
};
831+
this.initialOffset = null;
832832
this.t = null;
833833
this.func = null;
834834
}
@@ -878,13 +878,14 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
878878
for (let i = 0; i < output[0].length; i++) {
879879
const detune = getParamValue(i, params.detune);
880880
const freq = applySemitoneDetuneToFrequency(getParamValue(i, params.frequency), detune / 100);
881-
let t = (this.t / (sampleRate / 256)) * freq;
882-
const funcValue = this.func(t);
881+
let local_t = ((this.t / (sampleRate / 256)) * freq) + this.initialOffset
882+
const funcValue = this.func(local_t);
883883
let signal = (funcValue & 255) / 127.5 - 1;
884884
const out = signal * 0.2;
885885

886886
for (let c = 0; c < output.length; c++) {
887-
output[c][i] = clamp(out, -0.2, 0.2);
887+
//prevent speaker blowout via clipping if threshold exceeds
888+
output[c][i] = clamp(out, -0.4, 0.4);
888889
}
889890
this.t = this.t + 1;
890891
}

0 commit comments

Comments
 (0)