1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
# How To
Quick reference for common tasks.
---
## Building
### Workspace Selection
```bash
# Main demo (default)
cmake -S . -B build -DDEMO_WORKSPACE=main
cmake --build build -j4
./build/demo64k
# Test demo
cmake -S . -B build_test -DDEMO_WORKSPACE=test
cmake --build build_test -j4
./build_test/test_demo
```
### Debug Build
```bash
cmake -S . -B build
cmake --build build -j4
./build/demo64k
```
Options: `--fullscreen`, `--resolution WxH`, `--seek TIME`, `--hot-reload`
### Production Builds
```bash
# Size-optimized (development)
cmake -B build -DDEMO_SIZE_OPT=ON && cmake --build build -j4
# 64k target (full checks, no debug)
cmake -B build -DDEMO_STRIP_ALL=ON && cmake --build build -j4
# Final release (no checks, absolute minimum)
./scripts/build_final.sh
```
### Developer Build
```bash
cmake -B build -DDEMO_BUILD_TESTS=ON -DDEMO_BUILD_TOOLS=ON
cmake --build build -j4
```
### Headless Testing
```bash
cmake -B build_headless -DDEMO_HEADLESS=ON && cmake --build build_headless -j4
./build_headless/demo64k --headless --duration 30
```
See `doc/HEADLESS_MODE.md`.
### Size Measurement
```bash
./scripts/measure_size.sh
```
Measures demo vs external library size. See `doc/SIZE_MEASUREMENT.md`.
---
## Testing
### Run All Tests
```bash
cmake -B build -DDEMO_BUILD_TESTS=ON
cmake --build build -j4
cd build && ctest
# OR: make run_all_tests
```
### Run Subsystem Tests
```bash
make run_audio_tests # Audio system tests
make run_gpu_tests # GPU/shader tests
make run_3d_tests # 3D rendering tests
make run_assets_tests # Asset system tests
make run_util_tests # Utility tests
```
### Run Specific Test
```bash
./build/test_synth
```
---
## Training
### Patch-Based (Recommended)
Extracts patches at salient points, preserves natural pixel scale:
```bash
# Train with 32×32 patches at detected corners/edges
./training/train_cnn.py \
--input training/input/ --target training/output/ \
--patch-size 32 --patches-per-image 64 --detector harris \
--layers 3 --kernel_sizes 3,5,3 --epochs 5000 --batch_size 16 \
--checkpoint-every 1000
```
**Detectors:** `harris` (default), `fast`, `shi-tomasi`, `gradient`
### Full-Image (Legacy)
Resizes to 256×256 (distorts scale):
```bash
./training/train_cnn.py \
--input training/input/ --target training/output/ \
--layers 3 --kernel_sizes 3,5,3 --epochs 10000 --batch_size 8 \
--checkpoint-every 1000
```
### Export & Validation
```bash
# Generate shaders from checkpoint
./training/train_cnn.py --export-only checkpoints/checkpoint_epoch_5000.pth
# Generate ground truth for comparison
./training/train_cnn.py --infer input.png \
--export-only checkpoints/checkpoint_epoch_5000.pth \
--output ground_truth.png
```
**Kernel sizes:** 3×3 (36 weights), 5×5 (100 weights), 7×7 (196 weights)
---
## Timeline
Edit `workspaces/main/timeline.seq`:
```text
SEQUENCE 0.0 0
EFFECT + HeptagonEffect 0.0 60.0 0
```
Rebuild to apply. See `doc/SEQUENCE.md`.
---
## Audio
```cpp
#include "audio/audio_engine.h"
audio_init();
static AudioEngine g_audio_engine;
g_audio_engine.init();
g_audio_engine.update(music_time);
g_audio_engine.shutdown();
audio_shutdown();
```
See `doc/TRACKER.md` for music system.
---
## Assets
Edit `workspaces/main/assets.txt`, then rebuild:
```bash
cmake --build build -j4
```
See `doc/ASSET_SYSTEM.md` and `doc/WORKSPACE_SYSTEM.md`.
---
## CNN Testing
### Offline Shader Validation
**Note:** Tool builds and runs but produces incorrect output. Use CNNEffect visual validation in demo. See `doc/CNN_TEST_TOOL.md`.
```bash
# Test trained CNN on PNG input
./build/cnn_test input.png output.png
# Adjust blend amount (0.0 = original, 1.0 = full CNN)
./build/cnn_test input.png output.png --blend 0.5
# PPM output format
./build/cnn_test input.png output.ppm --format ppm
```
### Ground Truth Comparison
```bash
# Generate Python ground truth
./training/train_cnn.py --infer input.png \
--export-only checkpoints/checkpoint_epoch_1000.pth \
--output ground_truth.png
# Run tool
./build/cnn_test input.png tool_output.png
# Compare (Python required)
python3 -c "
import numpy as np
from PIL import Image
gt = np.array(Image.open('ground_truth.png').convert('RGB'))
out = np.array(Image.open('tool_output.png').convert('RGB'))
mse = np.mean((gt.astype(float) - out.astype(float)) ** 2)
print(f'MSE: {mse:.4f} (target: < 10.0)')
"
```
See `doc/CNN_TEST_TOOL.md` for full documentation.
---
## Modifying Build System
- **Add build option:** Edit `cmake/DemoOptions.cmake`
- **Add source files:** Edit `cmake/DemoSourceLists.cmake`
- **Add test:** Edit `cmake/DemoTests.cmake`
- **Add tool:** Edit `cmake/DemoTools.cmake`
- **Add library:** Edit `cmake/DemoLibraries.cmake`
See `doc/CMAKE_MODULES.md` for full architecture and shared macros.
---
## Additional Documentation
- **Build System:** `doc/BUILD.md` - Multi-platform, size optimization
- **CMake Modules:** `doc/CMAKE_MODULES.md` - Module architecture, shared macros
- **Tools:** `doc/TOOLS_REFERENCE.md` - spectool, coverage, Windows cross-compile
- **Shaders:** `doc/SEQUENCE.md` - Timeline format, shader parameters
- **3D:** `doc/3D.md` - Hybrid rendering, scene format
- **Hot Reload:** `doc/HOT_RELOAD.md` - Debug file watching
|