diff options
| author | skal <pascal.massimino@gmail.com> | 2026-01-28 09:34:29 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-01-28 09:34:29 +0100 |
| commit | 7631eaa56df1aea834998e9ce829bfb5937cdfdc (patch) | |
| tree | 7aaaef0de78a9a266abda4a8f5f608183a435195 | |
| parent | 302d883f34864bc66a5e04532ae27d7e89fd94e8 (diff) | |
docs: Update project context and session notes
Summarizes recent implementations including Asset Management, audio/visual fixes, and style improvements.
| -rw-r--r-- | PROJECT_CONTEXT.md | 19 | ||||
| -rw-r--r-- | SESSION_NOTES.md | 30 | ||||
| -rw-r--r-- | src/audio/synth.cc | 12 | ||||
| -rw-r--r-- | tools/asset_packer.cc | 4 |
4 files changed, 55 insertions, 10 deletions
diff --git a/PROJECT_CONTEXT.md b/PROJECT_CONTEXT.md index 28f86f8..acc0b43 100644 --- a/PROJECT_CONTEXT.md +++ b/PROJECT_CONTEXT.md @@ -36,30 +36,45 @@ Incoming tasks in no particular order: - [x] 8. add a #define STRIP_ALL to remove all unnecessary code for the final build (for instance, command-line args parsing, or unnecessary options, constant parameters to function calls, etc.) -- [ ] 9. work on the compact in-line and off-line asset system (@ASSET_SYSTEM.md) -- 9. work on the compact in-line and off-line asset system (@ASSET_SYSTEM.md) +- [x] 9. work on the compact in-line and off-line asset system (@ASSET_SYSTEM.md) ## Session Decisions and Current State +### Asset Management System: +- **Architecture**: Implemented a C++ tool (`asset_packer`) that bundles external files into the binary. +- **Descriptors**: Assets are defined in `assets/final/assets.txt` with optional compression settings. +- **Runtime Access**: Provides a type-safe `AssetId` enum and `GetAsset` function for retrieving raw byte data at runtime. +- **Integration**: Fully integrated into the CMake build process with automatic header/source generation. +- **Lazy Decompression**: Scaffolding implemented for future on-demand decompression support. + ### Audio Engine (Synth): - **Architecture**: Real-time additive synthesis from spectrograms using Inverse Discrete Cosine Transform (IDCT). - **Dynamic Updates**: Implemented a double-buffering (flip-flop) mechanism for thread-safe, real-time updates of spectrogram data. The main thread writes to a back buffer, which is then atomically swapped to become the active front buffer for the audio thread, avoiding real-time allocations and locks. +- **Peak Detection**: Real-time output peak detection with exponential decay for smooth visual synchronization. - **Sample Generation**: Samples are generated in the frequency domain (spectrograms) and converted to time-domain audio using IDCT with a Hamming window. - **Audio Input Support (`spectool`)**: Supports WAV and MP3 input for analysis (leveraging `miniaudio`'s built-in decoders). AAC is explicitly *not* supported due to complexity and dependency constraints. ### Tools Developed: - `spectool`: A command-line tool for analyzing WAV/MP3 files into `.spec` spectrogram format and for playing back `.spec` files through the synth engine. - `specview`: A command-line tool for visualizing `.spec` spectrogram files in ASCII art. +- `asset_packer`: A build-time tool for embedding assets into the binary. ### WebGPU Integration: - **Strategy**: Uses system-installed `wgpu-native` (e.g., via Homebrew) for the implementation. - **Surface Creation**: Uses `glfw3webgpu` helper library to abstract platform-specific surface creation from GLFW windows, keeping the codebase clean and cross-platform. - **Headers**: Uses standard `<webgpu.h>` provided by the system install. +- **Visuals**: Pulsating heptagon synchronized with audio peaks, with automatic aspect ratio correction. ### Coding Style: - **Standard**: Adopted a consistent coding style enforced by `.clang-format`. - **Rules**: 2-space indentation, no tabs, 80-column line limit. +- **Headers**: Mandatory 3-line descriptive header at the top of every `.h` and `.cc` file. - **File Extension**: All C++ source files renamed from `.cpp` to `.cc`. +### Platform & Input: +- **Windowing**: Uses GLFW for cross-platform window management. +- **Input**: Supports 'Esc' and 'Q' for quitting, and 'F' for toggling fullscreen. + ### Development Workflow: - **Commit Policy**: Explicit rule to always run the full test suite before preparing any commit, documented in `CONTRIBUTING.md`. +- **Testing**: Comprehensive test suite including `AssetManagerTest`, `SynthEngineTest`, `HammingWindowTest`, and `SpectoolEndToEndTest`. diff --git a/SESSION_NOTES.md b/SESSION_NOTES.md index 55e4fc1..77ff1be 100644 --- a/SESSION_NOTES.md +++ b/SESSION_NOTES.md @@ -21805,4 +21805,32 @@ why is clang-format taking so long? ## USER 🧑💻 -why is clang-format taking so long?
\ No newline at end of file +why is clang-format taking so long? +--- + +## Session Summary (Jan 28, 2026) + +### Accomplishments: +1. **Asset Management System**: + * Created ASSET_SYSTEM.md to define the architecture. + * Developed tools/asset_packer.cc to bundle external files as hex-encoded C arrays. + * Integrated into CMake with automatic assets.h and assets_data.cc generation. + * Added AssetManagerTest to verify integrity. +2. **Code Quality & Style**: + * Established a rule in CONTRIBUTING.md requiring a 3-line descriptive header for all source files. + * Performed a project-wide pass to apply these headers to all .h and .cc files. + * Updated clang-format command to exclude large directories (assets/, archive/, third_party/). +3. **Visuals & Audio**: + * Implemented exponential decay for audio peaks to create a smooth 'peak meter' effect for visuals. + * Added aspect ratio correction to the WGSL shader to prevent distortion on resize. + * Fixed a critical bug where STRIP_ALL was removing shader entry point names. +4. **Platform & Build**: + * Added 'Q' key as an alternative to 'Esc' for quitting. + * Optimized macOS build flags (-dead_strip instead of --gc-sections). + * Improved scripts/crunch_demo.sh to use strip and gzexe on macOS, achieving a ~48KB compressed binary. +5. **Documentation**: + * Updated PROJECT_CONTEXT.md, HOWTO.md, and GEMINI.md with new systems and instructions. + +### Status: +* Tasks 1, 2, 3, 7, 8, and 9 from the original list are now **Complete**. +* The demo is fully functional with audio-visual synchronization and fits within the 64k limit on macOS. diff --git a/src/audio/synth.cc b/src/audio/synth.cc index 8380301..2242d5c 100644 --- a/src/audio/synth.cc +++ b/src/audio/synth.cc @@ -35,7 +35,8 @@ static struct { } g_synth_data; static Voice g_voices[MAX_VOICES]; -static volatile float g_current_output_peak = 0.0f; // Global peak for visualization +static volatile float g_current_output_peak = + 0.0f; // Global peak for visualization void synth_init() { memset(&g_synth_data, 0, sizeof(g_synth_data)); @@ -183,9 +184,8 @@ void synth_render(float *output_buffer, int num_frames) { output_buffer[i * 2 + 1] = right_sample; // Update the peak with the new max (attack) - g_current_output_peak = - fmaxf(g_current_output_peak, - fmaxf(fabsf(left_sample), fabsf(right_sample))); + g_current_output_peak = fmaxf( + g_current_output_peak, fmaxf(fabsf(left_sample), fabsf(right_sample))); } } @@ -199,4 +199,6 @@ int synth_get_active_voice_count() { return count; } -float synth_get_output_peak() { return g_current_output_peak; } +float synth_get_output_peak() { + return g_current_output_peak; +} diff --git a/tools/asset_packer.cc b/tools/asset_packer.cc index 8696646..1e29578 100644 --- a/tools/asset_packer.cc +++ b/tools/asset_packer.cc @@ -113,8 +113,8 @@ int main(int argc, char *argv[]) { << (i == buffer.size() - 1 ? "" : ", "); } assets_data_cc_file << "\n};\n"; - assets_data_cc_file << "const size_t ASSET_SIZE_" << asset_name - << " = " << buffer.size() << ";\n\n"; + assets_data_cc_file << "const size_t ASSET_SIZE_" << asset_name << " = " + << buffer.size() << ";\n\n"; asset_id_counter++; } |
