AhmadHassan-BTed /AhSilence

An open-source Android Active Noise Cancellation (ANC) engine. Leveraging low-latency DSP to neutralize environmental hums and help you reclaim your quiet.

★ 4,923⑂ 14👁 1⑃ 5● 1▤ 0
KotlinApache-2.0Created 2026-07-03
+6
Daily
4,923
stars
14
forks
1
watchers
5
prs
1
issues
0
releases

README

AhSilence
  Silence the ambient hum. Find your perfect quiet.

  
    
    
    
    
    
  


---

 Overview

AhSilence is a native Android active noise cancellation (ANC) engine built with Jetpack Compose and Kotlin. It bridges the gap between complex digital signal processing (DSP) and human comfort by analyzing the environment for persistent, low-frequency hums (such as AC units or electrical drones) and emitting phase-inverted audio waves that mathematically neutralize acoustic disturbances.

The application runs a zero-allocation, GC-free hot loop, ensuring seamless destructive interference without frame drops or OS throttling.

 Key Features

| Component | Implementation | User Benefit |
|---|---|---|
| FFT Engine | Custom Cooley-Tukey Radix-2 algorithm on real-time PCM buffers | Automatically detects the dominant background drone |
| Phase Calibrator | Continuous 360° trigonometric dial bound to memory blocks | Manual wave alignment to compensate for hardware/BT latency |
| OS Shield | Android Foreground Service with persistent notification | Keeps cancellation active while screen is locked |
| Stateless UI | StateFlow + Compose hoisted parameters | Zero battery drain from unnecessary recompositions |

---

 Architecture

AhSilence follows Clean Architecture with strict unidirectional data flow and complete isolation of the Android framework from core business logic.

mermaid
graph TD
    subgraph Presentation Layer
        UI[Jetpack Compose UI]
        VM[ControlViewModel]
    end

    subgraph Domain Layer
        STATE((AcousticState))
        PORT{AudioEngine Port}
    end

    subgraph Data Layer
        SERVICE[ActiveHumService]
        DSP[NativeAudioDSP]
        FFT[FastFourier]
    end

    UI --|Observes State| VM
    UI --|OS Intent| SERVICE
    VM --|Updates| STATE
    VM --|Injects Phase/Gain| PORT
    SERVICE --|Foreground Shield| DSP
    DSP --|Implements| PORT
    DSP --|PCM Buffer Math| FFT

    classDef domain fill:1E1E1E,stroke:7F52FF,stroke-width:2px;
    class STATE,PORT domain;


 Data Flow

mermaid
sequenceDiagram
    participant M as Microphone
    participant E as NativeAudioDSP
    participant F as FastFourier (FFT)
    participant U as Dashboard UI
    participant S as Speaker (AudioTrack)

    Note over M,E: 7-Second Ambient Scan
    M-E: Capture Raw PCM Buffer
    E-F: Compute Radix-2 FFT
    F--E: Extract Dominant Frequency (Hz)
    E--U: Push AcousticState Update

    Note over U,S: User Calibration
    U-E: Inject Phase Offset (°) & Amplitude

    Note over E,S: Continuous Emission Loop
    loop GC-Free Hot Loop
        E-E: Synthesize Inverted Sine Wave
        E-S: Push Buffer (AudioTrack.WRITE_BLOCKING)
        S-M: Destructive Acoustic Interference
    end


---

 Project Structure


app/src/main/java/com/bted/ahsilence/
├── core/                                 Cross-cutting concerns
│   ├── constants/AudioConstants.kt       Centralised magic numbers
│   ├── di/AudioEngineLocator.kt          Lightwei

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON