feature/gradient-stuff #2

Closed
psk wants to merge 38 commits from feature/gradient-stuff into master
Owner
No description provided.
psk added 36 commits 2025-10-04 14:03:13 +00:00
Added stuff to load in music, no analysis yet.
Implemented real-time audio spectrum analysis and visualization mode:

- Added AudioAnalyzer module with FFT-based frequency analysis
  - Uses rustfft for spectrum computation with Hann windowing
  - Band energy calculation (bass, mid, high frequencies)
  - Beat detection via energy threshold system
  - Ring buffer for continuous audio processing

- Added RodioAudioHandler for audio playback and capture
  - Custom Source wrapper to intercept audio samples
  - Thread-safe sample passing via crossbeam-channel
  - Support for MP3, OGG, WAV, FLAC formats

- Added Spectrum visualization mode
  - 64 frequency bars with HSV coloring
  - Real-time audio analysis visualization
  - Exact-width bar calculation to fill screen

- Updated dependencies: rodio, rustfft, spectrum-analyzer, fundsp,
  crossbeam-channel

- Updated CLAUDE.md with audio pipeline documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Improvements to audio visualization:

- Smooth spectrum animation with exponential smoothing
  - Fast rise (0.3) for responsiveness
  - Slow fall (0.05) for smooth, bouncy decay
  - Prevents jarring jumps between frames

- Dynamic range compression
  - Running maximum with slow decay (0.995)
  - Normalizes amplitude to 0-1 range
  - Adapts to both quiet and loud sections

- Frequency weighting for better visualization
  - Progressive boost for higher frequencies (1x to 3x)
  - Square root curve for perceptual balance
  - Makes mid/high frequencies more visible

- CPU-based glow effects
  - 3-layer glow with decreasing alpha
  - Bright highlight on bar tops
  - Musicalizer-style visual pop

- Added 'O' keybind to load music files
  - Opens file dialog at any time
  - Alternative to clicking Load Music button

- Fixed "Load music" text positioning
  - Now properly centered below status text
  - No longer overlaps with main UI elements

- Added comprehensive TODO for GPU shader implementation
  - Step-by-step guide for raylib-rs shaders
  - Shader files already created in assets/shaders/

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add bottom info bar showing current song and playback status
- Add Space bar keybind for play/pause control
- Add O key keybind for loading music files
- Hide rotate buttons in Spectrum mode (not applicable)
- Shift UI elements up when rotate buttons hidden
- Remove rotation display from Spectrum mode status text
- Add conditional hint text showing available keybinds
- Fix spectrum bars to render above info bar (60px margin)
- Replace unicode characters with ASCII for better font compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Major refactor of spectrum rendering to use render-to-texture pipeline
with GPU shader post-processing for high-performance glow effects.

**Render-to-Texture Pipeline:**
- Spectrum bars now render to intermediate texture
- Glow shader applies post-processing as full-screen effect
- Proper separation of content and effects

**Shader Implementation:**
- Brightness-threshold based glow (only bright pixels glow)
- Configurable blur radius and intensity via uniforms
- Dark backgrounds stay dark, only bars glow
- Removed CPU-based multi-pass glow

**New UI Controls:**
- Glow Radius slider (0.1-10.0) - controls blur spread
- Glow Intensity slider (0.0-2.0) - controls effect strength
- Sliders only visible in Spectrum mode
- Speed slider hidden in Spectrum mode (not applicable)

**Keybindings:**
- Added M key to toggle between modes (Static/Animated/Spectrum)
- Updated hint text to show M keybind
- Updated info bar to show all keybinds

**Window Resize Handling:**
- Both gradient and spectrum textures recreate on resize
- Single check before recreation prevents dimension mismatch
- Shader uniforms update with new resolution dynamically

**Shader Example:**
- Created shader_test.rs example demonstrating render-to-texture
- Shows animated spectrum bars with shader post-processing
- Useful reference for future effect development

Technical details in src/main.rs:407-595 (Spectrum mode rendering)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add ping-pong texture rendering with additive blending to create smooth motion
blur trails that follow the audio spectrum bars. The implementation uses GPU
color multiplication and additive blending for efficient real-time performance.

Features:
- Trail toggle button and T keybinding (Spectrum mode only)
- Trail fade slider (0.70-0.95 range, default 0.85)
- Automatic decay factor (0.98) ensures trails gradually fade over time
- Ping-pong texture architecture prevents trail accumulation issues
- Gray background preserved through mathematical blending formula

Technical implementation:
- Ping-pong between two render textures (trail_texture_a/b)
- Formula: output = prev * (fade * decay) + current * (1 - fade)
- Uses BlendMode::BLEND_ADDITIVE for efficient GPU composition
- Trail textures initialized with gray background to match app theme

