# hoba3d/hoba-runtime architecture

> Architecture diagram of the GitHub repository hoba3d/hoba-runtime, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hoba3d/hoba-runtime
- Repository: https://github.com/hoba3d/hoba-runtime

## Overview

##### Project type and purpose
- This is a client-side JavaScript framework (HOBA renderer) for personalized binaural-audio rendering in web browsers. It provides a runtime library plus demo pages that show how to load head-related transfer functions (HRTFs) on demand, apply spatial panning, and output binaural audio via the Web Audio API.

##### File structure
- Top-level:
- LICENSE, README.md
- demos/ — static demo pages (HTML/CSS) and sample audio/HRTF data
- libs/ — third-party utilities (TrackballControls.js, osc2ws.js)
- renderer/ — core HOBA modules (hoba.js plus per-feature files)
- Patterns:
- “renderer/” contains modular components: listener, OSC interface, spatial panner, audio adapter (waa), HRTF loader (wavh), spatial source.
- “demos/” shows integration points: UI, WebGL controls, OSC-over-WebSocket, HTML/CSS styling, data assets.

##### README
- Confirms it’s the runtime portion of the HOBA framework.
- Purpose: personalized HRTF selection based on anthropometry.
- Target: web browsers, leveraging Web Audio API.

##### Elements
- Labels: “UI / Demo Pages,” “HOBA Core,” “Web Audio API,” “HRTF Data Store,” “OSC Server”
- UI → HOBA API calls
- HOBA modules → AudioContext nodes
- hoba-wavh → HRTF data files
- osc2ws → hoba-osc → hoba.js
- Blue for UI/Browser components
- Green for HOBA modules
- Orange for Web Audio API nodes
- Gray for external data/services

##### Final advice
- How data and control flow from the user or OSC server all the way to the audio output.
- Every essential interaction, but avoid clutter by aggregating low-level Web Audio nodes under one “AudioContext” wrapper if needed.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI / Demo Pages
    subgraph "UI / Demo Pages"
        direction TB
        UI1["hoba-explorer.html"]:::ui
        UI2["visual-renderer.js"]:::ui
        UI3["hoba-pannerdemo.html"]:::ui
        UI1 --> UI2
    end

    %% 3D UI Controls
    Trackball["TrackballControls.js"]:::ui

    %% OSC Bridge
    subgraph "WebSocket / OSC Bridge"
        direction TB
        OSCWS["osc2ws.js"]:::ui
        HobaOSC["hoba-osc.js"]:::ui
        OSCWS --> HobaOSC
    end

    %% HOBA Core Library
    subgraph "HOBA Core" 
        direction TB
        CoreEntry["hoba.js"]:::core
        Listener["hoba-listener.js"]:::core
        Source["hoba-spatialsource.js"]:::core
        Panner["hoba-spatialpanner.js"]:::core
        WAA["hoba-waa.js"]:::core
        WAVH["hoba-wavh.js"]:::core

        CoreEntry --> Listener
        CoreEntry --> Source
        CoreEntry --> Panner
        CoreEntry --> WAA
        CoreEntry --> WAVH
    end

    %% Web Audio API
    subgraph "Web Audio API"
        direction TB
        AudioCtx["AudioContext & Nodes"]:::audio
    end

    %% External Data / Services
    subgraph "External Data / Services"
        direction TB
        HRTFData["HRTF Data Store (.wavh)"]:::data
        AudioAssets["Demo Audio Assets (.wav)"]:::data
        OSCServer["OSC Server (optional)"]:::data
    end

    %% Connections
    UI2 -->|"calls API"| CoreEntry
    Trackball --> UI2
    OSCServer -->|"OSC over WS"| OSCWS
    HobaOSC -->|"feeds controls"| CoreEntry
    CoreEntry -->|"loads HRTF"| WAVH
    WAVH -->|"fetch"| HRTFData
    CoreEntry -->|"sets up graph"| WAA
    WAA --> AudioCtx
    CoreEntry -->|"inserts panner"| Panner
    Panner --> AudioCtx
    CoreEntry -->|"manages source"| Source
    Source --> AudioCtx
    Listener -->|"updates orientation"| Panner
    AudioAssets --> Source
    AudioCtx -->|"output audio"| Output["User Output"]:::ui

    %% Click Events
    click UI1 "https://github.com/hoba3d/hoba-runtime/blob/master/demos/hoba-explorer.html"
    click UI2 "https://github.com/hoba3d/hoba-runtime/blob/master/demos/visual-renderer.js"
    click UI3 "https://github.com/hoba3d/hoba-runtime/blob/master/demos/hoba-pannerdemo.html"
    click Trackball "https://github.com/hoba3d/hoba-runtime/blob/master/libs/TrackballControls.js"
    click OSCWS "https://github.com/hoba3d/hoba-runtime/blob/master/osc2ws.js"
    click HobaOSC "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-osc.js"
    click CoreEntry "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba.js"
    click Listener "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-listener.js"
    click Source "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-spatialsource.js"
    click Panner "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-spatialpanner.js"
    click WAA "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-waa.js"
    click WAVH "https://github.com/hoba3d/hoba-runtime/blob/master/renderer/hoba-wavh.js"
    click HRTFData "https://github.com/hoba3d/hoba-runtime/blob/master/demos/data/aalto.wavh"
    click AudioAssets "https://github.com/hoba3d/hoba-runtime/blob/master/demos/data/cowbell.wav"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef core fill:#E8F5E9,stroke:#1B5E20,color:#2E7D32
    classDef audio fill:#FFF3E0,stroke:#E65100,color:#EF6C00
    classDef data fill:#ECEFF1,stroke:#546E7A,color:#37474F
```
