Re-init audio before and after export

This commit is contained in:
Nikita
2025-10-19 15:10:27 +03:00
parent 0fbde61b2d
commit 920776fdfe
2 changed files with 19 additions and 4 deletions
+10 -3
View File
@@ -250,8 +250,9 @@ export async function initAudio(options = {}) {
logger('[superdough] failed to set audio interface', 'warning');
}
}
await audioCtx.resume();
if (!audioCtx instanceof OfflineAudioContext) {
await audioCtx.resume();
}
if (disableWorklets) {
logger('[superdough]: AudioWorklets disabled with disableWorklets');
return;
@@ -285,6 +286,12 @@ function getSuperdoughAudioController() {
}
return controller;
}
export function setSuperdoughAudioController(newController) {
controller = newController
return controller;
}
export function connectToDestination(input, channels) {
const controller = getSuperdoughAudioController();
controller.output.connectToDestination(input, channels);
@@ -367,7 +374,7 @@ function mapChannelNumbers(channels) {
}
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
controller = null;
// controller = null;
// new: t is always expected to be the absolute target onset time
const ac = getAudioContext();
const audioController = getSuperdoughAudioController();
+9 -1
View File
@@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
*/
import * as strudel from '@strudel/core';
import { superdough, getAudioContext, setLogger, doughTrigger, registerWorklet, setAudioContext, getSampleBufferSource, loadBuffer, getSampleInfo, getSound } from 'superdough';
import { superdough, getAudioContext, setLogger, doughTrigger, registerWorklet, setAudioContext, getSampleBufferSource, loadBuffer, getSampleInfo, getSound, initAudio, setSuperdoughAudioController } from 'superdough';
import './supradough.mjs';
import { workletUrl } from 'supradough';
@@ -29,6 +29,12 @@ export const webaudioOutput = (hap, _deadline, hapDuration, cps, t) => {
export async function renderPatternAudio(pattern, cps, begin, end) {
let audioContext = new OfflineAudioContext(2, (end - begin) / cps * 48000, 48000);
setAudioContext(audioContext)
setSuperdoughAudioController(null)
await initAudio({
maxPolyphony: 1024,
multiChannelOrbits: true
})
logger('[webaudio] start rendering');
console.log(audioContext)
@@ -77,6 +83,8 @@ export async function renderPatternAudio(pattern, cps, begin, end) {
document.body.removeChild(a);
URL.revokeObjectURL(url);
setAudioContext(null)
setSuperdoughAudioController(null)
initAudio()
});
}