feat(stage-shared): add an audio tapping node for troubleshooting beat-sync

This commit is contained in:
Makito
2025-12-02 01:40:02 +09:00
parent 38561f3a62
commit 7f4a0ecaf9
@@ -52,6 +52,7 @@ export function createBeatSyncDetector(options: CreateBeatSyncDetectorOptions):
}
let stopSource: (() => void) | undefined
let tapNode: ScriptProcessorNode | undefined // Dev
const listeners: { [K in keyof BeatSyncDetectorEventMap]: Array<(...args: any) => void> } = {
stateChange: [],
@@ -71,6 +72,13 @@ export function createBeatSyncDetector(options: CreateBeatSyncDetectorOptions):
stopSource?.()
stopSource = undefined
// Dev
if (tapNode) {
tapNode.onaudioprocess = null
tapNode.disconnect()
tapNode = undefined
}
source?.disconnect()
source = undefined
@@ -94,7 +102,26 @@ export function createBeatSyncDetector(options: CreateBeatSyncDetectorOptions):
})
const node = await createSource(context)
node.connect(analyser.workletNode)
if (import.meta.env.DEV) {
// Dev: Use a tap node to verify there're audio samples flowing in the pipeline.
tapNode = context.createScriptProcessor(256, 1, 1)
tapNode.addEventListener('audioprocess', (e) => {
const sample = e.inputBuffer.getChannelData(0)
// Avoid log flooding
if (e.timeStamp % 10 === 0) {
// eslint-disable-next-line no-console
console.debug('[debug:tap] sample.length =', sample.length, 'timeStamp =', e.timeStamp)
}
e.outputBuffer.copyToChannel(sample, 0)
})
node.connect(tapNode)
tapNode.connect(analyser.workletNode)
}
else {
node.connect(analyser.workletNode)
}
source = node
state.isActive = true