Additional changes:
- Updated shader_test.rs example to demonstrate trail technique
- Added TODO.md documenting planned features
- Applied rustfmt formatting to source files
- Created trail.fs shader (exploratory, not used in final implementation)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Simplifies the codebase by removing the Static gradient mode and converting the Spectrum mode from vertical bars to a circular visualization with bars radiating outward from the center.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit adds a third visualization mode (Circle) for circular/radial
spectrum display, while restoring the original vertical bar spectrum as a
separate mode. Users can now cycle through three modes via the M key:
Animated → Spectrum (bars) → Circle (radial) → Animated

Changes:
- Added Circle mode to VisualizerMode enum
- Restored original vertical bar spectrum rendering as Spectrum mode
- Renamed circular spectrum to Circle mode
- Updated mode cycling to include all three modes
- Polished Circle mode: reduced radius (250→180), increased bar count (64→96),
  increased bar width (8→10) for smoother appearance
- Updated all UI elements to handle three modes (buttons, sliders, status text)
- Trail and glow effects now available for both Spectrum and Circle modes
- Mode button colors: Purple (Animated), Orange (Spectrum), Blue (Circle)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolves issue where switching between Spectrum and Circle modes caused
brief visual artifacts when trail effect was enabled. Trail textures are
now properly cleared during mode transitions and automatically recreated
on the next frame.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reduces code duplication by creating a create_trail_textures() helper method
in VisualizerState. This pattern was duplicated in 4 places (prepare_texture
twice, and main loop twice for toggle handlers).

- Reduces main.rs from 1726 to 1680 lines (46 lines saved)
- Improves maintainability and reduces potential for bugs
- Makes trail texture creation consistent across all call sites

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Major code reduction by extracting repetitive patterns into reusable helpers:

- draw_button(): Handles button background + centered text (used 6x)
- draw_labeled_slider(): Draws slider with label above it (used 8x)
- load_music_file(): Consolidates audio handler creation and file loading (used 3x)

This reduces main.rs from 1726 to 1614 lines (112 lines saved total).
Improves code maintainability and reduces duplication significantly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements comprehensive debug overlay with keyboard toggle:
- Press D to toggle debug info display on/off
- FPS counter integrated as first line in debug display
- Shows window dimensions, mode, trail/spin/rotation status
- Displays audio analyzer metrics (spectrum peak, bass/mid/high energy, beat detection)
- Text size matches standard FPS counter (20px) for consistency
- Semi-transparent background for readability
- Only available in debug builds via #[cfg(debug_assertions)]
- Defaults to ON in debug builds, OFF in release builds

All debug info displayed together in top-left corner with bright green text.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add VirtualResolution struct to calculate virtual dimensions based on physical aspect ratio
- Support 21:9 ultrawide, 16:9, and 16:10 aspect ratios automatically
- Virtual width fixed at 2560, height calculated dynamically (1097 for 21:9, 1440 for 16:9, 1600 for 16:10)
- Recalculate virtual resolution when toggling fullscreen
- Fix file dialog resize issue: properly restore fullscreen dimensions and recalculate virtual resolution
- All debug println! statements now wrapped in #[cfg(debug_assertions)]
- Error messages use eprintln! instead of println!
- Update all UI positioning to use dynamic virtual_resolution instead of constants
- Pass VirtualResolution to create_virtual_camera() and screen_to_virtual()
- Create virtual_resolution_test.rs example demonstrating the concept

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use transparent backgrounds (rgba 0,0,0,0) for trail textures instead of opaque colors
- Main screen gray background shows through transparent areas consistently
- Fix trail fade to use alpha transparency instead of color darkening
  - Changed from Color::new(fade_value, fade_value, fade_value, 255) (darkens to black)
  - To Color::new(255, 255, 255, fade_alpha) (fades to transparent, preserves colors)
- Trails now maintain vibrant colors while fading instead of turning black
- Glow effect preserved on fading bars
- No more window dimming when trail is enabled
- Background color now consistent whether trail is enabled or disabled

Applied to both Spectrum and Circle visualization modes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The previous trail implementation was ineffective and barely visible. This
replaces it with a proper shader-based pipeline:

- Add blur.fs shader for spatial bar smoothing (Gaussian blur)
- Add streak.fs shader for vertical energy beam trails
- Remove unused trail.fs shader
- Implement 4-step pipeline: bars → blur → streak → glow
- Separate spatial blur from temporal effects for better control
- Increase default glow intensity (0.8 → 2.0) for visibility
- Add streak length and fade sliders with 'S' key toggle
- Clean up 150+ lines of ineffective trail code

