summaryrefslogtreecommitdiff
path: root/src/main.cc
AgeCommit message (Collapse)Author
28 hoursfeat(audio): Add WAV dump backend for debugging audio outputskal
Implemented WavDumpBackend that renders audio to .wav file instead of playing on audio device. Useful for debugging audio synthesis, tempo scaling, and tracker output without needing real-time playback. New Files: - src/audio/wav_dump_backend.h: WAV dump backend interface - src/audio/wav_dump_backend.cc: Implementation with WAV file writing Features: - Command line option: --dump_wav [filename] - Default output: audio_dump.wav - Format: 16-bit PCM, mono, 32kHz - Duration: 60 seconds (configurable in code) - Progress indicator during rendering - Properly writes WAV header (RIFF format) Integration (src/main.cc): - Added --dump_wav command line parsing - Optional filename parameter - Sets WavDumpBackend before audio_init() - Skips main loop in WAV dump mode (just render and exit) - Zero size impact (all code under !STRIP_ALL) Usage: ./demo64k --dump_wav # outputs audio_dump.wav ./demo64k --dump_wav my_audio.wav # custom filename Technical Details: - Uses AudioBackend interface (from Task #51) - Calls synth_render() in loop to capture audio - Converts float samples to int16_t for WAV format - Updates WAV header with final sample count on shutdown - Renders 60s worth of audio (1,920,000 samples @ 32kHz) Test Results: ✓ All 16 tests passing (100%) ✓ Successfully renders 3.7 MB WAV file ✓ File verified as valid RIFF WAVE format ✓ Playback in audio players confirmed Perfect for: - Debugging tempo scaling behavior - Verifying tracker pattern timing - Analyzing audio output offline - Creating reference audio for tests handoff(Claude): WAV dump debugging feature complete Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
28 hoursfeat(audio): Simplified demo track with tempo scaling testsskal
Created debuggable drum beat track that tests variable tempo system with clear acceleration and deceleration phases. Music Track Changes (assets/music.track): - Simplified to clear drum patterns (kick, snare, hi-hat, crash) - Light kick syncopation for musicality - Regular crash accents every 4 seconds - Hi-hat stress on beats for clarity - Phase 1 (0-10s): Steady beat at 1.0x tempo - Phase 2 (10-16s): Acceleration test (1.0x → 2.0x, then reset to 1.0x) - Phase 3 (16-20s): Denser patterns after reset (kick_dense, snare_dense) - Phase 4 (20-26s): Slow-down test (1.0x → 0.5x, then reset to 1.0x) - Phase 5 (26-30s): Return to normal tempo - Phase 6 (30s+): Add bass line and E minor melody Tempo Control (src/main.cc): - Implemented phase-based tempo scaling logic - Phase 1 (0-10s physical): tempo = 1.0 (steady) - Phase 2 (10-15s physical): tempo = 1.0 → 2.0 (acceleration) - Phase 3 (15-20s physical): tempo = 1.0 (reset trick) - Phase 4 (20-25s physical): tempo = 1.0 → 0.5 (deceleration) - Phase 5 (25s+ physical): tempo = 1.0 (reset trick) - Added debug output showing tempo changes (!STRIP_ALL) Test Updates (src/tests/test_tracker.cc): - Updated voice count assertions to match new track (3 → 4 voices) - New track triggers 4 patterns at t=0: crash, kick, snare, hi-hat Results: ✓ All 16 tests passing (100%) ✓ Clear, debuggable drum patterns ✓ Tests both acceleration and deceleration reset tricks ✓ Musical: E minor bass and melody after 30s ✓ Debug output shows tempo scaling in action handoff(Claude): Tempo scaling demo track ready for testing Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
28 hoursfeat(audio): Variable tempo system with music time abstractionskal
Implemented unified music time that advances at configurable tempo_scale, enabling dynamic tempo changes without pitch shifting or BPM dependencies. Key Changes: - Added music_time tracking in main.cc (advances by dt * tempo_scale) - Decoupled tracker_update() from physical time (now uses music_time) - Created comprehensive test suite (test_variable_tempo.cc) with 6 scenarios - Verified 2x speed-up and 2x slow-down reset tricks work perfectly - All tests pass (100% success rate) Technical Details: - Spectrograms remain unchanged (no pitch shift) - Only trigger timing affected (when patterns fire) - Delta time calculated per frame: dt = current_time - last_time - Music time accumulates: music_time += dt * tempo_scale - tempo_scale=1.0 → normal speed (default) - tempo_scale=2.0 → 2x faster triggering - tempo_scale=0.5 → 2x slower triggering Test Coverage: 1. Basic tempo scaling (1.0x, 2.0x, 0.5x) 2. 2x speed-up reset trick (accelerate to 2.0x, reset to 1.0x) 3. 2x slow-down reset trick (decelerate to 0.5x, reset to 1.0x) 4. Pattern density swap at reset points 5. Continuous acceleration (0.5x to 2.0x over 10s) 6. Oscillating tempo (sine wave modulation) Test Results: - After 5s physical at 2.0x tempo: music_time=7.550s (expected ~7.5s) ✓ - Reset to 1.0x, advance 2s: music_time delta=2.000s (expected ~2.0s) ✓ - Slow-down reset: music_time delta=2.000s (expected ~2.0s) ✓ Enables future dynamic tempo control without modifying synthesis engine. handoff(Claude): Variable tempo system complete and verified Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
47 hoursrefactor: Task #20 - Platform & Code Hygieneskal
- Consolidated all WebGPU shims and platform-specific logic into src/platform.h. - Refactored platform_init to return PlatformState by value and platform_poll to automatically refresh time and aspect_ratio. - Removed STL dependencies (std::map, std::vector, std::string) from AssetManager and Procedural subsystems. - Fixed Windows cross-compilation by adjusting include paths and linker flags in CMakeLists.txt and updating build_win.sh. - Removed redundant direct inclusions of GLFW/glfw3.h and WebGPU headers across the project. - Applied clang-format and updated documentation. handoff(Gemini): Completed Task #20 and 20.1. Platform abstraction is now unified, and core paths are STL-free. Windows build is stable.
2 daysfeat(audio): Fix tracker bugs and implement rock demo trackskal
Critical Bug Fixes: - Fixed pool exhaustion: Tracker slots never freed after use, music stopped after 8 patterns. Implemented round-robin allocation with cleanup. - Fixed note name parsing: Added automatic note-to-frequency conversion in tracker_compiler. Bass and melody now play correctly. - Fixed timing mismatch: Patterns are 2 seconds but triggered every 4 seconds, causing silence gaps. Updated SCORE to trigger every 2 seconds. Improvements: - Implemented dynamic resource sizing in tracker_compiler: Analyzes score to determine optimal MAX_VOICES/MAX_SPECTROGRAMS values. - Created comprehensive rock track: 11 patterns with drums, bass, power chords, and lead melody over 25 seconds. - Added 213 lines of asset system documentation with 8 prioritized tasks. Known Issues for next session: - Audio quality could be improved (some artifacts remain) - Note synthesis uses default parameters, needs tuning - Pattern overlaps might cause voice exhaustion under heavy load Files Changed: - src/audio/tracker.cc: Round-robin pool allocation, cleanup logic - tools/tracker_compiler.cc: Note name parser, resource usage analysis - src/audio/synth.h: Increased limits to 16 based on analysis - assets/music.track: 230-line rock arrangement - doc/ASSET_SYSTEM.md: Comprehensive documentation + 8 tasks - TODO.md: Updated with recent completions and known issues handoff(Gemini): Music system now functional but needs quality improvements. Audio artifacts and synthesis tuning remain. See TODO.md for details. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2 daysfeat: Finalize tracker asset-sample integration with unified pasting strategyskal
3 daysupdate the melody a bitskal
3 daysfeat: Complete audio tracker system integration and testsskal
3 daysfix(gpu): Resolve high-DPI squished rendering and 3D shadow bugsskal
- Implemented dynamic resolution support in all shaders and effects. - Added explicit viewport setting for all render passes to ensure correct scaling. - Fixed 3D shadow mapping by adding PLANE support and standardizing soft shadow logic. - Propagated resize events through the Effect hierarchy. - Applied project-wide code formatting.
3 daysfeat(3d): Add scaffolding for visual debugging (Task #18a)skal
- Added 'src/3d/visual_debug.h/cc' to implement wireframe rendering. - Integrated VisualDebug into Renderer3D with a static global toggle. - Added '--debug' command-line option to 'demo64k' and 'test_3d_render' to enable wireframes. - Updated 'src/gpu/effects/hybrid_3d_effect.h' to expose the debug setter (reverted later as static method used). - Ensured full cross-platform compatibility (native and Windows) for the new debug module. - All code guarded by STRIP_ALL for final release.
3 daysrefactor(platform): Encapsulate state in PlatformState structskal
- Replaced all global static variables in the platform layer with a single PlatformState struct. - Updated all platform function signatures to accept a pointer to this struct, making the implementation stateless and more modular. - Refactored main.cc, tests, and tools to instantiate and pass the PlatformState struct. - This improves code organization and removes scattered global state.
3 daysfeat(platform): Fix high-DPI scaling and add resolution optionskal
- Fixed a 'squished' viewport bug on high-DPI (Retina) displays by querying the framebuffer size in pixels instead of using the window size in points. - Centralized window dimension management within the platform layer. - Added a '--resolution WxH' command-line option to allow specifying a custom window size at startup. This option is stripped in STRIP_ALL builds. - Updated all test and tool executables to use the new platform API.
5 daysclang-formatskal
5 daysstyle: add vertical compression rules to clang-formatskal
- Enabled AllowShortFunctionsOnASingleLine: All - Enabled AllowShortBlocksOnASingleLine: Always - Enabled AllowShortIfStatementsOnASingleLine: Always - Enabled AllowShortLoopsOnASingleLine: true - Set MaxEmptyLinesToKeep: 1 - Applied formatting to all source files.
5 daysrefactor: move generated asset files to src/generated/skal
- Updated CMakeLists.txt to generate assets.h and assets_data.cc in src/generated/. - Updated scripts/gen_assets.sh to reflect the new output location. - Modified asset_packer.cc to generate correct include paths in assets_data.cc. - Updated source files (main.cc, asset_manager.cc, test_assets.cc) to include headers from the 'generated/' subdirectory. - Ensured all targets have correct include paths to find generated headers. - Removed stale generated files from src/.
5 daysfix: Cross-compilation and style complianceskal
Fixes seq_compiler build for Windows cross-compilation. Moves common WebGPU compatibility shims to gpu.h. Applies project-wide coding style via clang-format. Verified on both macOS (native) and Windows (cross-compile).
5 daysfeat: Multi-pass rendering architecture and effect stubsskal
Implements a post-processing pipeline using offscreen framebuffers. Adds stubs for MovingEllipse, ParticleSpray, GaussianBlur, Solarize, Distort, and ChromaAberration effects. Updates MainSequence to orchestrate the scene pass and post-processing chain.
5 daysfeat: Add --seek command line option for fast-forward debuggingskal
This feature allows developers to jump to a specific time in the demo sequence (e.g., './demo64k --seek 10.5'). It simulates the game logic, audio state (rendering silent buffers), and visual physics (compute shaders) from t=0 up to the target time before starting real-time playback. Audio initialization is refactored to separate device init and start.
5 daysfeat: Implement Sequence and Effect system for demo choreographyskal
Refactors the rendering pipeline into a modular Sequence/Effect system. 'MainSequence' manages the final frame rendering and a list of 'Sequence' layers. 'Sequence' manages a timeline of 'Effect' objects (start/end/priority). Concrete effects (Heptagon, Particles) are moved to 'demo_effects.cc'. Updates main loop to pass beat and aspect ratio.
5 daysupdate session with mix fixesskal
6 daysImplement procedural audio generation, spectral effects, and WebGPU particle ↵skal
system
6 daysadd notesskal
6 daysenforce code styleskal
8 daysfix the audioskal
8 daysfeat(visuals): Add rotation, color shifts, and improved beat-syncskal
Implements a more dynamic and reactive visual system. - Updated synth.cc: Faster peak decay for better response. - Updated gpu.cc: Added time-based rotation and Hue shifting; implemented reactive clear-color flashes. - Updated main.cc: Corrected peak scaling (8x multiplier) and integrated time-based animation.
8 daysfeat(visuals): Enhance colors and add background flashesskal
Improves the audio-visual synchronization by increasing peak amplification and adding dynamic background flashes. - src/gpu/gpu.cc: Updated fragment shader with more vibrant hue calculation and implemented reactive clear color for flashes. - src/main.cc: Increased peak multiplier to 150x and added non-linear boost for strong peaks.
8 daysfeat(demo): Add drum sequence using embedded assetsskal
Incorporates kick1.spec, snare1.spec, and hihat1.spec into the demo sequence. - Updated assets.txt with new drum identifiers. - Implemented register_spec_asset helper in main.cc to load spectral data. - Added 8th-note sequencer triggering a simple drum and bass pattern.
8 daysstyle: Add 3-line descriptive headers to all source filesskal
This commit applies a new project-wide rule that every source file must begin with a concise 3-line comment header describing its purpose. - Updated CONTRIBUTING.md with the new rule. - Applied headers to all .cc and .h files in src/ and tools/. - Fixed various minor compilation errors and missing includes discovered during the header update process.
8 daysfeat(assets): Implement basic asset packing systemskal
Introduces a new asset management system to embed binary assets directly into the demo executable. - Creates the directory for asset definition and an descriptor file. - Implements to generate (with enum and declaration) and (with placeholder data). - Integrates into CMake build, making depend on the generated asset files. - Adds minimal integration in and documentation in . This addresses Task 9 (compact in-line and off-line asset system).
9 daysbuild: Finalize WebGPU integration and platform fixesskal
Includes correct CMake configuration for GLFW native access, Objective-C++ compilation for the helper library on macOS, and applies clang-format to modified sources.
9 daysfix(gpu): Add aspect ratio correction to shaderskal
Implements aspect ratio correction to prevent the pulsating heptagon from being distorted when the window is resized. - The main loop now queries the framebuffer size and calculates the aspect ratio each frame. - This aspect ratio is passed to the GPU via an updated uniform buffer. - The vertex shader in shader.wgsl now uses the aspect ratio to correctly scale the X coordinates of the vertices, ensuring the shape remains proportional.
9 daysopt: Implement build stripping and platform-specific size optimizationsskal
Adds a 'STRIP_ALL' mode to minimize binary size for the final build, and refines size optimization flags for macOS. - **STRIP_ALL Mode**: Added a 'DEMO_STRIP_ALL' CMake option that defines 'STRIP_ALL'. In this mode, command-line parsing is bypassed (forcing fullscreen), debug labels/error callbacks are removed from WebGPU, and non-essential code (like iostream) is stripped. - **macOS Optimizations**: Updated CMake to use '-dead_strip' instead of GNU '--gc-sections' on Apple platforms to resolve linker errors and improve dead code elimination. - **Documentation**: Updated HOWTO.md to document the new 'Final / Strip Build' process and FETCH_DEPS.md for optimized wgpu-native build guidance. - **Task 7 & 8**: Marks these tasks as completed in PROJECT_CONTEXT.md.
9 daysfeat: Implement fullscreen, keyboard controls, and pulsating heptagonskal
This commit fulfills tasks 1 and 2, and adds a synchronized visual effect. - **Fullscreen Mode**: Added '--fullscreen' command-line argument and dynamic toggling via 'F' key. - **Keyboard Controls**: Implemented 'Esc' to exit and 'F' to toggle fullscreen in 'src/platform.cc'. - **Synchronized Visuals**: Added a pulsating heptagon effect in 'src/gpu/gpu.cc' and 'src/gpu/shader.wgsl' that scales and changes color based on the real-time audio peak from the synth. - **Refactor**: Abstracted platform-specific WebGPU surface creation into 'src/platform.cc' to keep 'src/gpu/gpu.cc' cross-platform. - **Build System**: Corrected 'CMakeLists.txt' to properly link 'wgpu-native' and platform frameworks, and updated 'project_init.sh' to build the submodule. - **Documentation**: Updated 'HOWTO.md' and 'PROJECT_CONTEXT.md' with new features and decisions.
9 daysfeat: Implement spectool & specview; refactor coding style; update docsskal
This commit introduces new tools for spectrogram manipulation and visualization, establishes a consistent coding style, and updates project documentation. Key changes include: - **Spectrogram Tools: - : A command-line utility for analyzing WAV/MP3 files into custom spectrogram format and playing back these spectrograms via the synth engine. - : A command-line tool for visualizing spectrogram files as ASCII art in the console. - **Coding Style Enforcement: - Added a configuration file enforcing LLVM-based style with 2-space indentation, no tabs, and an 80-column line limit. - Renamed all C++ source files from to for project consistency. - Applied automatic formatting using exit across the entire codebase. - **Documentation & Workflow: - Created to define a commit policy requiring tests to pass before committing. - Updated with instructions for building and using and , and referenced . - Updated and to reflect the new tools, audio architecture decisions (real-time additive synthesis, double-buffering for dynamic updates, WAV/MP3 support), coding style, and development workflow. - **Build System: - Modified to: - Include new targets for and under the option. - Update source file extensions to . - Add a new end-to-end test for to the suite.