# bert2/dtmfdetection architecture

> Architecture diagram of the GitHub repository bert2/dtmfdetection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bert2/dtmfdetection
- Repository: https://github.com/bert2/dtmfdetection

## Overview

##### Core Components (DtmfDetection Library)
- Goertzel Algorithm Implementation (Goertzel.cs)
- DTMF Analyzer (Analyzer.cs)
- DTMF Detector (Detector.cs)
- Configuration System (Config.cs)

##### NAudio Integration Layer (DtmfDetection.NAudio)
- Components:
- Audio File Handler (AudioFile.cs)
- Audio Stream Handler (AudioStream.cs)
- Background Analyzer (BackgroundAnalyzer.cs)
- Integration points with NAudio framework

##### Input/Output Flow
- Raw PCM Data
- Audio Files (MP3, WAV, etc.)
- Live Audio Streams (Microphone, System Audio)
- Output formats:
- DTMF Changes (DtmfChange.cs)
- DTMF Tones (DtmfTone.cs)

##### Processing Pipeline
- Audio Input → Sample Processing → DTMF Detection → Event Generation
- Sample block processing (26ms blocks as mentioned in README)

Specific Design Guidelines:

##### Use a layered architecture approach
- [Input Sources Layer]
- ↓
- [NAudio Integration Layer]
- ↓
- [Core Detection Layer]
- ↓
- [Output/Events Layer]

##### Component Relationships
- Clear dependencies between modules
- Extensibility points (custom implementations)
- Configuration flow

##### Processing Details
- Sample block size (26ms)
- Threshold configuration
- Multi-channel support
- Goertzel algorithm implementation

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        RAW["Raw PCM Data"]:::input
        AF["Audio Files"]:::input
        AS["Live Audio Streams"]:::input
    end

    subgraph "NAudio Integration"
        AFH["Audio File Handler"]:::naudio
        ASH["Audio Stream Handler"]:::naudio
        BA["Background Analyzer"]:::naudio
    end

    subgraph "Core Detection"
        subgraph "Interfaces"
            IA["IAnalyzer"]:::interface
            ID["IDetector"]:::interface
            IS["ISamples"]:::interface
        end

        subgraph "Core Components"
            GA["Goertzel Algorithm"]:::core
            AN["DTMF Analyzer"]:::core
            DT["DTMF Detector"]:::core
            CF["Configuration System"]:::core
            GN["DTMF Generator"]:::core
            PK["Phone Key Definitions"]:::core
            UT["Utility Functions"]:::core
            AD["Audio Data Handler"]:::core
        end
    end

    subgraph "Output"
        DC["DTMF Changes"]:::output
        DT_OUT["DTMF Tones"]:::output
    end

    %% Relationships
    RAW --> ASH
    AF --> AFH
    AS --> ASH
    
    AFH --> BA
    ASH --> BA
    
    BA --> IA
    BA --> ID
    
    IA --> AN
    ID --> DT
    IS --> AD
    
    AN --> GA
    DT --> GA
    
    CF --> AN
    CF --> DT
    
    AN --> DC
    DT --> DT_OUT
    
    GN --> DT_OUT
    PK --> DT
    UT --> AD

    %% Styles
    classDef input fill:#FFE5CC,stroke:#FF9933
    classDef naudio fill:#D4EDDA,stroke:#28A745
    classDef interface fill:#E2E3E5,stroke:#6C757D
    classDef core fill:#CCE5FF,stroke:#0066CC
    classDef output fill:#FFF3CD,stroke:#FFC107

    %% Click Events
    click AFH "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection.NAudio/AudioFile.cs"
    click ASH "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection.NAudio/AudioStream.cs"
    click BA "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection.NAudio/BackgroundAnalyzer.cs"
    click IA "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Interfaces/IAnalyzer.cs"
    click ID "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Interfaces/IDetector.cs"
    click IS "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Interfaces/ISamples.cs"
    click GA "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Goertzel.cs"
    click AN "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Analyzer.cs"
    click DT "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Detector.cs"
    click CF "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Config.cs"
    click GN "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/DtmfGenerator.cs"
    click PK "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/PhoneKey.cs"
    click UT "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/Utils.cs"
    click AD "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/AudioData.cs"
    click DC "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/DtmfChange.cs"
    click DT_OUT "https://github.com/bert2/DtmfDetection/blob/master/src/DtmfDetection/DtmfTone.cs"
```
