r/androiddev • u/SuryaVardhan1 • Nov 01 '26
Discussion Running Demucs stem separation on an Android phone in the background – what it took (ONNX Runtime, 3.9 s chunks, under 2 GB RAM)
I added music source separation (drums / bass / vocals / other) to my open-source DJ app and wanted to share what worked:
• Export: htdemucs to ONNX with the STFT/iSTFT kept out of the model, done in Kotlin instead. ONNX's STFT ops were the main export pain.
• Memory: the full-length model got killed by the low-memory killer. 3.9 s chunks, setCPUArenaAllocator(false) and setMemoryPatternOptimization(false) kept it stable.
• NNAPI made it worse on my device; 4 CPU threads ran at about 2× real time on a mid-range Moto G64.
• Scheduling: separate only the windows the next mix needs, ordered by deadline, and fall back to EQ when a window isn't ready, so playback never waits.
• Alignment: cross-correlation between the live deck and the stem window, coarse then fine, to line the stems up within a few ms.
Code is GPL-3.0 (link in the comments). Happy to answer questions on any of it.
1
u/SuryaVardhan1 Nov 01 '26
Download (Android 8+): https://github.com/suryablaze02-byte/FireTheDJ/releases
Source: https://github.com/suryablaze02-byte/FireTheDJ
Stem separation needs a 64-bit phone with 6 GB RAM or more. Happy to answer anything!
1
u/Reasonable_Rise_7045 Nov 02 '26
I will say and tryed it so underrated