# ic-scm/openrevolution architecture

> Architecture diagram of the GitHub repository ic-scm/openrevolution, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ic-scm/openrevolution
- Repository: https://github.com/ic-scm/openrevolution

## Overview

##### Project type and purpose
- This is a C++‐based open‐source command‐line toolkit plus library (“OpenRevolution”) for decoding, encoding, converting and playing Nintendo audio formats (BRSTM, BCSTM, BFSTM, BWAV, etc.). It provides:
- A core library (`src/lib/…`) exposing encoder/decoder APIs
- CLI tools (`src/converter.cpp`, `src/decoder.cpp`, `src/encoder.cpp`, `src/rebuilder.cpp`, `src/reencoder.cpp`)
- A real-time player (`src/rt_player/…`) using RtAudio

##### File structure
- Top-level artifacts:
- `build.sh` – build script
- `README.md`, `LICENSE`
- `src/`:
- `converter.cpp`, `decoder.cpp`, `encoder.cpp`, `rebuilder.cpp`, `reencoder.cpp` – command‐line frontends
- `lib/` – core library modules:
– `audio_decoder.h` / `audio_encoder.h` – public interfaces
– `brstm.h`, `brstm_encode.h` – format‐specific headers
– `crc/` – CRC utilities
– `d_formats/`, `e_formats/` – modular decode/encode format implementations
– `dspadpcm_encoder.c` – codec implementation
– `utils.h` – shared helpers
- `rt_player/` – real-time player:
– `main.cpp`, `ui.h`, `utils.h` – CLI UI
– `RtAudio.h`, `rtaudio_c.h` – external audio I/O
- No GUI yet; purely CLI + library

##### README for additional insights
- Describes supported formats, lossless conversion, usage instructions
- Mentions optional dependencies: ffmpeg (for advanced audio ops), librtaudio, POSIX threads

##### Detail
- Every logical sub‐component: separate decode vs. encode modules, CRC unit, DSPADPCM codec
- Don’t shy away from breaking the library core into its sub‐folders so the engineer sees each extension point

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "CLI Tools"
        Converter["Converter CLI"]:::cli
        Decoder["Decoder CLI"]:::cli
        Encoder["Encoder CLI"]:::cli
        Rebuilder["Rebuilder CLI"]:::cli
        Reencoder["Reencoder CLI"]:::cli
    end

    subgraph "Real-time Player"
        RealTime["Real-time Player (brstm_rt)"]:::cli
    end

    subgraph "Core Library"
        subgraph "Public API Layer"
            AudioDecoderAPI["Audio Decoder API"]:::library
            AudioEncoderAPI["Audio Encoder API"]:::library
        end
        subgraph "Format Modules"
            DecodeFormats["Decode Format Modules"]:::library
            EncodeFormats["Encode Format Modules"]:::library
        end
        CRCUtils["CRC Utilities"]:::library
        DSPCodec["DSP-ADPCM Codec"]:::library
        CoreUtils["Core Utilities"]:::library
    end

    subgraph "External Dependencies"
        FFMPEG["ffmpeg"]:::external
        RtAudioExt["RtAudio"]:::external
        POSIX["POSIX Threads"]:::external
    end

    %% Relationships
    Converter -->|invoke| AudioDecoderAPI
    Decoder -->|invoke| AudioDecoderAPI
    Encoder -->|invoke| AudioEncoderAPI
    Rebuilder -->|invoke| AudioDecoderAPI
    Reencoder -->|invoke| AudioDecoderAPI

    RealTime -->|invoke| AudioDecoderAPI
    RealTime -->|PCM stream| RtAudioExt
    RealTime -->|concurrency| POSIX

    AudioDecoderAPI -->|loads| DecodeFormats
    AudioEncoderAPI -->|loads| EncodeFormats

    DecodeFormats -->|use| DSPCodec
    DecodeFormats -->|use| CRCUtils
    DecodeFormats -->|use| CoreUtils

    EncodeFormats -->|use| DSPCodec
    EncodeFormats -->|use| CRCUtils
    EncodeFormats -->|use| CoreUtils

    %% Optional ffmpeg integration
    Converter -.->|optional shell| FFMPEG
    Decoder -.->|optional shell| FFMPEG
    Encoder -.->|optional shell| FFMPEG
    Rebuilder -.->|optional shell| FFMPEG
    Reencoder -.->|optional shell| FFMPEG

    %% Click Events
    click Converter "https://github.com/ic-scm/openrevolution/blob/master/src/converter.cpp"
    click Decoder "https://github.com/ic-scm/openrevolution/blob/master/src/decoder.cpp"
    click Encoder "https://github.com/ic-scm/openrevolution/blob/master/src/encoder.cpp"
    click Rebuilder "https://github.com/ic-scm/openrevolution/blob/master/src/rebuilder.cpp"
    click Reencoder "https://github.com/ic-scm/openrevolution/blob/master/src/reencoder.cpp"
    click RealTime "https://github.com/ic-scm/openrevolution/blob/master/src/rt_player/main.cpp"
    click AudioDecoderAPI "https://github.com/ic-scm/openrevolution/blob/master/src/lib/audio_decoder.h"
    click AudioEncoderAPI "https://github.com/ic-scm/openrevolution/blob/master/src/lib/audio_encoder.h"
    click DecodeFormats "https://github.com/ic-scm/openrevolution/tree/master/src/lib/d_formats/"
    click EncodeFormats "https://github.com/ic-scm/openrevolution/tree/master/src/lib/e_formats/"
    click CRCUtils "https://github.com/ic-scm/openrevolution/tree/master/src/lib/crc/"
    click DSPCodec "https://github.com/ic-scm/openrevolution/blob/master/src/lib/dspadpcm_encoder.c"
    click CoreUtils "https://github.com/ic-scm/openrevolution/blob/master/src/lib/utils.h"
    click RtAudioExt "https://github.com/ic-scm/openrevolution/blob/master/src/rt_player/RtAudio.h"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef library fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
