Skip to content

Feature/code quality improvements#29

Merged
davidirvine merged 7 commits intodevelopfrom
feature/code-quality-improvements
Jul 21, 2025
Merged

Feature/code quality improvements#29
davidirvine merged 7 commits intodevelopfrom
feature/code-quality-improvements

Conversation

@davidirvine
Copy link
Copy Markdown
Owner

No description provided.

- Replace std::vector with std::array for oscillators storage
- Add MAX_OSCILLATORS constant to prevent unbounded allocation
- Eliminate dynamic memory allocation in audio processing path
- Add oscillator_count member to track active oscillators
- Update all oscillator iteration to use index-based loops

This improves real-time audio performance by avoiding heap allocation
during audio processing, which is critical for maintaining low latency.
- Add validation for sample rate, frequencies, and oscillator count
- Throw std::invalid_argument with descriptive messages for invalid parameters
- Validate non-negative frequencies and positive sample rates
- Check oscillator count bounds against MAX_OSCILLATORS
- Add validation for animation multiplier
- Include <stdexcept> for exception handling

This prevents undefined behavior from invalid parameters and provides
clear error messages to help developers identify configuration issues.
- Add noexcept to getter methods and simple setters that cannot throw
- Mark const methods with noexcept where appropriate
- Update Range class methods with noexcept specifications
- Improve exception safety guarantees for performance-critical operations

This helps the compiler optimize better and provides clearer contract
specifications for API consumers about which operations can throw.
- Create deepnote::constants namespace for configuration values
- Define DEFAULT_LFO_AMPLITUDE, DEFAULT_DETUNE_HZ, TARGET_FREQUENCY_TOLERANCE
- Replace hard-coded magic numbers with named constants
- Update init_voice function to use DEFAULT_DETUNE_HZ constant
- Update target frequency tolerance in process_voice function

This improves code maintainability by centralizing configuration
values and making their purpose explicit through naming.
…tions

- Extract calculate_shaped_frequency for LFO processing and scaling
- Extract update_voice_state for state transition logic
- Extract constrain_frequency for frequency bounds checking
- Simplify main process_voice function to focus on orchestration
- Improve code readability and testability by separation of concerns
- Use anonymous namespace for helper functions to limit scope

This makes the code more maintainable and easier to understand by
breaking complex logic into focused, single-responsibility functions.
- Add detailed class documentation for DeepnoteVoice with usage instructions
- Document BezierUnitShaper with mathematical formula and purpose
- Add comprehensive function documentation with parameter descriptions
- Document the detuning algorithm with clear explanation
- Add examples and usage patterns in docstrings
- Explain the state machine and animation system

This improves code maintainability and helps developers understand
the complex audio processing algorithms and their intended usage.
- Add comprehensive compiler warning flags (-Wall, -Wextra, -Wpedantic, -Werror)
- Enable AddressSanitizer and UndefinedBehaviorSanitizer in debug builds
- Add optimized release builds with -O3
- Create .clang-format configuration for consistent code formatting
- Enhance .gitignore with comprehensive build artifact exclusions
- Add static analysis script for clang-format, clang-tidy, and cppcheck
- Improve development workflow with automated code quality checks

This establishes better development practices and helps catch bugs early
through static analysis and runtime sanitizers.
@davidirvine davidirvine merged commit c41897b into develop Jul 21, 2025
@davidirvine davidirvine deleted the feature/code-quality-improvements branch July 25, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant