dsp-cookbook
Production-ready DSP algorithms including filters, compressors, delays, modulation effects, saturation, and distortion with JUCE integration and optimization techniques. Use when implementing audio processing, DSP algorithms, audio effects, dynamics processors, or need code examples for common audio operations.
What this skill does
# DSP Cookbook
Practical DSP algorithm implementations for audio plugins. Production-ready code examples with JUCE framework integration, covering filters, dynamics, modulation, delays, and common audio effects.
## Table of Contents
1. [Filters](#filters)
2. [Dynamics Processors](#dynamics-processors)
3. [Modulation Effects](#modulation-effects)
4. [Delay-Based Effects](#delay-based-effects)
5. [Saturation & Distortion](#saturation--distortion)
6. [Parameter Smoothing](#parameter-smoothing)
7. [Utility Functions](#utility-functions)
---
## Filters
### Biquad Filter (2nd Order IIR)
**Use for**: EQ, lowpass, highpass, bandpass, notch filters
```cpp
class BiquadFilter {
public:
enum class Type {
Lowpass,
Highpass,
Bandpass,
Notch,
Allpass,
PeakingEQ,
LowShelf,
HighShelf
};
void setCoefficients(Type type, float frequency, float sampleRate,
float Q = 0.707f, float gainDB = 0.0f) {
const float w0 = juce::MathConstants<float>::twoPi * frequency / sampleRate;
const float cosw0 = std::cos(w0);
const float sinw0 = std::sin(w0);
const float alpha = sinw0 / (2.0f * Q);
const float A = std::pow(10.0f, gainDB / 40.0f); // For shelf/peak
float b0, b1, b2, a0, a1, a2;
switch (type) {
case Type::Lowpass:
b0 = (1.0f - cosw0) / 2.0f;
b1 = 1.0f - cosw0;
b2 = (1.0f - cosw0) / 2.0f;
a0 = 1.0f + alpha;
a1 = -2.0f * cosw0;
a2 = 1.0f - alpha;
break;
case Type::Highpass:
b0 = (1.0f + cosw0) / 2.0f;
b1 = -(1.0f + cosw0);
b2 = (1.0f + cosw0) / 2.0f;
a0 = 1.0f + alpha;
a1 = -2.0f * cosw0;
a2 = 1.0f - alpha;
break;
case Type::Bandpass:
b0 = alpha;
b1 = 0.0f;
b2 = -alpha;
a0 = 1.0f + alpha;
a1 = -2.0f * cosw0;
a2 = 1.0f - alpha;
break;
case Type::PeakingEQ:
b0 = 1.0f + alpha * A;
b1 = -2.0f * cosw0;
b2 = 1.0f - alpha * A;
a0 = 1.0f + alpha / A;
a1 = -2.0f * cosw0;
a2 = 1.0f - alpha / A;
break;
// Add other types as needed...
}
// Normalize coefficients
coeffs.b0 = b0 / a0;
coeffs.b1 = b1 / a0;
coeffs.b2 = b2 / a0;
coeffs.a1 = a1 / a0;
coeffs.a2 = a2 / a0;
}
float processSample(float input) {
const float output = coeffs.b0 * input
+ coeffs.b1 * z1
+ coeffs.b2 * z2
- coeffs.a1 * y1
- coeffs.a2 * y2;
// Update state
z2 = z1;
z1 = input;
y2 = y1;
y1 = output;
return output;
}
void reset() {
z1 = z2 = y1 = y2 = 0.0f;
}
private:
struct Coefficients {
float b0 = 1.0f, b1 = 0.0f, b2 = 0.0f;
float a1 = 0.0f, a2 = 0.0f;
} coeffs;
float z1 = 0.0f, z2 = 0.0f; // Input delays
float y1 = 0.0f, y2 = 0.0f; // Output delays
};
```
**Usage:**
```cpp
BiquadFilter filter;
filter.setCoefficients(BiquadFilter::Type::Lowpass, 1000.0f, 48000.0f, 0.707f);
for (int i = 0; i < buffer.getNumSamples(); ++i) {
float input = buffer.getSample(0, i);
float output = filter.processSample(input);
buffer.setSample(0, i, output);
}
```
### State Variable Filter (SVF)
**Use for**: Smooth parameter changes, multimode filters
```cpp
class StateVariableFilter {
public:
enum class Mode { Lowpass, Highpass, Bandpass };
void prepare(double sampleRate) {
this->sampleRate = sampleRate;
}
void setParameters(float cutoff, float resonance, Mode mode) {
this->mode = mode;
// Calculate coefficients (Chamberlin SVF)
const float g = std::tan(juce::MathConstants<float>::pi * cutoff / sampleRate);
const float k = 2.0f - 2.0f * resonance; // resonance 0-1
a1 = 1.0f / (1.0f + g * (g + k));
a2 = g * a1;
a3 = g * a2;
}
float processSample(float input) {
const float v3 = input - ic2eq;
const float v1 = a1 * ic1eq + a2 * v3;
const float v2 = ic2eq + a2 * ic1eq + a3 * v3;
ic1eq = 2.0f * v1 - ic1eq;
ic2eq = 2.0f * v2 - ic2eq;
switch (mode) {
case Mode::Lowpass: return v2;
case Mode::Highpass: return input - k * v1 - v2;
case Mode::Bandpass: return v1;
default: return v2;
}
}
void reset() {
ic1eq = ic2eq = 0.0f;
}
private:
Mode mode = Mode::Lowpass;
double sampleRate = 44100.0;
float a1 = 0.0f, a2 = 0.0f, a3 = 0.0f;
float ic1eq = 0.0f, ic2eq = 0.0f; // Integrator state
};
```
---
## Dynamics Processors
### Compressor
**Use for**: Dynamics control, leveling, punchy mixes
```cpp
class Compressor {
public:
void prepare(double sampleRate) {
this->sampleRate = sampleRate;
envelope = 0.0f;
}
void setParameters(float thresholdDB, float ratio, float attackMs, float releaseMs) {
threshold = juce::Decibels::decibelsToGain(thresholdDB);
this->ratio = ratio;
// Calculate time constants
attackCoeff = std::exp(-1.0f / (attackMs * 0.001f * sampleRate));
releaseCoeff = std::exp(-1.0f / (releaseMs * 0.001f * sampleRate));
}
float processSample(float input) {
const float inputLevel = std::abs(input);
// Envelope follower
if (inputLevel > envelope)
envelope = attackCoeff * envelope + (1.0f - attackCoeff) * inputLevel;
else
envelope = releaseCoeff * envelope + (1.0f - releaseCoeff) * inputLevel;
// Compute gain reduction
float gainReduction = 1.0f;
if (envelope > threshold) {
const float excess = envelope / threshold;
gainReduction = std::pow(excess, 1.0f / ratio - 1.0f);
}
return input * gainReduction;
}
float getGainReductionDB() const {
return juce::Decibels::gainToDecibels(envelope > threshold
? std::pow(envelope / threshold, 1.0f / ratio - 1.0f)
: 1.0f);
}
void reset() {
envelope = 0.0f;
}
private:
double sampleRate = 44100.0;
float threshold = 1.0f;
float ratio = 4.0f;
float attackCoeff = 0.0f;
float releaseCoeff = 0.0f;
float envelope = 0.0f;
};
```
### Limiter (Look-Ahead)
```cpp
class Limiter {
public:
void prepare(double sampleRate, int maxBlockSize) {
this->sampleRate = sampleRate;
// Look-ahead buffer (5ms typical)
const int lookAheadSamples = static_cast<int>(0.005 * sampleRate);
delayBuffer.setSize(2, lookAheadSamples);
delayBuffer.clear();
writePos = 0;
}
void setThreshold(float thresholdDB) {
threshold = juce::Decibels::decibelsToGain(thresholdDB);
}
float processSample(float input, int channel) {
// Write to delay buffer
delayBuffer.setSample(channel, writePos, input);
// Read delayed sample
const float delayed = delayBuffer.getSample(channel, writePos);
// Analyze future peak
float peak = 0.0f;
for (int i = 0; i < delayBuffer.getNumSamples(); ++i) {
peak = std::max(peak, std::abs(delayBuffer.getSample(channel, i)));
}
// Calculate gain
float gain = 1.0f;
if (peak > threshold) {
gain = threshold / peak;
}
writePos = (writePos + 1) % delayBuffer.getNumSamples();
return delayed * gain;
}
void reset() {
delayBuffer.clear()Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.