# ahmadgon/wm8731-audio-codec architecture

> Architecture diagram of the GitHub repository ahmadgon/wm8731-audio-codec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmadgon/wm8731-audio-codec
- Repository: https://github.com/ahmadgon/wm8731-audio-codec

## Overview

##### Project type and purpose
- This is an FPGA‐based hardware project (DE2-115 board) implementing a WM8731 audio CODEC interface in Verilog.
- It configures the WM8731 via an I2C driver and streams 13 seconds of 16-bit, 8 kHz PCM data stored in on-chip M9K ROM blocks to the codec.
- A MATLAB script converts a HEX audio dump (from Audacity + HEX Editor) into a Quartus-readable MIF file.

##### File structure
- Top-level files:
– Audio_CODEC.rar: likely contains the Verilog source, constraints, Quartus project files and I2C/I2S modules
– PCM_16bit_Audio.m: MATLAB script that turns a HEX audio file into a MIF memory initialization file
– README.md: project overview and workflow
- No separate “src” or “lib” folders visible; everything packs into the RAR archive.
- Key configuration artifacts: .mif (memory init), Quartus project files inside the RAR, pin constraints, Verilog modules.

##### README for additional insights
- Workflow:
1. Use Audacity → export 16-bit PCM @8 kHz → save as HEX via HEX Editor Neo
2. Run MATLAB script to convert HEX → .mif
3. .mif in Quartus, synthesize onto DE2-115
4. FPGA I2C config + I2S audio streaming to WM8731

##### Components and relationships
a. Main components
- Audio Preprocessing (Audacity + HEX Editor)
- MATLAB conversion script (PCM_16bit_Audio.m) → produces .mif
- Quartus Project (Verilog modules, .mif, pin constraints)
- FPGA Design:
– I2C Configuration Controller (initializes WM8731 registers)
– ROM (M9K block) storing audio samples
– I2S Audio Transmitter (serial audio data to codec)
- External Hardware:
– DE2-115 FPGA board
– WM8731 Audio CODEC chip
– Speakers or headphone output
b. Interactions & data flow
1. Audio file → HEX → MATLAB script → .mif
2. Quartus imports .mif → synthesizes FPGA bitstream
3. FPGA loads bitstream on DE2-115 at power-on
4. FPGA I2C controller programs WM8731 over two‐wire bus
5. FPGA reads sample words from M9K ROM → feeds I2S transmitter
6. I2S bus carries clocked audio data to WM8731 → analog output to speakers
c. Architectural patterns
- Simple streaming pipeline: ROM → I2S → CODEC
- Control plane vs. data plane separation: I2C (configuration) vs. I2S (audio streaming)
- Memory-mapped ROM using Quartus M9K block primitives
d. Key technologies
- Verilog HDL (I2C + I2S finite‐state machines)
- Quartus II synthesizer, .mif for block RAM initialization
- MATLAB for data conversion
- Audacity + HEX Editor Neo for audio export

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Offline Tools"
        Audacity["Audacity (16-bit PCM export)"]:::tools
        HEXEditor["HEX Editor Neo"]:::tools
    end

    subgraph "Conversion"
        MATLAB["MATLAB Conversion Script"]:::tools
        MIF[".mif Memory Init File"]:::init
    end

    Audacity -->|export HEX| HEXEditor --> MATLAB -->|generate .mif| MIF

    subgraph "Synthesis Flow"
        Quartus["Quartus Project"]:::tools
        Bitstream["FPGA Bitstream"]:::tools
    end

    MIF -->|included in| Quartus -->|synthesize| Bitstream

    FPGAdev["DE2-115 FPGA"]:::hardware

    Bitstream -->|"programs FPGA"| FPGAdev

    subgraph "FPGA Modules"
        I2C["I2C Configuration Controller"]:::fpga
        ROM["M9K ROM (audio samples)"]:::fpga
        I2S["I2S Audio Transmitter"]:::fpga
    end

    FPGAdev --> I2C
    FPGAdev --> ROM
    FPGAdev --> I2S

    I2C -->|"I2C (control)"| WM["WM8731 Audio CODEC"]:::hardware
    ROM -->|"16-bit samples @8 kHz"| I2S
    I2S -->|"I2S (data)"| WM -->|"analog audio"| SP["Speakers/Headphones"]:::hardware

    click MATLAB "https://github.com/ahmadgon/wm8731-audio-codec/blob/master/PCM_16bit_Audio.m"
    click Quartus "https://github.com/ahmadgon/wm8731-audio-codec/blob/master/Audio_CODEC.rar"
    click README["README.md"] "README.md"

    classDef tools fill:#DDDDDD,stroke:#333,stroke-width:1px
    classDef fpga fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef hardware fill:#90EE90,stroke:#000,stroke-width:1px
    classDef init stroke-dasharray:5 5,fill:#FFF,stroke:#FFA500,stroke-width:1px
```
