Analyze C++ code for real-time safety violations including heap allocations, locks, blocking calls, and unbounded operations in audio threads.
The Real-Time Safety Auditor enforces Orpheus SDK's critical real-time constraints by analyzing C++ code for violations that could cause audio dropouts, latency spikes, or non-deterministic behavior. This skill encodes deep domain knowledge about broadcast-safe audio programming and prevents common mistakes that would break professional-grade performance requirements.
Core Requirements:
This skill is the primary enforcement mechanism for maintaining Orpheus's "broadcast-safe" guarantee (24/7 reliability, <5ms latency, zero dropouts).
Trigger Patterns:
*_processor.cpp, *_audio.cpp, *Transport*.cpp, *Render*.cppDo NOT Use When:
Use Alternative Skills:
test.result.analyzerorpheus.doc.genread_file - Read C++ source files and headers for analysisbash - Run static analysis tools (cppcheck, clang-check, grep for patterns)grep - Search for banned function calls and patternsAccess Level: 1 (Local Execution - read + command execution)
Rationale:
Explicitly Denied:
write_file, edit_file - This skill audits, doesn't fix (suggest fixes in report)Input:
Output:
Type: Real-Time Safety Audit Report (Markdown)
Format:
# Real-Time Safety Audit Report
## File: [filename]
### VIOLATIONS (Critical - must fix)
- [Line X]: [Issue description]
- **Problem:** [Why this breaks real-time safety]
- **Fix:** [Specific solution]
### WARNINGS (Review recommended)
- [Line Y]: [Potential issue]
- **Concern:** [Why this might be problematic]
- **Suggestion:** [How to verify or improve]
### PASSED
- [Summary of correct patterns found]
Validation:
Required:
cppcheck (static analysis), clang-check (AST analysis)Optional:
compile_commands.json (CMake output) for precise analysisVersion Requirements:
User: "Audit src/modules/m1/transport_controller.cpp for real-time safety"
Claude Process:
read_file src/modules/m1/transport_controller.cppgrep -n "new \|delete \|malloc\|calloc" file.cppOutput:
# Real-Time Safety Audit Report
## File: src/modules/m1/transport_controller.cpp
### VIOLATIONS
#### Line 156: Heap Allocation in Audio Thread
```cpp
float* buffer = new float[size]; // VIOLATION
```
Problem: Dynamic allocation in processBlock() causes unbounded latency. Heap allocation may trigger system calls, memory page faults, or garbage collection, leading to audio dropouts in real-time contexts.
Fix:
// Pre-allocate in constructor
std::array<float, MAX_BUFFER_SIZE> buffer_;
// Or use fixed-size buffer
float buffer[kMaxFrames * kMaxChannels];
### Example 2: Detecting Mutex Lock Violation
**User:** "Check if AudioMixer uses locks in the process method"
**Claude Process:**
1. Read file
2. Search for mutex patterns: `grep -n "std::mutex\|lock_guard\|unique_lock\|pthread_mutex" file.cpp`
3. Verify if usage is in audio thread
4. Report violation with lock-free alternative
**Output:**
```markdown
# Real-Time Safety Audit Report
## File: src/modules/m3/audio_mixer.cpp
### VIOLATIONS
#### Line 89: Mutex Lock in Audio Thread
```cpp
void AudioMixer::process(float** outputs, int numFrames) {
std::lock_guard<std::mutex> lock(gainMutex_); // VIOLATION
// ... processing code
}
Problem: Mutex locking in audio callback can cause priority inversion. If a lower-priority thread holds the lock, the audio thread will block indefinitely, causing audible glitches, dropouts, or complete audio failure.
Fix: Use lock-free atomic operations or single-producer-single-consumer queue:
// Option 1: Atomic for simple values
std::atomic<float> targetGain_;
void process(float** outputs, int numFrames) {
float gain = targetGain_.load(std::memory_order_acquire);
// ... use gain
}
// Option 2: Lock-free SPSC queue for complex updates
// (Use juce::AbstractFifo or boost::lockfree::spsc_queue)
activeChannels_.push_back(channelId); // WARNING
Concern: std::vector::push_back() may trigger reallocation.
Suggestion: Use reserve() in constructor to pre-allocate, or use fixed-size array.
// In constructor
activeChannels_.reserve(kMaxChannels);
### Example 3: Clean Code (No Violations)
**User:** "Audit the sample counter implementation for real-time safety"
**Output:**
```markdown
# Real-Time Safety Audit Report
## File: src/modules/m2/sample_counter.cpp
### VIOLATIONS
None detected.
### WARNINGS
None detected.
### PASSED ✓
- **Atomic operations:** All sample count updates use std::atomic<uint64_t> with proper memory ordering
- **No allocations:** All buffers are stack-allocated or pre-allocated members
- **No locks:** No mutex, condition variables, or blocking primitives detected
- **Bounded operations:** All loops have compile-time bounds (kMaxFrames)
- **Deterministic:** Function execution time is O(1) with respect to sample count
**Real-Time Safety: VERIFIED**
This module follows all Orpheus real-time safety requirements and is safe for use in audio threads.
Known Edge Cases:
Performance Constraints:
Security Boundaries:
Scope Limitations:
Success Metrics:
Failure Modes:
Recovery:
// SAFE: pre-allocated)Dependencies:
Composes With:
test.result.analyzer - Combine with sanitizer output to catch runtime violationsorpheus.doc.gen - Document real-time safety guarantees in Doxygen commentsAlternative Skills:
clang-tidy - General C++ linting (not real-time specific)Owner: Orpheus Team Review Cycle: Weekly (update banned function list as needed) Last Updated: 2025-10-18 Version: 1.0
Revision Triggers: