AhSilence README

项目的 README,来自 github.com/AhmadHassan-BTed/AhSilence。合并为一个 markdown 文件:README.md。

AhSilence Banner

AhSilence

Silence the ambient hum. Find your perfect quiet.

Kotlin API Level Architecture DSP License


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.

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

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         # Lightweight service locator
│   └── logging/AppLogger.kt            # Structured logging facade
│
├── domain/                              # Pure Kotlin — zero Android imports
│   ├── model/AcousticState.kt           # Immutable single source of truth
│   └── port/AudioEngine.kt             # DSP engine contract
│
├── data/                                # Android framework implementations
│   ├── engine/FastFourier.kt            # Radix-2 FFT math engine
│   ├── engine/NativeAudioDSP.kt        # AudioRecord / AudioTrack pipeline
│   └── service/ActiveHumService.kt     # Foreground service (OS Shield)
│
├── presentation/                        # State management
│   └── ControlViewModel.kt             # Jetpack Compose bridge
│
├── ui/                                  # Visual layer
│   ├── screen/DashboardScreen.kt        # Main dashboard (Pro / Simple mode)
│   ├── component/                       # Reusable UI elements
│   │   ├── CalibratorRing.kt           # 360° phase dial
│   │   └── GainSlider.kt               # Vertical amplitude fader
│   └── theme/                           # OLED Black / Neon Amber design system
│       ├── Color.kt
│       ├── Theme.kt
│       └── Type.kt
│
└── MainActivity.kt                      # Entry point

Getting Started

Prerequisites

Build

# Clone
git clone https://github.com/ahmadhassan-bted/ahsilence.git
cd ahsilence

# Build debug APK
./gradlew clean assembleDebug

# Run unit tests
./gradlew test

# Lint check
./gradlew lint

Install

# Install on connected device
./gradlew installDebug

Tech Stack

Layer Technology
Language Kotlin 2.0.21
UI Jetpack Compose (Material 3)
State StateFlow + ViewModel
Audio Capture AudioRecord (PCM 16-bit, 44.1kHz)
Audio Playback AudioTrack (streaming mode)
FFT Custom Cooley-Tukey Radix-2
Background Foreground Service (mediaPlayback)
Build Gradle (Kotlin DSL) + Version Catalog
Min SDK API 26 (Android 8.0)

Contributing

See CONTRIBUTING.md for branch naming, commit conventions, and the non-negotiable architectural rules (zero-allocation hot loops, domain isolation, UI purity).

Security

AhSilence is fully offline — zero network calls, zero data collection, zero telemetry. See SECURITY.md.

Roadmap

See ROADMAP.md for planned features including multi-frequency cancellation, adaptive algorithms, and Bluetooth latency compensation.

License

Copyright 2025 Ahmad Hassan

Licensed under the Apache License, Version 2.0.
See LICENSE for details.

AhSilence (AhmadHassan-BTed/AhSilence)

正在搜索数据库…

这是什么?AhSilence 是一款原生 Android 应用,可进行主动降噪:它会分析空调机组或电器嗡嗡声等持续存在的低频噪音,并实时发出相位相反的声波将其抵消。
这是我需要安装的应用,还是给开发者用的库?这是一款基于 Kotlin 和 Jetpack Compose 构建的独立 Android 应用,而不是可以嵌入其他应用中的库。
怎样才能让它运行起来?克隆代码仓库,使用 JDK 21+ 和项目提供的 Gradle 配置,在 Android Studio Ladybug(2024.2.1+)中构建,然后将生成的 APK 安装到你的手机上。
试用它需要什么硬件或工具?你需要 Android Studio Ladybug、JDK 21+,以及一台至少运行 Android 8.0(API 26)、带有可用麦克风的实体 Android 设备。
我可以在模拟器上测试吗?不可以,你需要一部真实的手机,因为模拟器无法完成本应用所依赖的低延迟硬件麦克风 FFT 处理。
它能在所有 Android 手机上运行吗?它面向 Android 8.0(API 26)及以上版本,是基于 Kotlin/Jetpack Compose 的原生应用。
应用会把任何音频或数据发送到我的手机之外吗?不会,所有处理都在本地完成:AhSilence 不发起任何网络请求,也不收集任何数据或遥测信息。
应用究竟如何检测到它要抵消的嗡嗡声?它会对实时 PCM 音频缓冲区运行一种自定义的 Cooley-Tukey Radix-2 FFT 算法,从而自动检测主要的背景嗡鸣声。
锁屏后降噪还能继续工作吗?可以,它以 Android 前台服务的形式运行,并带有常驻通知,因此即使屏幕锁定也能保持工作状态。
运行它会很快耗电吗?界面使用 StateFlow 并将 Compose 参数提升至外部,以避免不必要的重组;音频循环则做到零内存分配、不产生垃圾回收,因此其设计目标是尽量降低电量和性能开销。
未来版本有什么计划?路线图包括多频率降噪、自适应算法以及蓝牙延迟补偿。
大小
5.9 MB
星标
4.9K
更新
提交Nov 10
时长
4个月
提交 · 90 天