# dolbylaboratories/spdif architecture

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

- Interactive diagram: https://gitdiagram.com/dolbylaboratories/spdif
- Repository: https://github.com/dolbylaboratories/spdif

## Overview

SPDIF is a command-line audio transport converter: it accepts AC-3/E-AC-3 elementary streams and produces IEC 60958/IEC 61937-compatible output; the README also describes deformatting. The visible implementation centers on the CLI, transport logic, and a reusable Dolby bitstream interface. The graph preserves the documented conversion/deformatting workflow and the sampled parsing/support layers. Some subsystem relationships are documented only at a high level; those links are dashed where source call paths were not shown.

Main entry points: [`spdif.c`](https://github.com/dolbylaboratories/spdif/blob/master/spdif.c) (SPDIF command), [`common/fmi/c_ref/code/fmi_api.c`](https://github.com/dolbylaboratories/spdif/blob/master/common/fmi/c_ref/code/fmi_api.c) (Frame API), [`common/bsi/c_ref/code/bsid_ddp.c`](https://github.com/dolbylaboratories/spdif/blob/master/common/bsi/c_ref/code/bsid_ddp.c) (BSI unpacking), [`common/bitstream_ops/c_ref/code/bsod.c`](https://github.com/dolbylaboratories/spdif/blob/master/common/bitstream_ops/c_ref/code/bsod.c) (Bitstream reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["CLI and transport"]
  node_spdif["SPDIF command<br/>[spdif.c]"]
  node_transport["IEC transport<br/>[spdif.c]"]
  node_tables["Transport data<br/>[data.c]"]
end

subgraph group_interface["Frame interface"]
  node_fmi["Frame API<br/>[fmi_api.c]"]
  node_frame_util["Frame utilities<br/>[fmi_utl.c]"]
end

subgraph group_parsing["Bitstream parsing"]
  node_bsi["BSI unpacking<br/>[bsid_ddp.c]"]
  node_bsi_types["BSI structures"]
  node_bitstream["Bitstream reader<br/>[bsod.c]"]
  node_auxdata["Aux data<br/>[axdd.c]"]
  node_drc["Dynamic range<br/>[drcd.h]"]
end

subgraph group_support["Shared support"]
  node_globals["Global definitions<br/>[gbl.c]"]
  node_errors["Error handling<br/>[err.h]"]
  node_debug["Debug support<br/>[dbg.h]"]
end

node_user(("CLI user"))
node_output["IEC audio output"]
node_input["Audio elementary stream"]

node_user -->|"runs"| node_spdif
node_input -->|"provides stream"| node_spdif
node_spdif -.->|"dispatches"| node_transport
node_transport -->|"formats"| node_output
node_spdif -.->|"uses frame API"| node_fmi
node_transport -.->|"uses tables"| node_tables
node_fmi -->|"uses BSI parsing"| node_bsi
node_fmi -->|"reads bits"| node_bitstream
node_fmi -->|"uses DRC types"| node_drc
node_frame_util -->|"maps frame data"| node_bsi
node_frame_util -->|"uses aux data"| node_auxdata
node_bsi -->|"unpacks bits"| node_bitstream
node_bsi -->|"uses DRC types"| node_drc
node_auxdata -->|"reads bits"| node_bitstream
node_bitstream -->|"uses declarations"| node_spdif

click node_spdif "https://github.com/dolbylaboratories/spdif/blob/master/spdif.c"
click node_transport "https://github.com/dolbylaboratories/spdif/blob/master/spdif.c"
click node_tables "https://github.com/dolbylaboratories/spdif/blob/master/data.c"
click node_fmi "https://github.com/dolbylaboratories/spdif/blob/master/common/fmi/c_ref/code/fmi_api.c"
click node_frame_util "https://github.com/dolbylaboratories/spdif/blob/master/common/fmi/c_ref/code/fmi_utl.c"
click node_bsi "https://github.com/dolbylaboratories/spdif/blob/master/common/bsi/c_ref/code/bsid_ddp.c"
click node_bitstream "https://github.com/dolbylaboratories/spdif/blob/master/common/bitstream_ops/c_ref/code/bsod.c"
click node_auxdata "https://github.com/dolbylaboratories/spdif/blob/master/common/auxdata/c_ref/code/axdd.c"
click node_drc "https://github.com/dolbylaboratories/spdif/blob/master/common/drc/c_ref/code/drcd.h"
click node_globals "https://github.com/dolbylaboratories/spdif/blob/master/common/global/c_ref/code/gbl.c"
click node_errors "https://github.com/dolbylaboratories/spdif/blob/master/common/error/c_ref/code/err.h"
click node_debug "https://github.com/dolbylaboratories/spdif/blob/master/common/debug/c_ref/code/dbg.h"

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_spdif,node_transport,node_tables,node_user toneBlue
class node_fmi,node_frame_util toneAmber
class node_bsi,node_bsi_types,node_bitstream,node_auxdata,node_drc toneMint
class node_globals,node_errors,node_debug toneRose
class node_output,node_input toneIndigo
```

## Components

### CLI and transport

- [SPDIF command](https://github.com/dolbylaboratories/spdif/blob/master/spdif.c): `spdif.c`
- [IEC transport](https://github.com/dolbylaboratories/spdif/blob/master/spdif.c): `spdif.c`
- [Transport data](https://github.com/dolbylaboratories/spdif/blob/master/data.c): `data.c`

### Frame interface

- [Frame API](https://github.com/dolbylaboratories/spdif/blob/master/common/fmi/c_ref/code/fmi_api.c): `common/fmi/c_ref/code/fmi_api.c`
- [Frame utilities](https://github.com/dolbylaboratories/spdif/blob/master/common/fmi/c_ref/code/fmi_utl.c): `common/fmi/c_ref/code/fmi_utl.c`

### Bitstream parsing

- [BSI unpacking](https://github.com/dolbylaboratories/spdif/blob/master/common/bsi/c_ref/code/bsid_ddp.c): `common/bsi/c_ref/code/bsid_ddp.c`
- **BSI structures**
- [Bitstream reader](https://github.com/dolbylaboratories/spdif/blob/master/common/bitstream_ops/c_ref/code/bsod.c): `common/bitstream_ops/c_ref/code/bsod.c`
- [Aux data](https://github.com/dolbylaboratories/spdif/blob/master/common/auxdata/c_ref/code/axdd.c): `common/auxdata/c_ref/code/axdd.c`
- [Dynamic range](https://github.com/dolbylaboratories/spdif/blob/master/common/drc/c_ref/code/drcd.h): `common/drc/c_ref/code/drcd.h`

### Shared support

- [Global definitions](https://github.com/dolbylaboratories/spdif/blob/master/common/global/c_ref/code/gbl.c): `common/global/c_ref/code/gbl.c`
- [Error handling](https://github.com/dolbylaboratories/spdif/blob/master/common/error/c_ref/code/err.h): `common/error/c_ref/code/err.h`
- [Debug support](https://github.com/dolbylaboratories/spdif/blob/master/common/debug/c_ref/code/dbg.h): `common/debug/c_ref/code/dbg.h`

### Other components

- **CLI user**
- **IEC audio output**
- **Audio elementary stream**

## Connections

- CLI user → SPDIF command: runs (evidence: `README.md`)
- Audio elementary stream → SPDIF command: provides stream (evidence: `README.md`)
- SPDIF command → IEC transport: dispatches (evidence: `spdif.c`)
- IEC transport → IEC audio output: formats (evidence: `README.md`)
- SPDIF command → Frame API: uses frame API
- IEC transport → Transport data: uses tables
- Frame API → BSI unpacking: uses BSI parsing (evidence: `common/fmi/c_ref/code/fmi_api.c`)
- Frame API → Bitstream reader: reads bits (evidence: `common/fmi/c_ref/code/fmi_api.c`)
- Frame API → Dynamic range: uses DRC types (evidence: `common/fmi/c_ref/code/fmi_api.c`)
- Frame utilities → BSI unpacking: maps frame data (evidence: `common/fmi/c_ref/code/fmi_utl.c`)
- Frame utilities → Aux data: uses aux data (evidence: `common/fmi/c_ref/code/fmi_utl.c`)
- BSI unpacking → Bitstream reader: unpacks bits (evidence: `common/bsi/c_ref/code/bsid_ddp.c`)
- BSI unpacking → Dynamic range: uses DRC types (evidence: `common/bsi/c_ref/code/bsid_ddp.c`)
- Aux data → Bitstream reader: reads bits (evidence: `common/auxdata/c_ref/code/axdd.c`)
- Bitstream reader → SPDIF command: uses declarations (evidence: `common/bitstream_ops/c_ref/code/bsod.c`)
