|
| 1 | +--- |
| 2 | +name: analyze-dsp |
| 3 | +description: DSP analysis toolkit for iPlug2 CLI plugins - impulse response, THD, noise floor, validation |
| 4 | +--- |
| 5 | + |
| 6 | +# DSP Analysis Toolkit |
| 7 | + |
| 8 | +Use this skill to analyze and visualize audio processing from iPlug2 plugins using the CLI target. |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +- Plugin built with CLI target (`-cli` suffix) |
| 13 | +- Python 3 with matplotlib and numpy (`pip install matplotlib numpy`) |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +```bash |
| 18 | +# Build the CLI target |
| 19 | +ninja -C build-ninja MyPlugin-cli |
| 20 | + |
| 21 | +# Basic impulse response |
| 22 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --set 0 100 -o plot.png |
| 23 | + |
| 24 | +# THD analysis (distortion measurement) |
| 25 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --thd 1000 100 -o thd.png |
| 26 | + |
| 27 | +# Validation checks |
| 28 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --validate unity |
| 29 | +``` |
| 30 | + |
| 31 | +**Important:** Always use the Read tool to show generated plots to the user. |
| 32 | + |
| 33 | +## CLI Test Signals |
| 34 | + |
| 35 | +The CLI binary supports these test signals: |
| 36 | + |
| 37 | +```bash |
| 38 | +--impulse <samples> Unit impulse response (default: 4096) |
| 39 | +--sine <freq> <ms> Sine wave at frequency for duration |
| 40 | +--noise <ms> White noise for duration |
| 41 | +--step <ms> Unit step response |
| 42 | +--chirp <start> <end> <ms> Log frequency sweep |
| 43 | +``` |
| 44 | + |
| 45 | +## Python Script Options |
| 46 | + |
| 47 | +### Basic Options |
| 48 | + |
| 49 | +| Option | Description | |
| 50 | +|--------|-------------| |
| 51 | +| `--set <idx> <val>` | Set parameter by index | |
| 52 | +| `--length <n>`, `-l` | Impulse length in samples | |
| 53 | +| `--sr <rate>` | Sample rate (default: 44100) | |
| 54 | +| `--output <file>`, `-o` | Save plot to PNG | |
| 55 | +| `--no-plot` | Print numeric data only | |
| 56 | + |
| 57 | +### Plot Types |
| 58 | + |
| 59 | +| Option | Description | |
| 60 | +|--------|-------------| |
| 61 | +| `--spectrum`, `-s` | Frequency response (magnitude dB) | |
| 62 | +| `--phase` | Phase response | |
| 63 | +| `--combined`, `-c` | 4-panel view | |
| 64 | +| `--group-delay` | Group delay vs frequency | |
| 65 | + |
| 66 | +### Analysis Modes |
| 67 | + |
| 68 | +| Option | Description | |
| 69 | +|--------|-------------| |
| 70 | +| `--thd <freq> <ms>` | THD analysis with sine input | |
| 71 | +| `--noise-floor <ms>` | Noise floor from silence | |
| 72 | +| `--step-response <ms>` | Step response metrics | |
| 73 | +| `--validate <type>` | Sanity checks (effect/unity/lowpass/highpass) | |
| 74 | +| `--metrics <file>` | Export metrics as JSON | |
| 75 | + |
| 76 | +### Instrument/Synth Mode |
| 77 | + |
| 78 | +| Option | Description | |
| 79 | +|--------|-------------| |
| 80 | +| `--note <midi>` | Render MIDI note | |
| 81 | +| `--velocity <vel>` | Note velocity (default: 100) | |
| 82 | +| `--duration <ms>` | Note duration (default: 500) | |
| 83 | +| `--release <ms>` | Release time (default: 500) | |
| 84 | + |
| 85 | +## Examples |
| 86 | + |
| 87 | +### THD Analysis |
| 88 | + |
| 89 | +Measure harmonic distortion with a 1kHz sine wave: |
| 90 | + |
| 91 | +```bash |
| 92 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --set 0 100 --thd 1000 100 -o thd.png |
| 93 | +``` |
| 94 | + |
| 95 | +Output shows THD percentage and harmonic levels relative to fundamental. |
| 96 | + |
| 97 | +### Validation Checks |
| 98 | + |
| 99 | +Run sanity checks on impulse response: |
| 100 | + |
| 101 | +```bash |
| 102 | +# Basic checks (NaN, peak, DC, energy decay) |
| 103 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --validate effect |
| 104 | + |
| 105 | +# Unity gain validation (for gain/bypass plugins) |
| 106 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --set 0 100 --validate unity |
| 107 | + |
| 108 | +# Lowpass filter validation |
| 109 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --validate lowpass |
| 110 | +``` |
| 111 | + |
| 112 | +### Noise Floor Analysis |
| 113 | + |
| 114 | +Measure output noise from silence input: |
| 115 | + |
| 116 | +```bash |
| 117 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --noise-floor 1000 |
| 118 | +``` |
| 119 | + |
| 120 | +Reports RMS, peak, crest factor, and estimated bit resolution. |
| 121 | + |
| 122 | +### Step Response |
| 123 | + |
| 124 | +Analyze transient behavior: |
| 125 | + |
| 126 | +```bash |
| 127 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --step-response 100 -o step.png |
| 128 | +``` |
| 129 | + |
| 130 | +Reports rise time, overshoot, and settling time. |
| 131 | + |
| 132 | +### JSON Metrics Export |
| 133 | + |
| 134 | +Export comprehensive metrics for automation: |
| 135 | + |
| 136 | +```bash |
| 137 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --no-plot --metrics output.json |
| 138 | +``` |
| 139 | + |
| 140 | +### Instrument/Synth Analysis |
| 141 | + |
| 142 | +Render and analyze MIDI notes: |
| 143 | + |
| 144 | +```bash |
| 145 | +# Render middle C (note 60) |
| 146 | +python3 scripts/cli_analyze.py ./build-ninja/out/MySynth --note 60 --combined -o note60.png |
| 147 | + |
| 148 | +# With custom envelope |
| 149 | +python3 scripts/cli_analyze.py ./build-ninja/out/MySynth --note 60 --duration 200 --release 800 -o note.png |
| 150 | +``` |
| 151 | + |
| 152 | +### Parameter Sweep |
| 153 | + |
| 154 | +Compare different parameter values: |
| 155 | + |
| 156 | +```bash |
| 157 | +# Time domain comparison |
| 158 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --sweep 0 0 100 4 -o sweep.png |
| 159 | + |
| 160 | +# Frequency domain comparison |
| 161 | +python3 scripts/cli_analyze.py ./build-ninja/out/MyPlugin --sweep 0 0 100 4 --spectrum -o freq_sweep.png |
| 162 | +``` |
| 163 | + |
| 164 | +## DSP Iteration Workflow |
| 165 | + |
| 166 | +1. Make changes to plugin DSP code |
| 167 | +2. Rebuild: `ninja -C build-ninja MyPlugin-cli` |
| 168 | +3. Run analysis: |
| 169 | + - `--thd 1000 100` for distortion |
| 170 | + - `--validate unity` for sanity checks |
| 171 | + - `--combined` for full visualization |
| 172 | +4. Read plot images to show user |
| 173 | +5. Iterate based on results |
| 174 | + |
| 175 | +## Direct CLI Usage |
| 176 | + |
| 177 | +The analysis script wraps the CLI binary. Direct usage: |
| 178 | + |
| 179 | +```bash |
| 180 | +# Impulse response as text |
| 181 | +./build-ninja/out/MyPlugin --set 0 100 --impulse 1024 --output-txt ir.txt |
| 182 | + |
| 183 | +# Sine wave response |
| 184 | +./build-ninja/out/MyPlugin --set 0 100 --sine 1000 100 --output-txt sine.txt |
| 185 | + |
| 186 | +# MIDI note render |
| 187 | +./build-ninja/out/MyPlugin --midi 60 100 0 500 --render 1000 --output render.wav |
| 188 | +``` |
0 commit comments