significantly improve visual performance

This commit is contained in:
Boof2015
2026-03-28 16:42:43 -04:00
parent a972d4646b
commit 9b22400747
15 changed files with 778 additions and 20 deletions
+27 -1
View File
@@ -4,6 +4,7 @@ import type {
ScopePopoutStereoBatch,
} from '../../types/popout'
import type { ScopeKind } from '../../types/scope'
import { NativeVisualizerTransport } from '../audio/NativeVisualizerTransport'
import type { LUFSMeterDataSource } from '../visualizers/LUFSMeter'
import type { OscilloscopeDataSource } from '../visualizers/Oscilloscope'
import type { SpectrogramDataSource } from '../visualizers/Spectrogram'
@@ -42,22 +43,43 @@ export class ScopePopoutDataSource implements AnyScopeDataSource {
private stereoQueue: ScopePopoutStereoBatch = []
private sessionState: ScopePopoutSessionState = INITIAL_SESSION_STATE
private readonly listeners = new Set<(state: ScopePopoutSessionState) => void>()
private readonly nativeVisualizerTransport = new NativeVisualizerTransport()
constructor(private readonly scopeKind: ScopeKind) {}
constructor(private readonly scopeKind: ScopeKind) {
this.nativeVisualizerTransport.setDemand({
spectrum: scopeKind === 'spectrum',
oscilloscope: scopeKind === 'oscilloscope',
vectorscope: scopeKind === 'vectorscope',
})
this.nativeVisualizerTransport.reset(this.sessionState)
}
pushAudioBatch(batch: ScopePopoutAudioBatch): void {
if (isStereoScope(this.scopeKind)) {
if (!isStereoBatch(batch)) return
this.stereoQueue.push(...batch)
for (const chunk of batch) {
this.nativeVisualizerTransport.handleChunk(chunk.left, chunk.right, {
sessionId: this.sessionState.sessionId,
channelCount: this.sessionState.channelCount,
})
}
return
}
if (isStereoBatch(batch)) return
this.monoQueue.push(...batch)
for (const chunk of batch) {
this.nativeVisualizerTransport.handleChunk(chunk, chunk, {
sessionId: this.sessionState.sessionId,
channelCount: 1,
})
}
}
setSessionState(nextState: ScopePopoutSessionState): void {
this.sessionState = nextState
this.nativeVisualizerTransport.reset(nextState)
if (!nextState.capturing) {
this.monoQueue = []
this.stereoQueue = []
@@ -84,6 +106,10 @@ export class ScopePopoutDataSource implements AnyScopeDataSource {
}
}
getNativeVisualizerTransport(): NativeVisualizerTransport {
return this.nativeVisualizerTransport
}
getPendingSpectrumSamples(): Float32Array[] {
const batch = this.monoQueue
this.monoQueue = []