The new streak effect creates upward-fading light beams that respond to
music, with configurable length (10-200px) and persistence (0.5-0.95).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add configurable frequency boost slider (0.5-10.0x) for spectrum visualization
- Improves visibility of mid/high frequencies by reducing bass dominance
- Slider appears in both Spectrum and Circle modes with real-time adjustment
- Add Loop toggle button for automatic music restart when playback finishes
- Loop button appears with general controls when music is loaded
- Display freq boost and loop status in debug overlay (D key)
- Update AudioAnalyzer to use exponential frequency weighting curve

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add MicrophoneInputHandler using CPAL for cross-platform mic capture
- Refactor MusicState with AudioSource enum (None/File/Microphone)
- Add "Mic: ON/OFF" toggle button for seamless source switching
- Support Windows/Linux/macOS via CPAL default input device
- Auto-detect sample format (F32/I16/U16) and convert to f32
- Mix multi-channel input down to mono for analysis
- Reuse existing FFT analysis pipeline for both file and mic sources
- All spectrum modes (Spectrum/Circle) work with microphone input
- Update CLAUDE.md with complete microphone architecture docs
- Clean up completed TODO items

Technical details:
- Same crossbeam-channel architecture as file playback
- 2048-sample buffering for smooth real-time analysis
- Non-blocking sample passing to analyzer
- Frequency boost slider applies to both audio sources
- Debug overlay shows current audio source

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements vertical mirroring of spectrum bars from center line for symmetric visualization. Bars grow outward from center with highlights, creating a balanced effect. Toggle button appears only in Spectrum mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Pressing H toggles a clean, distraction-free visualization view by hiding all UI elements (buttons, sliders, text). Keyboard shortcuts remain functional when UI is hidden. Perfect for presentations or immersive viewing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements oscilloscope-style waveform visualization with two display modes and configurable scaling for both waveform and circular spectrum modes.

**New Features:**
- Waveform visualization mode (4th mode in cycle)
  - Standard: Horizontal oscilloscope display (1024 samples)
  - Radial: Circular "shooting out" pattern (512 samples)
  - Toggle between modes with "Radial: ON/OFF" button
- Scale slider for dynamic size control
  - Waveform mode: Adjusts amplitude (0.5-2.0x, labeled "Amplitude")
  - Circle mode: Adjusts radius and bar length (0.5-2.0x, labeled "Radius")
  - Default 1.0x maintains current sizing
- Full shader support (blur, glow, streak effects work in Waveform mode)

**Improvements:**
- Fixed UI alignment bug where FPS slider overlapped other elements in new modes
- Frequency boost now correctly available in both Spectrum and Circle modes
- Added get_waveform_samples() to AudioAnalyzer for raw time-domain data

**Technical Details:**
- Waveform rendering reuses spectrum_render_texture pipeline
- Radial waveform: 180px base radius, scales to 360px at 2.0x
- Standard waveform: 40% base amplitude scale, up to 80% at 2.0x
- Circle mode: 220px base radius, 40% max bar length, both scale together
- Mode button shows green for Waveform mode
- All UI elements respect H key hide functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- README.md: Add comprehensive Features section with all 4 visualization
  modes, keyboard shortcuts table, visual effects list, and mouse controls
- CLAUDE.md: Update architecture docs to reflect current implementation
  - Four visualization modes (Animated, Spectrum, Circle, Waveform)
  - Complete shader pipeline (blur, glow, streak effects)
  - Keyboard shortcuts reference
  - Updated structs with all new fields (scale, mirror, radial, etc.)
  - Improved development guidelines
- TODO.md: Remove completed features (microphone input, mirrored spectrum,
  waveform mode)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Frequency Boost Fixes:
- Fix freq_ratio calculation to use visualized bins (128) instead of full
  spectrum (1024), ensuring boost applies to visible frequency range
- Remove .min(1.0) clamps that were defeating the boost effect
- Change power curve from 0.3 to 1.5 for more aggressive mid/high boost
- Update slider range to 1.0-20.0 (default 8.0) from 0.5-10.0 (default 2.5)
- Adjust brightness calculation for better visual differentiation
- Add freq_boost_test example to validate algorithm

Remove Animated Mode:
- Remove Animated variant from VisualizerMode enum
- Set default mode to Spectrum
- Remove CPU-animated gradient rendering code
- Remove rotation/auto-rotate buttons and related UI
- Remove animation sliders (intensity, wave speed, color shift)
- Remove unused fields: intensity, wave_speed, color_shift, set_speed()
- Update mode cycling to: Spectrum → Circle → Waveform → Spectrum

Documentation:
- Update TODO.md with space utilization enhancements plan
- Update README.md prerequisites for Windows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
psk closed this pull request 2025-10-04 14:18:46 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
public/soundy-bits!2
No description provided.