# heroeslament/melpe-rs architecture

> Architecture diagram of the GitHub repository heroeslament/melpe-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/heroeslament/melpe-rs
- Repository: https://github.com/heroeslament/melpe-rs

## Overview

melpe-rs is a fixed-size, 600 bps MELPe speech codec. Its main workflow encodes 540 audio samples into a six-byte superframe, then decodes that superframe back into audio. Encoding analyzes frames and packs quantized parameters; decoding unpacks and dequantizes them before excitation generation and synthesis. The graph follows the README’s documented stages and sampled module references; unsampled implementation details are not expanded.

Main entry points: [`src/encoder.rs`](https://github.com/heroeslament/melpe-rs/blob/main/src/encoder.rs) (Encoder), [`src/decoder.rs`](https://github.com/heroeslament/melpe-rs/blob/main/src/decoder.rs) (Decoder), [`src/math.rs`](https://github.com/heroeslament/melpe-rs/blob/main/src/math.rs) (Math shim), [`src/bitstream.rs`](https://github.com/heroeslament/melpe-rs/blob/main/src/bitstream.rs) (Bitstream codec)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Codec API"]
  node_encoder["Encoder<br/>[encoder.rs]"]
  node_decoder["Decoder<br/>[decoder.rs]"]
end

subgraph group_analysis["Speech Analysis"]
  node_lpc["LPC / LSF<br/>[lpc.rs]"]
  node_pitch["Pitch detection<br/>[pitch.rs]"]
  node_voicing["Voicing analysis<br/>[voicing.rs]"]
  node_math["Math shim<br/>[math.rs]"]
end

subgraph group_transport["Parameters &amp; Bitstream"]
  node_quantize["Quantization<br/>[quantize.rs]"]
  node_bitstream["Bitstream codec<br/>[bitstream.rs]"]
  node_core_types["Codec parameters<br/>[core_types.rs]"]
end

subgraph group_synthesis["Speech Synthesis"]
  node_excitation["Mixed excitation<br/>[voicing.rs]"]
  node_synthesis["Filter &amp; de-emphasis<br/>[synthesis.rs]"]
end

node_audio_in(("Audio input"))
node_audio_out(("Audio output"))
node_libm["libm"]

node_audio_in -->|"provides samples"| node_encoder
node_encoder -->|"analyzes spectrum"| node_lpc
node_encoder -->|"estimates pitch"| node_pitch
node_encoder -->|"analyzes voicing"| node_voicing
node_encoder -->|"quantizes parameters"| node_quantize
node_encoder -->|"packs parameters"| node_bitstream
node_encoder -->|"uses frame types"| node_core_types
node_encoder -->|"emits six bytes"| node_bitstream
node_bitstream -->|"provides six bytes"| node_decoder
node_decoder -->|"unpacks parameters"| node_bitstream
node_decoder -->|"dequantizes parameters"| node_quantize
node_decoder -->|"generates excitation"| node_excitation
node_decoder -->|"synthesizes frames"| node_synthesis
node_decoder -->|"uses frame types"| node_core_types
node_decoder -->|"returns samples"| node_audio_out
node_excitation -->|"uses voicing methods"| node_voicing
node_synthesis -->|"uses LPC conversion"| node_lpc
node_lpc -->|"uses math functions"| node_math
node_pitch -->|"uses math functions"| node_math
node_voicing -->|"uses math functions"| node_math
node_quantize -->|"uses math functions"| node_math
node_synthesis -->|"uses math functions"| node_math
node_math -.->|"dispatches in embedded builds"| node_libm

click node_encoder "https://github.com/heroeslament/melpe-rs/blob/main/src/encoder.rs"
click node_decoder "https://github.com/heroeslament/melpe-rs/blob/main/src/decoder.rs"
click node_lpc "https://github.com/heroeslament/melpe-rs/blob/main/src/lpc.rs"
click node_pitch "https://github.com/heroeslament/melpe-rs/blob/main/src/pitch.rs"
click node_voicing "https://github.com/heroeslament/melpe-rs/blob/main/src/voicing.rs"
click node_quantize "https://github.com/heroeslament/melpe-rs/blob/main/src/quantize.rs"
click node_bitstream "https://github.com/heroeslament/melpe-rs/blob/main/src/bitstream.rs"
click node_core_types "https://github.com/heroeslament/melpe-rs/blob/main/src/core_types.rs"
click node_excitation "https://github.com/heroeslament/melpe-rs/blob/main/src/voicing.rs"
click node_synthesis "https://github.com/heroeslament/melpe-rs/blob/main/src/synthesis.rs"
click node_math "https://github.com/heroeslament/melpe-rs/blob/main/src/math.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_encoder,node_decoder toneBlue
class node_lpc,node_pitch,node_voicing,node_math toneAmber
class node_quantize,node_bitstream,node_core_types toneMint
class node_excitation,node_synthesis toneRose
class node_audio_in,node_audio_out,node_libm toneIndigo
```

## Components

### Codec API

- [Encoder](https://github.com/heroeslament/melpe-rs/blob/main/src/encoder.rs): `src/encoder.rs`
- [Decoder](https://github.com/heroeslament/melpe-rs/blob/main/src/decoder.rs): `src/decoder.rs`

### Speech Analysis

- [LPC / LSF](https://github.com/heroeslament/melpe-rs/blob/main/src/lpc.rs): `src/lpc.rs`
- [Pitch detection](https://github.com/heroeslament/melpe-rs/blob/main/src/pitch.rs): `src/pitch.rs`
- [Voicing analysis](https://github.com/heroeslament/melpe-rs/blob/main/src/voicing.rs): `src/voicing.rs`
- [Math shim](https://github.com/heroeslament/melpe-rs/blob/main/src/math.rs): `src/math.rs`

### Parameters & Bitstream

- [Quantization](https://github.com/heroeslament/melpe-rs/blob/main/src/quantize.rs): `src/quantize.rs`
- [Bitstream codec](https://github.com/heroeslament/melpe-rs/blob/main/src/bitstream.rs): `src/bitstream.rs`
- [Codec parameters](https://github.com/heroeslament/melpe-rs/blob/main/src/core_types.rs): `src/core_types.rs`

### Speech Synthesis

- [Mixed excitation](https://github.com/heroeslament/melpe-rs/blob/main/src/voicing.rs): `src/voicing.rs`
- [Filter & de-emphasis](https://github.com/heroeslament/melpe-rs/blob/main/src/synthesis.rs): `src/synthesis.rs`

### Other components

- **Audio input**
- **Audio output**
- **libm**

## Connections

- Audio input → Encoder: provides samples (evidence: `README.md`)
- Encoder → LPC / LSF: analyzes spectrum (evidence: `src/encoder.rs`)
- Encoder → Pitch detection: estimates pitch (evidence: `src/encoder.rs`)
- Encoder → Voicing analysis: analyzes voicing (evidence: `src/encoder.rs`)
- Encoder → Quantization: quantizes parameters (evidence: `src/encoder.rs`)
- Encoder → Bitstream codec: packs parameters (evidence: `src/encoder.rs`)
- Encoder → Codec parameters: uses frame types (evidence: `src/encoder.rs`)
- Encoder → Bitstream codec: emits six bytes (evidence: `README.md`)
- Bitstream codec → Decoder: provides six bytes (evidence: `README.md`)
- Decoder → Bitstream codec: unpacks parameters (evidence: `README.md`)
- Decoder → Quantization: dequantizes parameters (evidence: `src/decoder.rs`)
- Decoder → Mixed excitation: generates excitation (evidence: `README.md`)
- Decoder → Filter & de-emphasis: synthesizes frames (evidence: `src/decoder.rs`)
- Decoder → Codec parameters: uses frame types (evidence: `src/decoder.rs`)
- Decoder → Audio output: returns samples (evidence: `README.md`)
- Mixed excitation → Voicing analysis: uses voicing methods (evidence: `README.md`)
- Filter & de-emphasis → LPC / LSF: uses LPC conversion (evidence: `src/synthesis.rs`)
- LPC / LSF → Math shim: uses math functions (evidence: `src/lpc.rs`)
- Pitch detection → Math shim: uses math functions (evidence: `src/pitch.rs`)
- Voicing analysis → Math shim: uses math functions (evidence: `src/voicing.rs`)
- Quantization → Math shim: uses math functions (evidence: `src/quantize.rs`)
- Filter & de-emphasis → Math shim: uses math functions (evidence: `src/synthesis.rs`)
- Math shim → libm: dispatches in embedded builds (evidence: `src/math.rs`)
