Technical guide on porting Meta AI's HTDemucs neural network to browser WebGPU, handling Cooley-Tukey FFT transforms, and client-side stem separation.
By Audio Engineering Team
•
Published 2026-11-18
•Updated 2026-11-23
•6 min read
The Evolution of Deep Learning Audio Source Separation
Audio source separation—the algorithmic task of decomposing a complex composite audio recording into its distinct constituent tracks, such as isolated vocals, drums, bass, and instrumental accompaniment—has long represented one of the most mathematically demanding challenges in digital signal processing (DSP). For decades, recording engineers and researchers relied on classical techniques like Out of Phase Stereo (OOPS), center-channel subtraction, and comb filtering. While these algebraic methods offered crude vocal attenuation, they fundamentally degraded the underlying audio, stripping out kick drums, collapsing stereo depth, and introducing severe comb-filtered phasing artifacts.
The paradigm shifted dramatically with the introduction of deep learning architectures tailored for machine audition. In 2019, Meta AI Research published the original Demucs architecture, an audio source separation model utilizing deep convolutional neural networks operating directly on time-domain waveforms. By 2021, the research team, led by Alexandre Défossez, advanced this foundation with HTDemucs (Hybrid Transformer Demucs v4). HTDemucs combined convolutional U-Net encoders and decoders with cross-domain transformer layers that operate simultaneously across both the raw temporal waveform and the two-dimensional Short-Time Fourier Transform (STFT) spectrogram representation.
This hybrid approach allowed the neural network to capture long-range temporal dependencies (such as musical phrasing, vibrato modulations, and sustained reverb decays) while maintaining microscopic frequency resolution. As documented in Meta AI's benchmark evaluations, HTDemucs achieved an unprecedented Signal-to-Distortion Ratio (SDR) exceeding 9.0 dB on the standard MUSDB18-HQ evaluation dataset, setting the current gold standard for commercial and open-source music isolation.
The Client-Side Challenge: Escaping Python and Server Dependencies
Despite its state-of-the-art separation fidelity, standard Demucs historically presented massive barriers for consumer accessibility. Running the native PyTorch implementation requires a dedicated Python 3.10+ runtime, TorchAudio, CUDA 12 development toolkits, and a desktop-grade NVIDIA GPU with at least 4 GB to 8 GB of dedicated video memory (VRAM). For conventional web-based audio platforms, offering this capability meant deploying expensive fleets of GPU-accelerated cloud instances.
However, server-side processing introduces critical operational and ethical vulnerabilities. Uploading gigabytes of user audio to third-party servers creates severe latency bottlenecks, bandwidth costs, and queuing delays. More importantly, it compromises user privacy: independent musicians, voice actors, and mastering studios are rightfully reluctant to upload unreleased stems, copyrighted multi-tracks, or private vocal takes to remote cloud infrastructure. Learn more about our zero-upload privacy architecture on our About Us Page and review our Privacy Policy.
To eliminate server dependency entirely, our engineering team engineered a client-side execution pipeline capable of running Demucs v4 directly inside the user's web browser. By taking advantage of the modern W3C WebGPU standard and WebAssembly (WASM), your local hardware performs all tensor computations in a sandboxed, confidential client environment. In browser mode, your audio stays on your device.
Model Quantization and the ONNX Runtime Web Pipeline
Directly executing a multi-gigabyte PyTorch checkpoint inside a browser tab is infeasible due to memory caps and lack of native PyTorch bindings. To overcome this limitation, the HTDemucs neural network was exported into the Open Neural Network Exchange (ONNX) format using PyTorch's trace-based graph exporter (`torch.onnx.export`).
The native FP32 (32-bit single-precision floating point) model weighs approximately 180 megabytes per separation stem. To ensure rapid initialization without saturating browser heap limits, we applied post-training quantization. By converting weights to FP16 (half-precision float) and selectively quantizing dense linear transformer projections to INT8, we reduced model asset delivery overhead while preserving mathematical precision across critical frequency bands.
Client-side inference is driven by Microsoft's ONNX Runtime Web (`onnxruntime-web`). We configured the runtime to target the WebGPU execution provider (`webgpu`). WebGPU provides modern, low-overhead access to the underlying hardware GPU—whether Apple Metal on macOS, Direct3D 12 on Windows, or Vulkan on Linux and Android. The runtime compiles optimized WebGPU Shading Language (WGSL) compute shaders directly on the user's GPU, executing General Matrix Multiplications (GEMM) and multi-head attention operations at native near-metal speeds.
Digital Signal Processing in the Browser: STFT, Hann Windows, and Overlap-Add
Neural inference represents only half of the source separation pipeline. HTDemucs requires complex time-frequency spectrogram inputs and must synthesize time-domain audio outputs from the predicted complex spectrogram masks. Performing these transforms in the browser requires high-performance Digital Signal Processing (DSP) implemented directly in TypeScript and WebAssembly SIMD.
Before audio enters the neural network, our engine computes a Short-Time Fourier Transform (STFT) with a frame length of 4096 samples and a hop length of 1024 samples (75% overlap). To prevent spectral leakage across frequency bins, each frame is multiplied by a periodic Hann window: $w(n) = 0.5 - 0.5 \cos(2\pi n / N)$. The windowed samples are transformed using a high-performance in-place Radix-2 Cooley-Tukey Fast Fourier Transform (FFT) algorithm.
Once the neural network outputs the predicted complex vocal and instrumental spectrogram masks, the audio must be reconstructed into temporal PCM audio. We execute an Inverse Fast Fourier Transform (iSTFT) followed by an Overlap-Add (OLA) reconstruction step. Because our hop size and window function satisfy the Constant Overlap-Add (COLA) mathematical constraint, the overlapping windowed time slices sum to unity across the entire timeline, eliminating amplitude modulation and phase cancellation artifacts.
Streaming Chunk Architecture and Memory Management
A standard 4-minute stereo audio song at 44.1 kHz contains over 10.5 million individual 32-bit floating-point audio samples per channel. Attempting to process an entire song in a single forward pass would allocate tens of gigabytes of intermediate activation tensors, instantly exceeding the 2 GB to 4 GB memory ceiling imposed on individual browser tabs by Chrome, Firefox, and Safari.
To maintain complete stability on consumer hardware, our pipeline implements a streaming chunk architecture. The input audio is sliced into 10-second processing segments with a 1-second bidirectional crossfade margin. Each chunk is passed through the WebGPU inference worker sequentially. As each segment completes, the overlapping crossfade window applies a smooth linear attenuation curve to stitch adjacent audio slices together seamlessly, eliminating audible clicks, pop transients, or boundary discontinuities.
Between chunks, all temporary `Float32Array` buffers and intermediate WebGPU tensor allocations are explicitly destroyed and flagged for garbage collection, ensuring that browser memory consumption remains rock-solid under 350 megabytes regardless of song length.
Practical Application and Production Workflow
You can test this browser-based architecture immediately using our free AI Vocal Remover on our homepage. Upload any MP3, WAV, FLAC, or video file, and watch the real-time WebGPU progress meter isolate clean stems in seconds.
For producers looking to isolate individual vocal tracks for remixing or mashup production, explore our specialized Vocal Extractor Tool and Acapella Extractor. If your goal is generating clean sing-along accompaniment tracks, our Instrumental Maker and Karaoke Maker provide instant lossless 16-bit WAV downloads.
For a complete step-by-step tutorial on file preparation, sample rates, and avoiding audio bleed, read our comprehensive How to Remove Vocals from Any Song Guide. To understand how input audio encoding influences separation cleanliness, explore our analysis of MP3 vs WAV for AI Audio Separation.
Technical Documentation and Authoritative References
For software engineers, audio researchers, and digital signal processing specialists interested in exploring the underlying academic literature and specifications, we recommend the following primary sources:
1. Défossez, A. (2021). *Hybrid Spectrogram and Waveform Source Separation*. Meta AI Research. arXiv:2111.12203 [cs.SD].
2. Microsoft Corporation (2024). *ONNX Runtime Web: WebGPU Execution Provider Architecture and Operator Support*. Microsoft Open Source Documentation.
3. W3C WebGPU Working Group (2024). *WebGPU Specification: High-Performance 3D Graphics and Computation on the Web*. World Wide Web Consortium Candidate Recommendation.
4. Cooley, J. W., & Tukey, J. W. (1965). *An Algorithm for the Machine Calculation of Complex Fourier Series*. Mathematics of Computation, 19(90), 297–301.
5. Rouard, S., Massa, F., & Défossez, A. (2023). *Hybrid Transformers for Music Source Separation*. IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP 2023).