mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-13 06:19:33 -04:00
Re-init audio before and after export
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user