
AhSilence
Open-source Android active noise cancellation engine
Replaces —

Who it's for
Someone working from home with a loud HVAC or server room hum can run AhSilence on an Android device near the noise source to soften the persistent drone without purchasing ANC headphones.
User needs cancellation while wearing earbuds or in a noisy open-plan office with broadband sound.
A developer or student studying digital signal processing can read the Radix-2 FFT implementation, the AudioRecord/AudioTrack pipeline, and the Clean Architecture separation as a reference for building their own audio processing apps.
Someone bothered by a refrigerator compressor or air conditioning unit at night can lock their phone screen and let the Foreground Service maintain cancellation throughout the night without the app being killed.
User needs white-noise generation rather than active cancellation of a specific frequency.
The problem
Persistent low-frequency environmental hums from AC units, fans, and electrical equipment disrupt focus and sleep, yet software-based noise cancellation on Android has historically required proprietary SDKs or hardware ANC chips. There was no open, inspectable Android engine that handled the full DSP pipeline in Kotlin with clean architecture, offline operation, and a manual calibration path for Bluetooth latency.
How it works
A hand-written Cooley-Tukey Radix-2 algorithm runs on real-time PCM buffers captured at 44.1kHz to extract the dominant background frequency during a 7-second ambient scan, with no third-party DSP dependency.
The continuous emission loop synthesizes and pushes inverted sine wave buffers via AudioTrack.WRITE_BLOCKING without heap allocations, preventing garbage collection pauses that would interrupt destructive interference.
A continuous trigonometric dial bound to memory blocks lets users inject an exact phase offset in degrees to compensate for speaker-to-microphone path differences and Bluetooth transmission latency.
An Android Foreground Service with a persistent notification keeps the ANC engine active while the screen is locked, preventing the OS from throttling or killing the audio pipeline.
AhSilence makes zero network calls, collects no data, and sends no telemetry. The entire pipeline runs locally on-device with no external dependencies at runtime.
The DSP engine contract and acoustic state model are pure Kotlin with zero Android imports, making the domain layer independently testable and the Android framework substitutable without touching business logic.
Features
- Custom Radix-2 FFT Engine
- Zero-Allocation GC-Free Hot Loop
- 360-Degree Phase Calibrator
- OS Shield Foreground Service
- Fully Offline and Privacy-Free
- Clean Architecture Domain Isolation
How to install
git clone https://github.com/ahmadhassan-bted/ahsilence.git cd ahsilence ./gradlew clean assembleDebug ./gradlew installDebug
Recommended for this setup
Strengths
- No Hardware ANC Required: The entire cancellation pipeline runs in software, so it works on any Android 8.0+ device regardless of whether the hardware includes dedicated ANC chips.
- Transparent, Auditable DSP: Because the FFT math, phase synthesis, and audio pipeline are all plain Kotlin, every step of the signal processing can be read, audited, and modified without reverse-engineering a closed SDK.
- Manual Calibration for Bluetooth: The 360-degree phase dial addresses the practical reality that Bluetooth headsets introduce variable latency; users can tune the offset until the cancellation effect is audible rather than waiting for an adaptive algorithm.
- Battery-Conscious UI: StateFlow with Compose hoisted parameters means the UI only recomposes on genuine state changes, and the stateless design avoids background recomposition that would otherwise drain the battery.
Trade-offs
- Single-Frequency Cancellation Only: The current engine targets one dominant frequency per session. The roadmap lists multi-frequency cancellation as a future feature, so environments with overlapping hums at different frequencies are not yet handled.
- Physical Device Required: Emulators do not support the low-latency hardware microphone path the FFT engine depends on, so development and testing require a real Android device running API 26 or higher.
- Speaker-Based Cancellation Limitations: Software ANC through a phone speaker is effective for environmental hums in a room but cannot replicate the in-ear destructive interference that hardware ANC headphones achieve, so it is a poor fit for blocking broadband noise while wearing earbuds.
- No Adaptive Algorithm Yet: Phase and amplitude do not auto-adjust as the ambient environment changes; users must re-calibrate manually or restart a scan when conditions shift. Adaptive algorithms are listed on the roadmap but not yet implemented.
Tech stack
FAQ
No. Emulators do not expose the low-latency hardware microphone path required for FFT testing. A physical Android device running API 26 (Android 8.0) or higher is required.
Yes. The engine runs inside an Android Foreground Service with a persistent notification, which prevents the OS from throttling or terminating the audio pipeline when the screen is locked.
No. The app is fully offline with zero network calls, zero data collection, and zero telemetry, as stated in SECURITY.md.
It targets persistent, low-frequency hums such as those from AC units or electrical drones. It performs a 7-second ambient scan to identify the dominant frequency, then emits a phase-inverted wave to cancel it. It is not designed for broadband or dynamic noise.
Use the 360-degree Phase Calibrator dial on the dashboard. It lets you inject a manual phase offset in degrees so the inverted wave aligns correctly with the ambient sound despite Bluetooth transmission delay.