Skip to content

[Frameforge 2] Implement Web Audio mixing, media sources and waveform decoding #55

Description

@danwalmsley

Outcome and dependencies

Depends on the media service in #54. AudioContext is currently undefined. Provide the real mix graph Frameforge uses for transport audio, fades, monitor controls, meters, waveform jobs and recording input.

Specification and implementation

  • Implement AudioContext lifecycle/state/currentTime/sampleRate/destination, resume/suspend/close and statechange, with defined host user-activation policy. Expose constructors/methods through AOT-safe bindings, not reflection-only activation.
  • Implement createGain, createAnalyser, createMediaElementSource, createMediaStreamDestination and decodeAudioData; node connect/disconnect and valid routing/ownership; AudioParam.value and setTargetAtTime with audio-clock scheduling. Add validation/errors for invalid graph operations and duplicate media-element source creation.
  • Implement gain/mixing, channel conversion/resampling, analyser fftSize/smoothingTimeConstant and getFloatTimeDomainData sufficient for real RMS meters. decodeAudioData must return real AudioBuffer sample data, numberOfChannels, duration/sampleRate/length and getChannelData; failures reject correctly.
  • MediaElementAudioSourceNode consumes the media decode service without duplicate audible output, observes mute/rate/seek and synchronizes clock changes. Keep context graph and device callbacks independent of V8/UI; no JS invocation, blocking file work or unbounded allocation on the realtime callback.
  • MediaStreamAudioDestinationNode exposes a real audio track for the recording issue. Track cloning/stopping must not inadvertently stop monitor playback or sibling consumers.
  • Frameforge copies decoded PCM into transferable worker buffers for waveform reduction. Reuse the existing worker/clone implementation and preserve transferred backing-store lifetime after either realm terminates.

Tests and verification

Generate sine, silence, impulse and stereo fixtures; verify gain/fades and mix numerically, channel handling, sample-rate conversion, analyser output and decode failures. Test scheduling across suspend/resume, seek/rate changes, source/context disposal, track cloning and queue bounds. Compare waveform worker envelopes with an independent reduction. Measure A/V drift using a timestamped flash/click fixture during playback and recording; record tolerance and results, not merely audible sound.

Acceptance

  • Original playback, volume/mute and clip gain/fades work; no doubled audio.
  • Waveforms reflect real decoded media; meters respond correctly to known signals.
  • A real mixed audio track is consumable by recording, with bounded latency and clean shutdown.
  • Focused Web Audio WPT/project contracts and realtime/lifetime tests pass.

References

Web Audio specification.

Original application references

Shared delivery requirements

Parent: #53. Baseline: PR #43 / ce56d49; sample experiments/WebScene.Frameforge.
Reference application: https://github.com/wieslawsoltes/Frameforge (pin f414cd44896b659a5c6da2e4fc596a2ded055f2a, includes demo media and THIRD_PARTY_NOTICES.md).
Implement in WebScene, leaving original application JavaScript/WGSL unchanged. No fake capability objects, synthetic successful events or swallowed errors. Keep public contracts cross-platform with isolated backend implementations; qualify macOS arm64 first and explicitly track Windows/Linux follow-up. Production Avalonia 11 must remain supported; only samples opt into Avalonia 12. Native AOT/trim safety is mandatory.
Add focused native/managed regression coverage and a pinned WPT subset or clearly labeled project-owned contract for non-WebGPU behavior. Applicable WebGPU CTS cases belong with GPU work. Record exact revisions, test commands, negative cases and reproducible evidence in the implementation PR. Unsupported functionality cannot be marked passed; distinguish app coverage from standards conformance. Review existing implementation before adding overlapping infrastructure.

Cross-platform and airspace requirements

Use common services and lifecycle contracts across Windows, macOS and Linux. Prefer reusable cross-platform libraries; native OS service providers are acceptable where appropriate. No native child video window, AVPlayerLayer, HWND overlay or separate presentation surface: video must compose as a retained WebScene texture with normal HTML stacking, clipping, transforms, opacity and scrolling. Share frame ownership with WebGPU external textures and the existing vsync/mailbox/versioned-image architecture. GPU consumers retain immutable frame leases through completion, including resize and replacement.

Foundation progress (not issue completion)

PR #43 commit 42c2e34 adds a bounded asynchronous decoder service, statically compiled pinned miniaudio PCM decoding and a macOS AVFoundation native-frame provider. Original Frameforge score decodes to 576000 stereo frames at 24000 Hz; actual 960x540 H.264 frames at 0 and 1 second differ and retain IOSurfaces after decoder destruction. Local native suite: 17/17 passed; Windows/Linux audio CI coverage added but not yet qualified.

This is opt-in native foundation work. HTML media bindings/playback scheduling, Web Audio realtime graph/output and GPU scene consumption are still pending. No fake browser capability is exposed, and Frameforge remains a compatibility preview. Windows/Linux video currently rejects as unsupported; evaluate FFmpeg versus native providers before selecting those implementations.

Design, library comparison and next slices: https://github.com/wieslawsoltes/WebScene/blob/42c2e349/experiments/WebScene.NativeEngine.Probe/native/media/README.md

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions