Reviewed changes

This commit is contained in:
Nikita 2025-10-21 16:30:18 +03:00
parent 6e4dae4dfa
commit bf702c3b2a
3 changed files with 8 additions and 12 deletions

View file

@ -98,7 +98,6 @@ export class Cyclist {
this.started = v; this.started = v;
this.onToggle?.(v); this.onToggle?.(v);
} }
async start() { async start() {
await this.beforeStart?.(); await this.beforeStart?.();
this.num_ticks_since_cps_change = 0; this.num_ticks_since_cps_change = 0;

View file

@ -282,7 +282,7 @@ export async function initAudioOnFirstClick(options) {
} }
let controller; let controller;
function getSuperdoughAudioController() { export function getSuperdoughAudioController() {
if (controller == null) { if (controller == null) {
controller = new SuperdoughAudioController(getAudioContext()); controller = new SuperdoughAudioController(getAudioContext());
} }
@ -376,7 +376,6 @@ function mapChannelNumbers(channels) {
} }
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => { export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
// controller = null;
// new: t is always expected to be the absolute target onset time // new: t is always expected to be the absolute target onset time
const ac = getAudioContext(); const ac = getAudioContext();
const audioController = getSuperdoughAudioController(); const audioController = getSuperdoughAudioController();
@ -402,7 +401,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
`[superdough]: cannot schedule sounds in the past (target: ${t.toFixed(2)}, now: ${ac.currentTime.toFixed(2)})`, `[superdough]: cannot schedule sounds in the past (target: ${t.toFixed(2)}, now: ${ac.currentTime.toFixed(2)})`,
); );
return; return;
} // FIXME: fix }
// destructure // destructure
let { let {
tremolo, tremolo,

View file

@ -45,12 +45,11 @@ export const webaudioOutput = (hap, _deadline, hapDuration, cps, t) => {
}; };
export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, downloadName = undefined) { export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, downloadName = undefined) {
const oldAudioCtx = getAudioContext(); let audioContext = getAudioContext();
await oldAudioCtx.close(); await audioContext.close();
let audioContext = new OfflineAudioContext(2, ((end - begin) / cps) * sampleRate, sampleRate); audioContext = new OfflineAudioContext(2, ((end - begin) / cps) * sampleRate, sampleRate);
setAudioContext(audioContext); setAudioContext(audioContext);
let context = getAudioContext(); setSuperdoughAudioController(new SuperdoughAudioController(audioContext));
setSuperdoughAudioController(new SuperdoughAudioController(context));
setMaxPolyphony(1024); setMaxPolyphony(1024);
setMultiChannelOrbits(true); setMultiChannelOrbits(true);
await loadWorklets(); await loadWorklets();
@ -69,7 +68,7 @@ export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, d
let bank = getSound(s).data.samples; let bank = getSound(s).data.samples;
if (bank) { if (bank) {
let { url: sampleUrl, label } = getSampleInfo(h.value, bank); let { url: sampleUrl, label } = getSampleInfo(h.value, bank);
await loadBuffer(sampleUrl, context, label); await loadBuffer(sampleUrl, audioContext, label);
} }
} }
}), }),
@ -81,10 +80,9 @@ export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, d
} }
}); });
return context return audioContext
.startRendering() .startRendering()
.then((renderedBuffer) => { .then((renderedBuffer) => {
console.log(renderedBuffer);
const wavBuffer = audioBufferToWav(renderedBuffer); const wavBuffer = audioBufferToWav(renderedBuffer);
const blob = new Blob([wavBuffer], { type: 'audio/wav' }); const blob = new Blob([wavBuffer], { type: 'audio/wav' });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);