# timothytylee/libgsm architecture

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

- Interactive diagram: https://gitdiagram.com/timothytylee/libgsm
- Repository: https://github.com/timothytylee/libgsm

## Overview

This repository implements GSM 06.10 RPE/LTP speech compression as both a C library and the `toast` command-line front end. The principal workflow accepts audio, converts it to 160-sample frames, encodes or decodes GSM frames, and writes the resulting audio; the library also exposes frame packing and inspection. The README documents the product-level interfaces and format, while the excerpts do not expose most internal calls, so uncertain algorithm-stage links are dashed and have no evidence path.

Main entry points: [`inc/gsm.h`](https://github.com/timothytylee/libgsm/blob/master/inc/gsm.h) (Library interface), [`src/gsm_encode.c`](https://github.com/timothytylee/libgsm/blob/master/src/gsm_encode.c) (Frame encoder), [`src/toast_audio.c`](https://github.com/timothytylee/libgsm/blob/master/src/toast_audio.c) (Audio setup), [`src/gsm_decode.c`](https://github.com/timothytylee/libgsm/blob/master/src/gsm_decode.c) (Frame decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Command-line audio"]
  node_toast["Toast frontend<br/>[toast.c]"]
  node_audio_io["Audio setup<br/>[toast_audio.c]"]
end

subgraph group_formats["Audio formats"]
  node_linear["Linear audio<br/>[toast_lin.c]"]
  node_alaw["A-law audio<br/>[toast_alaw.c]"]
  node_ulaw["μ-law audio<br/>[toast_ulaw.c]"]
end

subgraph group_api["GSM library API"]
  node_gsm_api["Library interface<br/>[gsm.h]"]
  node_create["Codec lifecycle<br/>[gsm_create.c]"]
  node_options["Codec options<br/>[gsm_option.c]"]
end

subgraph group_codec["RPE/LTP codec"]
  node_encode["Frame encoder<br/>[gsm_encode.c]"]
  node_decode["Frame decoder<br/>[gsm_decode.c]"]
  node_lpc["LPC analysis<br/>[lpc.c]"]
  node_longterm["Long-term prediction<br/>[long_term.c]"]
  node_shortterm["Short-term filtering<br/>[short_term.c]"]
  node_rpe["RPE processing<br/>[rpe.c]"]
  node_preprocess["Signal preprocessing<br/>[preprocess.c]"]
end

subgraph group_packing["Frame formats"]
  node_explode["Frame unpacking<br/>[gsm_explode.c]"]
  node_implode["Frame packing<br/>[gsm_implode.c]"]
  node_taste["Packing descriptors<br/>[taste.h]"]
  node_taste_reader["Descriptor reader<br/>[taste.c]"]
  node_sour["WAV49 pack generator<br/>[sour.c]"]
end

node_user(("Audio user"))

node_user -->|"invokes"| node_toast
node_toast -.->|"sets up audio"| node_audio_io
node_toast -.->|"uses library"| node_gsm_api
node_audio_io -.->|"selects input/output"| node_linear
node_audio_io -.->|"selects input/output"| node_alaw
node_audio_io -.->|"selects input/output"| node_ulaw
node_gsm_api -.->|"creates state"| node_create
node_gsm_api -.->|"sets options"| node_options
node_gsm_api -.->|"encodes frames"| node_encode
node_gsm_api -.->|"decodes frames"| node_decode
node_encode -.->|"processes samples"| node_preprocess
node_encode -.->|"analyzes speech"| node_lpc
node_encode -.->|"predicts residual"| node_longterm
node_encode -.->|"encodes residual"| node_rpe
node_decode -.->|"reconstructs residual"| node_rpe
node_decode -.->|"synthesizes prediction"| node_longterm
node_decode -.->|"filters signal"| node_shortterm
node_gsm_api -.->|"unpacks frames"| node_explode
node_gsm_api -.->|"packs frames"| node_implode
node_taste_reader -->|"uses descriptors"| node_taste
node_sour -->|"uses descriptors"| node_taste

click node_toast "https://github.com/timothytylee/libgsm/blob/master/src/toast.c"
click node_audio_io "https://github.com/timothytylee/libgsm/blob/master/src/toast_audio.c"
click node_linear "https://github.com/timothytylee/libgsm/blob/master/src/toast_lin.c"
click node_alaw "https://github.com/timothytylee/libgsm/blob/master/src/toast_alaw.c"
click node_ulaw "https://github.com/timothytylee/libgsm/blob/master/src/toast_ulaw.c"
click node_gsm_api "https://github.com/timothytylee/libgsm/blob/master/inc/gsm.h"
click node_create "https://github.com/timothytylee/libgsm/blob/master/src/gsm_create.c"
click node_options "https://github.com/timothytylee/libgsm/blob/master/src/gsm_option.c"
click node_encode "https://github.com/timothytylee/libgsm/blob/master/src/gsm_encode.c"
click node_decode "https://github.com/timothytylee/libgsm/blob/master/src/gsm_decode.c"
click node_lpc "https://github.com/timothytylee/libgsm/blob/master/src/lpc.c"
click node_longterm "https://github.com/timothytylee/libgsm/blob/master/src/long_term.c"
click node_shortterm "https://github.com/timothytylee/libgsm/blob/master/src/short_term.c"
click node_rpe "https://github.com/timothytylee/libgsm/blob/master/src/rpe.c"
click node_preprocess "https://github.com/timothytylee/libgsm/blob/master/src/preprocess.c"
click node_explode "https://github.com/timothytylee/libgsm/blob/master/src/gsm_explode.c"
click node_implode "https://github.com/timothytylee/libgsm/blob/master/src/gsm_implode.c"
click node_taste "https://github.com/timothytylee/libgsm/blob/master/tls/taste.h"
click node_taste_reader "https://github.com/timothytylee/libgsm/blob/master/tls/taste.c"
click node_sour "https://github.com/timothytylee/libgsm/blob/master/tls/sour.c"

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_toast,node_audio_io,node_user toneBlue
class node_linear,node_alaw,node_ulaw toneAmber
class node_gsm_api,node_create,node_options toneMint
class node_encode,node_decode,node_lpc,node_longterm,node_shortterm,node_rpe,node_preprocess toneRose
class node_explode,node_implode,node_taste,node_taste_reader,node_sour toneIndigo
```

## Components

### Command-line audio

- [Toast frontend](https://github.com/timothytylee/libgsm/blob/master/src/toast.c): `src/toast.c`
- [Audio setup](https://github.com/timothytylee/libgsm/blob/master/src/toast_audio.c): `src/toast_audio.c`

### Audio formats

- [Linear audio](https://github.com/timothytylee/libgsm/blob/master/src/toast_lin.c): `src/toast_lin.c`
- [A-law audio](https://github.com/timothytylee/libgsm/blob/master/src/toast_alaw.c): `src/toast_alaw.c`
- [μ-law audio](https://github.com/timothytylee/libgsm/blob/master/src/toast_ulaw.c): `src/toast_ulaw.c`

### GSM library API

- [Library interface](https://github.com/timothytylee/libgsm/blob/master/inc/gsm.h): `inc/gsm.h`
- [Codec lifecycle](https://github.com/timothytylee/libgsm/blob/master/src/gsm_create.c): `src/gsm_create.c`
- [Codec options](https://github.com/timothytylee/libgsm/blob/master/src/gsm_option.c): `src/gsm_option.c`

### RPE/LTP codec

- [Frame encoder](https://github.com/timothytylee/libgsm/blob/master/src/gsm_encode.c): `src/gsm_encode.c`
- [Frame decoder](https://github.com/timothytylee/libgsm/blob/master/src/gsm_decode.c): `src/gsm_decode.c`
- [LPC analysis](https://github.com/timothytylee/libgsm/blob/master/src/lpc.c): `src/lpc.c`
- [Long-term prediction](https://github.com/timothytylee/libgsm/blob/master/src/long_term.c): `src/long_term.c`
- [Short-term filtering](https://github.com/timothytylee/libgsm/blob/master/src/short_term.c): `src/short_term.c`
- [RPE processing](https://github.com/timothytylee/libgsm/blob/master/src/rpe.c): `src/rpe.c`
- [Signal preprocessing](https://github.com/timothytylee/libgsm/blob/master/src/preprocess.c): `src/preprocess.c`

### Frame formats

- [Frame unpacking](https://github.com/timothytylee/libgsm/blob/master/src/gsm_explode.c): `src/gsm_explode.c`
- [Frame packing](https://github.com/timothytylee/libgsm/blob/master/src/gsm_implode.c): `src/gsm_implode.c`
- [Packing descriptors](https://github.com/timothytylee/libgsm/blob/master/tls/taste.h): `tls/taste.h`
- [Descriptor reader](https://github.com/timothytylee/libgsm/blob/master/tls/taste.c): `tls/taste.c`
- [WAV49 pack generator](https://github.com/timothytylee/libgsm/blob/master/tls/sour.c): `tls/sour.c`

### Other components

- **Audio user**

## Connections

- Audio user → Toast frontend: invokes (evidence: `README`)
- Toast frontend → Audio setup: sets up audio
- Toast frontend → Library interface: uses library
- Audio setup → Linear audio: selects input/output
- Audio setup → A-law audio: selects input/output
- Audio setup → μ-law audio: selects input/output
- Library interface → Codec lifecycle: creates state (evidence: `src/gsm_create.c`)
- Library interface → Codec options: sets options (evidence: `src/gsm_option.c`)
- Library interface → Frame encoder: encodes frames (evidence: `src/gsm_encode.c`)
- Library interface → Frame decoder: decodes frames (evidence: `src/gsm_decode.c`)
- Frame encoder → Signal preprocessing: processes samples
- Frame encoder → LPC analysis: analyzes speech
- Frame encoder → Long-term prediction: predicts residual
- Frame encoder → RPE processing: encodes residual
- Frame decoder → RPE processing: reconstructs residual
- Frame decoder → Long-term prediction: synthesizes prediction
- Frame decoder → Short-term filtering: filters signal
- Library interface → Frame unpacking: unpacks frames (evidence: `src/gsm_explode.c`)
- Library interface → Frame packing: packs frames (evidence: `src/gsm_implode.c`)
- Descriptor reader → Packing descriptors: uses descriptors (evidence: `tls/taste.c`)
- WAV49 pack generator → Packing descriptors: uses descriptors (evidence: `tls/sour.c`)
