# nycrov/monostereomod architecture

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

- Interactive diagram: https://gitdiagram.com/nycrov/monostereomod
- Repository: https://github.com/nycrov/monostereomod

## Overview

MonoStereoMod replaces Terraria’s audio playback path with MonoStereo while retaining compatibility with vanilla sound APIs. The main workflow is Terraria audio hooks routing sounds and music through cached or custom MonoStereo sources, then through track/effect controls and filters to an output device. Mod developers can register custom music and filters; players can configure output devices and latency. Vanilla wave-bank cues have a separate decoding path. Some relationships below rely on the README or SOURCE INDEX references; unsampled implementation details are not assumed.

Main entry points: [`Content/MonoStereoModAPI.cs`](https://github.com/nycrov/monostereomod/blob/master/Content/MonoStereoModAPI.cs) (Mod audio API), [`Content/Detours/SoundControl`](https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SoundControl) (Sound detours), [`Content/Detours/SystemIntegration`](https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SystemIntegration) (System detours), [`Content/Systems/SoundCache.cs`](https://github.com/nycrov/monostereomod/blob/master/Content/Systems/SoundCache.cs) (Sound cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Terraria Integration"]
  node_hooks_sound["Sound detours"]
  node_hooks_system["System detours"]
  node_utils["Audio utilities<br/>[MonoStereoUtils.cs]"]
  node_reflection["Reflection accessors<br/>[Reflection.cs]"]
end

subgraph group_audio["Audio Playback"]
  node_cache[("Sound cache<br/>[SoundCache.cs]")]
  node_sound_adapter["Sound effect adapter"]
  node_cached_reader["Cached sound reader"]
  node_filter["Audio filter<br/>[TerrariaFilter.cs]"]
end

subgraph group_music["Music Sources"]
  node_audio_track["MonoStereo track"]
  node_highperf["High-performance source"]
  node_cue_reader["Cue stream reader<br/>[CueReader.cs]"]
  node_wavebank["Wave-bank cue decoder<br/>[WaveBankCue.cs]"]
  node_content_source["Vanilla cue source"]
end

subgraph group_configuration["Configuration and API"]
  node_api["Mod audio API"]
  node_config["Output settings"]
  node_config_ui["Config UI elements"]
end

node_terraria(("Terraria audio"))
node_moddev(("Mod developer"))
node_engine["MonoStereo engine"]
node_output["PortAudio output"]

node_terraria -->|"invokes hooks"| node_hooks_sound
node_terraria -->|"invokes hooks"| node_hooks_system
node_hooks_sound -->|"looks up sounds"| node_cache
node_hooks_sound -->|"forwards playback"| node_sound_adapter
node_hooks_sound -->|"reads internals"| node_reflection
node_hooks_sound -->|"tracks instances"| node_cache
node_cache -->|"creates reader"| node_cached_reader
node_cache -->|"caches effects"| node_sound_adapter
node_sound_adapter -->|"applies controls"| node_filter
node_api -->|"registers audio"| node_cache
node_api -->|"creates tracks"| node_audio_track
node_api -->|"uses utilities"| node_utils
node_moddev -->|"registers sources"| node_api
node_audio_track -->|"applies controls"| node_filter
node_audio_track -->|"plays source"| node_engine
node_hooks_system -->|"registers hooks"| node_api
node_hooks_system -->|"loads tracks"| node_audio_track
node_hooks_system -->|"selects source"| node_highperf
node_hooks_system -->|"loads cues"| node_cue_reader
node_highperf -->|"streams audio"| node_engine
node_content_source -->|"reads cues"| node_wavebank
node_content_source -->|"wraps cues"| node_cue_reader
node_cue_reader -->|"reads samples"| node_wavebank
node_config_ui -->|"edits settings"| node_config
node_config -->|"resets output"| node_api
node_api -->|"configures device"| node_output
node_engine -->|"sends audio"| node_output

click node_hooks_sound "https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SoundControl"
click node_hooks_system "https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SystemIntegration"
click node_cache "https://github.com/nycrov/monostereomod/blob/master/Content/Systems/SoundCache.cs"
click node_sound_adapter "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/MonoStereoSoundEffect.cs"
click node_cached_reader "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SoundSources/TerrariaCachedSoundEffectReader.cs"
click node_filter "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/Structures/TerrariaFilter.cs"
click node_api "https://github.com/nycrov/monostereomod/blob/master/Content/MonoStereoModAPI.cs"
click node_config "https://github.com/nycrov/monostereomod/blob/master/Content/Config/MonoStereoConfig.cs"
click node_config_ui "https://github.com/nycrov/monostereomod/tree/master/Content/Config/UI"
click node_audio_track "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/MonoStereoAudioTrack.cs"
click node_highperf "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SongSources/HighPerformanceSongSource.cs"
click node_cue_reader "https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SongSources/WaveStreams/CueReader.cs"
click node_wavebank "https://github.com/nycrov/monostereomod/blob/master/Content/Systems/VanillaReaders/WaveBankCue.cs"
click node_content_source "https://github.com/nycrov/monostereomod/blob/master/Content/Systems/VanillaReaders/CueReadingContentSource.cs"
click node_utils "https://github.com/nycrov/monostereomod/blob/master/Content/Utils/MonoStereoUtils.cs"
click node_reflection "https://github.com/nycrov/monostereomod/blob/master/Content/Utils/Reflection.cs"

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_hooks_sound,node_hooks_system,node_utils,node_reflection toneBlue
class node_cache,node_sound_adapter,node_cached_reader,node_filter toneAmber
class node_audio_track,node_highperf,node_cue_reader,node_wavebank,node_content_source toneMint
class node_api,node_config,node_config_ui toneRose
class node_terraria,node_moddev,node_engine,node_output toneIndigo
```

## Components

### Terraria Integration

- [Sound detours](https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SoundControl): `Content/Detours/SoundControl`
- [System detours](https://github.com/nycrov/monostereomod/tree/master/Content/Detours/SystemIntegration): `Content/Detours/SystemIntegration`
- [Audio utilities](https://github.com/nycrov/monostereomod/blob/master/Content/Utils/MonoStereoUtils.cs): `Content/Utils/MonoStereoUtils.cs`
- [Reflection accessors](https://github.com/nycrov/monostereomod/blob/master/Content/Utils/Reflection.cs): `Content/Utils/Reflection.cs`

### Audio Playback

- [Sound cache](https://github.com/nycrov/monostereomod/blob/master/Content/Systems/SoundCache.cs): `Content/Systems/SoundCache.cs`
- [Sound effect adapter](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/MonoStereoSoundEffect.cs): `Content/Audio/MonoStereoSoundEffect.cs`
- [Cached sound reader](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SoundSources/TerrariaCachedSoundEffectReader.cs): `Content/Audio/SoundSources/TerrariaCachedSoundEffectReader.cs`
- [Audio filter](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/Structures/TerrariaFilter.cs): `Content/Audio/Structures/TerrariaFilter.cs`

### Music Sources

- [MonoStereo track](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/MonoStereoAudioTrack.cs): `Content/Audio/MonoStereoAudioTrack.cs`
- [High-performance source](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SongSources/HighPerformanceSongSource.cs): `Content/Audio/SongSources/HighPerformanceSongSource.cs`
- [Cue stream reader](https://github.com/nycrov/monostereomod/blob/master/Content/Audio/SongSources/WaveStreams/CueReader.cs): `Content/Audio/SongSources/WaveStreams/CueReader.cs`
- [Wave-bank cue decoder](https://github.com/nycrov/monostereomod/blob/master/Content/Systems/VanillaReaders/WaveBankCue.cs): `Content/Systems/VanillaReaders/WaveBankCue.cs`
- [Vanilla cue source](https://github.com/nycrov/monostereomod/blob/master/Content/Systems/VanillaReaders/CueReadingContentSource.cs): `Content/Systems/VanillaReaders/CueReadingContentSource.cs`

### Configuration and API

- [Mod audio API](https://github.com/nycrov/monostereomod/blob/master/Content/MonoStereoModAPI.cs): `Content/MonoStereoModAPI.cs`
- [Output settings](https://github.com/nycrov/monostereomod/blob/master/Content/Config/MonoStereoConfig.cs): `Content/Config/MonoStereoConfig.cs`
- [Config UI elements](https://github.com/nycrov/monostereomod/tree/master/Content/Config/UI): `Content/Config/UI`

### Other components

- **Terraria audio**
- **Mod developer**
- **MonoStereo engine**
- **PortAudio output**

## Connections

- Terraria audio → Sound detours: invokes hooks
- Terraria audio → System detours: invokes hooks
- Sound detours → Sound cache: looks up sounds (evidence: `Content/Detours/SoundControl/SoundEffectDetours.cs`)
- Sound detours → Sound effect adapter: forwards playback (evidence: `Content/Detours/SoundControl/SoundEffectDetours.cs`)
- Sound detours → Reflection accessors: reads internals (evidence: `Content/Detours/SoundControl/SoundEffectDetours.cs`)
- Sound detours → Sound cache: tracks instances (evidence: `Content/Detours/SoundControl/SoundEffectInstanceDetours.cs`)
- Sound cache → Cached sound reader: creates reader (evidence: `Content/Systems/SoundCache.cs`)
- Sound cache → Sound effect adapter: caches effects (evidence: `Content/Systems/SoundCache.cs`)
- Sound effect adapter → Audio filter: applies controls (evidence: `Content/Audio/MonoStereoSoundEffect.cs`)
- Mod audio API → Sound cache: registers audio (evidence: `Content/MonoStereoModAPI.cs`)
- Mod audio API → MonoStereo track: creates tracks (evidence: `Content/MonoStereoModAPI.cs`)
- Mod audio API → Audio utilities: uses utilities (evidence: `Content/MonoStereoModAPI.cs`)
- Mod developer → Mod audio API: registers sources
- MonoStereo track → Audio filter: applies controls (evidence: `Content/Audio/MonoStereoAudioTrack.cs`)
- MonoStereo track → MonoStereo engine: plays source
- System detours → Mod audio API: registers hooks (evidence: `Content/MonoStereoModAPI.cs`)
- System detours → MonoStereo track: loads tracks (evidence: `Content/Detours/SystemIntegration/MusicLoaderDetours.cs`)
- System detours → High-performance source: selects source (evidence: `Content/Detours/SystemIntegration/MusicLoaderDetours.cs`)
- System detours → Cue stream reader: loads cues (evidence: `Content/Detours/SystemIntegration/LegacyAudioSystemDetours.cs`)
- High-performance source → MonoStereo engine: streams audio
- Vanilla cue source → Wave-bank cue decoder: reads cues (evidence: `Content/Systems/VanillaReaders/CueReadingContentSource.cs`)
- Vanilla cue source → Cue stream reader: wraps cues (evidence: `Content/Systems/VanillaReaders/CueReadingContentSource.cs`)
- Cue stream reader → Wave-bank cue decoder: reads samples (evidence: `Content/Audio/SongSources/WaveStreams/CueReader.cs`)
- Config UI elements → Output settings: edits settings (evidence: `Content/Config/MonoStereoConfig.cs`)
- Output settings → Mod audio API: resets output (evidence: `Content/Config/MonoStereoConfig.cs`)
- Mod audio API → PortAudio output: configures device
- MonoStereo engine → PortAudio output: sends audio
