### RBJ Biquad Filter Setup Examples Source: https://context7.com/vinniefalco/dspfilters/llms.txt Demonstrates the setup for various RBJ (Robert Bristol-Johnson) biquad filters, including Low Pass, Band Shelf, and All Pass. These are single-section, lightweight filters suitable for common audio EQ designs. Ensure the DspFilters library is included. ```cpp #include "DspFilters/Dsp.h" // RBJ Low Pass — single biquad, 1 channel Dsp::SimpleFilter lpf; lpf.setup(44100.0, 1000.0, 0.707); // sample rate, cutoff Hz, Q // RBJ Band Shelf (parametric EQ band) — boost 6 dB at 1 kHz, BW=1 octave Dsp::SimpleFilter eq; eq.setup(44100.0, 1000.0, 6.0, 1.0); // fs, center Hz, gain dB, bandwidth // RBJ All Pass — phase manipulation only Dsp::SimpleFilter ap; ap.setup(44100.0, 5000.0, 0.707); // fs, phase freq Hz, Q float buf[128]; float* ch[1] = { buf }; lpf.process(128, ch); eq.process(128, ch); ``` -------------------------------- ### Create and Setup a Chebyshev Band Stop Filter in C++ Source: https://github.com/vinniefalco/dspfilters/blob/master/README.md Instantiates a Chebyshev Type I Band Stop filter of a specified order and configures it with audio parameters. This example demonstrates how to set up a filter for processing multiple audio channels. ```C++ // Create a Chebyshev type I Band Stop filter of order 3 // with state for processing 2 channels of audio. Dsp::SimpleFilter , 2> f; f.setup (3, // order 44100,// sample rate 4000, // center frequency 880, // band width 1); // ripple dB f.process (numSamples, arrayOfChannels); ``` -------------------------------- ### Legendre Low Pass and Band Pass Filter Setup Source: https://context7.com/vinniefalco/dspfilters/llms.txt Shows the setup for 5th-order Legendre filters, including Low Pass and Band Pass topologies. Legendre filters offer a maximally steep transition band with a monotone passband, balancing rolloff sharpness and passband flatness. ```cpp #include "DspFilters/Dsp.h" // 5th-order Legendre Low Pass Dsp::SimpleFilter, 1> f; f.setup(5, 48000.0, 4000.0); // order, sample rate, cutoff Hz // 5th-order Legendre Band Pass (doubles stages) Dsp::SimpleFilter, 2> bp; bp.setup(5, 48000.0, 2000.0, 400.0); // order, fs, center Hz, width Hz float buf[512]; float* ch[1] = { buf }; f.process(512, ch); ``` -------------------------------- ### Configure and Process with SimpleFilter Source: https://context7.com/vinniefalco/dspfilters/llms.txt Use SimpleFilter for fused filter and state management in multichannel processing. Call setup() to configure the filter and process() to apply it to audio buffers. The response() method can retrieve frequency response data. ```cpp #include "DspFilters/Dsp.h" // Order-8 Butterworth Low Pass, 2 channels, Direct Form II state (default) Dsp::SimpleFilter, 2> lpf; lpf.setup(8, // actual order (must be <= MaxOrder template param) 44100.0, // sample rate (Hz) 2000.0); // cutoff frequency (Hz) // Stereo audio: two separate channel buffers of 512 float samples float left[512], right[512]; // ... fill buffers with audio ... float* channels[2] = { left, right }; lpf.process(512, channels); // Retrieve frequency response at 1 kHz (normalized freq = f / sampleRate) std::complex h = lpf.response(1000.0 / 44100.0); double magnitudeDb = 20.0 * std::log10(std::abs(h)); // → approximately 0 dB (well below cutoff) ``` -------------------------------- ### SimpleFilter Usage Source: https://context7.com/vinniefalco/dspfilters/llms.txt `SimpleFilter` is the recommended class for most use cases. It combines a filter class with per-channel state storage. You configure it using `setup()` and process audio buffers with `process()`. You can also retrieve frequency responses using `response()`. ```APIDOC ## SimpleFilter — Fused filter + state for multichannel processing `SimpleFilter` is the recommended one-stop class for most use cases. It inherits directly from the chosen filter class (e.g. `Butterworth::LowPass`) and bundles the required per-channel state internally, so no separate state management is needed. Call `setup()` to configure, then `process()` to filter audio buffers. ```cpp #include "DspFilters/Dsp.h" // Order-8 Butterworth Low Pass, 2 channels, Direct Form II state (default) Dsp::SimpleFilter, 2> lpf; lpf.setup(8, // actual order (must be <= MaxOrder template param) 44100.0, // sample rate (Hz) 2000.0); // cutoff frequency (Hz) // Stereo audio: two separate channel buffers of 512 float samples float left[512], right[512]; // ... fill buffers with audio ... float* channels[2] = { left, right }; lpf.process(512, channels); // Retrieve frequency response at 1 kHz (normalized freq = f / sampleRate) std::complex h = lpf.response(1000.0 / 44100.0); double magnitudeDb = 20.0 * std::log10(std::abs(h)); // → approximately 0 dB (well below cutoff) ``` ``` -------------------------------- ### Chebyshev II High Pass Filter Setup Source: https://context7.com/vinniefalco/dspfilters/llms.txt Configures a 4th-order Chebyshev II High Pass filter. Ensure the DspFilters library is included. The stopBandDb parameter controls minimum stopband attenuation. ```cpp #include "DspFilters/Dsp.h" // 4th-order Chebyshev II High Pass, mono, 40 dB stopband attenuation Dsp::SimpleFilter, 1> f; f.setup(4, // order 44100.0, // sample rate 1000.0, // cutoff frequency (Hz) 40.0); // stopband attenuation (dB) double buf[512]; // fill buf with audio samples (double precision)... double* ch[1] = { buf }; f.process(512, ch); ``` -------------------------------- ### Elliptic Band Stop Filter Setup and Analysis Source: https://context7.com/vinniefalco/dspfilters/llms.txt Sets up a 3rd-order Elliptic Band Stop filter for 2 channels. This filter offers the sharpest transition band at the cost of ripple in both passband and stopband. The `rippleDb` and `rolloff` parameters control passband ripple and transition band steepness, respectively. Pole-zero analysis is also demonstrated. ```cpp #include "DspFilters/Dsp.h" // 3rd-order Elliptic Band Stop, 2 channels // 1 dB passband ripple, 0.5 rolloff factor Dsp::SimpleFilter, 2> f; f.setup(3, // order 44100.0, // sample rate 4000.0, // center frequency (Hz) 880.0, // bandwidth (Hz) 1.0, // passband ripple (dB) 0.5); // rolloff (0 = tightest, 1 = widest transition) float left[512], right[512]; float* channels[2] = { left, right }; f.process(512, channels); // Inspect poles and zeros for analysis std::vector pz = f.getPoleZeros(); for (const auto& pair : pz) printf("pole: (%.4f, %.4f) zero: (%.4f, %.4f)\n", pair.poles.first.real(), pair.poles.first.imag(), pair.zeros.first.real(), pair.zeros.first.imag()); ``` -------------------------------- ### Bessel Low Pass and Band Pass Filter Setup Source: https://context7.com/vinniefalco/dspfilters/llms.txt Demonstrates setting up 4th-order Bessel filters for Low Pass and Band Pass applications. Bessel filters are ideal for preserving transient shapes due to their near-linear phase response. The impulse response is processed to show shape preservation. ```cpp #include "DspFilters/Dsp.h" // 4th-order Bessel Low Pass — preserves transient shape Dsp::SimpleFilter, 1> f; f.setup(4, 44100.0, 3000.0); // order, sample rate, cutoff Hz // 4th-order Bessel Band Pass Dsp::SimpleFilter, 1> bp; bp.setup(4, 44100.0, 1000.0, 500.0); // order, fs, center Hz, width Hz float buf[256] = { /* impulse at buf[0]=1 */ }; buf[0] = 1.0f; float* ch[1] = { buf }; f.process(256, ch); // buf now contains the impulse response — should show smooth, // well-preserved envelope compared to other filter types ``` -------------------------------- ### Custom Filter Design with Pole/Zero Placement Source: https://context7.com/vinniefalco/dspfilters/llms.txt Design custom filters by manually specifying pole and zero locations in the z-plane. This example shows creating a simple one-pole DC-blocking filter and a two-pole resonator, then introspecting the resulting poles. ```cpp #include "DspFilters/Dsp.h" // Single real pole at z=0.9 (simple DC-blocking one-pole IIR) Dsp::FilterDesign onePole; Dsp::Params p; p[0] = 44100.0; // sample rate p[1] = 0.9; // pole radius in z-plane onePole.setParams(p); // Custom two-pole resonator: conjugate poles near unit circle Dsp::FilterDesign resonator; Dsp::Params p2; p2[0] = 44100.0; // sample rate p2[1] = 0.95; // pole radius p2[2] = 1000.0; // pole angle frequency (Hz) resonator.setParams(p2); // Introspect the resulting poles auto pz = resonator.getPoleZeros(); for (const auto& pair : pz) printf("pole: %.4f + %.4fi\n", pair.poles.first.real(), pair.poles.first.imag()); ``` -------------------------------- ### Butterworth Filters Source: https://context7.com/vinniefalco/dspfilters/llms.txt The `Butterworth` namespace provides various filter types including `LowPass`, `HighPass`, `BandPass`, `BandStop`, `LowShelf`, `HighShelf`, and `BandShelf`. These filters are configured using `setup()` with parameters like order, sample rate, cutoff frequency, and bandwidth. ```APIDOC ## Butterworth filters — Maximally flat magnitude response The `Butterworth` namespace provides `LowPass`, `HighPass`, `BandPass`, `BandStop`, `LowShelf`, `HighShelf`, and `BandShelf` template classes. All types take `MaxOrder` as a compile-time upper bound; the actual runtime order is passed to `setup()`. Band variants double the effective order (a 4th-order band-pass has 8 poles). ```cpp #include "DspFilters/Dsp.h" // --- Low Pass --- Dsp::SimpleFilter, 1> lpf; lpf.setup(6, 44100.0, 500.0); // order=6, fs=44100, fc=500 Hz // --- Band Stop (notch) --- Dsp::SimpleFilter, 2> notch; notch.setup(4, // order 44100.0, // sample rate 60.0, // center frequency (Hz) — e.g. mains hum 10.0); // bandwidth (Hz) // --- High Shelf (treble boost) --- Dsp::SimpleFilter, 1> shelf; shelf.setup(4, 44100.0, 8000.0, 6.0); // fc=8kHz, +6 dB gain // Process mono buffer float mono[1024] = { /* ... audio data ... */ }; float* ch[1] = { mono }; lpf.process(1024, ch); // chain filters in sequence notch.process(1024, ch); shelf.process(1024, ch); ``` ``` -------------------------------- ### Butterworth Filter Variants Source: https://context7.com/vinniefalco/dspfilters/llms.txt The Butterworth namespace offers various filter types including LowPass, HighPass, BandPass, BandStop, and shelf variants. Setup requires order, sample rate, and specific frequency parameters. Filters can be chained by calling process() sequentially on the same buffer. ```cpp #include "DspFilters/Dsp.h" // --- Low Pass --- Dsp::SimpleFilter, 1> lpf; lpf.setup(6, 44100.0, 500.0); // order=6, fs=44100, fc=500 Hz // --- Band Stop (notch) --- Dsp::SimpleFilter, 2> notch; notch.setup(4, // order 44100.0, // sample rate 60.0, // center frequency (Hz) — e.g. mains hum 10.0); // bandwidth (Hz) // --- High Shelf (treble boost) --- Dsp::SimpleFilter, 1> shelf; shelf.setup(4, 44100.0, 8000.0, 6.0); // fc=8kHz, +6 dB gain // Process mono buffer float mono[1024] = { /* ... audio data ... */ }; float* ch[1] = { mono }; lpf.process(1024, ch); notch.process(1024, ch); // chain filters in sequence shelf.process(1024, ch); ``` -------------------------------- ### Biquad State Implementations (Direct Form I vs. II) Source: https://context7.com/vinniefalco/dspfilters/llms.txt Demonstrates the usage of `DirectFormIState` and `DirectFormIIState` for storing biquad section delay-line state. Direct Form II uses half the memory of Direct Form I. ```cpp #include "DspFilters/Dsp.h" Dsp::Butterworth::LowPass<4> filter; filter.setup(4, 44100.0, 1000.0); // Direct Form I: 4 state vars per stage, 4 stages → 16 doubles of state Dsp::PipelineState<4, Dsp::DirectFormIState> stateI; // Direct Form II: 2 state vars per stage, 4 stages → 8 doubles of state Dsp::PipelineState<4, Dsp::DirectFormIIState> stateII; stateI.reset(); stateII.reset(); // Process one sample manually through all cascade stages double sample = 0.5; for (int stage = 0; stage < filter.getNumStages(); ++stage) { Dsp::DirectFormI form; sample = stateI[stage].process(sample, filter[stage], form); } printf("Output (Direct Form I): %.6f\n", sample); ``` -------------------------------- ### ChebyshevI Filters Source: https://context7.com/vinniefalco/dspfilters/llms.txt The `ChebyshevI` filters offer a steeper rolloff than Butterworth filters, with passband ripple controlled by the `rippleDb` parameter. This section demonstrates setting up a `ChebyshevI::BandStop` filter and introspecting its frequency response. ```APIDOC ## ChebyshevI filters — Equiripple in the passband `ChebyshevI` filters achieve a steeper rolloff than Butterworth at the cost of passband ripple, controlled by the `rippleDb` parameter. All topology variants (LowPass, HighPass, BandPass, BandStop, LowShelf, HighShelf, BandShelf) are available. ```cpp #include "DspFilters/Dsp.h" // 5th-order Chebyshev I Band Stop, stereo, 1 dB passband ripple Dsp::SimpleFilter, 2> f; f.setup(5, // order 44100.0, // sample rate 4000.0, // center frequency (Hz) 880.0, // bandwidth (Hz) 1.0); // passband ripple (dB) // Demonstrate runtime introspection via response() const double fs = 44100.0; for (double freq = 100.0; freq < 20000.0; freq *= 1.1) { std::complex h = f.response(freq / fs); printf("%.0f Hz -> %.2f dB\n", freq, 20.0 * std::log10(std::abs(h))); } ``` ``` -------------------------------- ### Set C++ Standard and Build Type Source: https://github.com/vinniefalco/dspfilters/blob/master/shared/CMakeLists.txt Configures the C++ standard to C++11 and sets the build type to Release. Ensures the C++ standard is strictly enforced. ```cmake cmake_minimum_required(VERSION 3.0) project (DSPFilters_Solution) set (CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_BUILD_TYPE Release) ``` -------------------------------- ### Time-Domain Response Computation with ImpulseResponse and StepResponse Source: https://context7.com/vinniefalco/dspfilters/llms.txt These utility structs compute the filter's impulse or step response, useful for visualization and characterization. Ensure the state object is reset before computing each response type. The size of the response buffer should be sufficient to capture the filter's decay. ```cpp #include "DspFilters/Dsp.h" typedef Dsp::Butterworth::LowPass<4> MyFilter; typedef MyFilter::template State::processor MyState; MyFilter filter; filter.setup(4, 44100.0, 500.0); MyState state; state.reset(); // Impulse response (first sample = 1, rest = 0) double impulse[256] = {}; Dsp::ImpulseResponse::compute(256, impulse, filter, state); // Step response (all samples set to 1 before filtering) state.reset(); double step[256] = {}; Dsp::StepResponse::compute(256, step, filter, state); // impulse[0..10] shows the ring-down characteristic // step[] shows convergence to DC gain for (int i = 0; i < 16; ++i) printf("impulse[%d]=%.6f step[%d]=%.6f\n", i, impulse[i], i, step[i]); ``` -------------------------------- ### Free-Function Buffer Processing with applyFilter Source: https://context7.com/vinniefalco/dspfilters/llms.txt Use applyFilter and applyFilterInterleaved for low-level buffer processing without a SimpleFilter wrapper. These utilities require explicitly managed state objects and are suitable for external state management. Ensure the state object matches the filter type. ```cpp #include "DspFilters/Dsp.h" // Define the filter type and obtain its state type typedef Dsp::Butterworth::LowPass<4> MyFilter; typedef MyFilter::template State::processor MyState; MyFilter filter; filter.setup(4, 44100.0, 1000.0); MyState state; state.reset(); // Apply to a non-interleaved mono float buffer float mono[512] = { /* ... */ }; Dsp::applyFilter(filter, state, 512, mono); // Apply to an interleaved stereo buffer (L,R,L,R,...) float stereo[1024] = { /* ... L,R pairs ... */ }; // Process left channel (offset 0, stride 2) Dsp::applyFilterInterleaved(filter, state, 512, stereo, 2); // Reset state and process right channel (offset 1, stride 2) state.reset(); Dsp::applyFilterInterleaved(filter, state, 512, stereo + 1, 2); ``` -------------------------------- ### Add Subdirectories Source: https://github.com/vinniefalco/dspfilters/blob/master/shared/CMakeLists.txt Includes other CMake subdirectories for building different parts of the project. Commented-out lines indicate optional or disabled subdirectories. ```cmake add_subdirectory(DSPFilters) #add_subdirectory(JuceAmalgam) #add_subdirectory(DSPFiltersDemo) ``` -------------------------------- ### Biquad Coefficients and Response Evaluation Source: https://context7.com/vinniefalco/dspfilters/llms.txt Manually create a biquad section from poles and zeros, then evaluate its magnitude response at a specific frequency. This snippet also demonstrates processing a block of samples using Direct Form II state. ```cpp #include "DspFilters/Dsp.h" // Manually create a biquad from poles and zeros in the z-plane Dsp::Biquad section; Dsp::complex_t pole1(-0.5, 0.3); Dsp::complex_t zero1(-1.0, 0.0); Dsp::complex_t pole2(-0.5, -0.3); // conjugate Dsp::complex_t zero2(-1.0, 0.0); section.setTwoPole(pole1, zero1, pole2, zero2); // Evaluate magnitude response at 1 kHz (fs = 44100) double normalizedFreq = 1000.0 / 44100.0; std::complex h = section.response(normalizedFreq); printf("Magnitude at 1kHz: %.3f dB\n", 20.0 * std::log10(std::abs(h))); // Process a block of samples using Direct Form II state Dsp::DirectFormIIState state; float buf[64] = { 1.0f }; // impulse section.process(64, buf, state); ``` -------------------------------- ### ChebyshevI Filter Design and Response Analysis Source: https://context7.com/vinniefalco/dspfilters/llms.txt ChebyshevI filters provide a steeper rolloff than Butterworth filters at the expense of passband ripple, controlled by the rippleDb parameter. The response() method can be used to analyze the filter's frequency response over a range of frequencies. ```cpp #include "DspFilters/Dsp.h" // 5th-order Chebyshev I Band Stop, stereo, 1 dB passband ripple Dsp::SimpleFilter, 2> f; f.setup(5, // order 44100.0, // sample rate 4000.0, // center frequency (Hz) 880.0, // bandwidth (Hz) 1.0); // passband ripple (dB) // Demonstrate runtime introspection via response() const double fs = 44100.0; for (double freq = 100.0; freq < 20000.0; freq *= 1.1) { std::complex h = f.response(freq / fs); printf("%.0f Hz -> %.2f dB\n", freq, 20.0 * std::log10(std::abs(h))); } ``` -------------------------------- ### Runtime Introspection and Polymorphism with Filter Base Class Source: https://context7.com/vinniefalco/dspfilters/llms.txt The Dsp::Filter abstract base class allows runtime inspection of filter properties like name, parameter metadata, and frequency response. Use FilterDesign to create polymorphic Filter pointers. Ensure proper memory management when using raw pointers. ```cpp #include "DspFilters/Dsp.h" #include std::unique_ptr createFilter() { auto* f = new Dsp::FilterDesign< Dsp::Butterworth::Design::LowPass<8>, 2>; Dsp::Params p = f->getDefaultParams(); p[0] = 44100.0; // sample rate p[1] = 4.0; // order p[2] = 1000.0; // cutoff Hz f->setParams(p); return std::unique_ptr(f); } void inspectFilter(Dsp::Filter* f) { printf("Name: %s\n", f->getName().c_str()); printf("Params (%d):\n", f->getNumParams()); for (int i = 0; i < f->getNumParams(); ++i) { Dsp::ParamInfo info = f->getParamInfo(i); printf(" [%d] %s = %.2f (range %.2f..%.2f)\n", i, info.szLabel, f->getParam(i), info.minValue, info.maxValue); } // Frequency response sweep (normalized frequency = f/fs) printf("Frequency response:\n"); for (int i = 0; i < 10; ++i) { double normFreq = 0.01 + i * 0.04; // 0.01 .. 0.37 std::complex h = f->response(normFreq); printf(" %.3f -> %.2f dB\n", normFreq * 44100.0, 20.0 * std::log10(std::abs(h))); } // Pole/zero display auto pz = f->getPoleZeros(); printf("Poles/zeros: %zu pairs\n", pz.size()); } ``` -------------------------------- ### MSVC Specific Compiler Flags Source: https://github.com/vinniefalco/dspfilters/blob/master/shared/CMakeLists.txt Applies optimization and warning flags for the MSVC compiler. Includes a check for snprintf symbol existence and defines a fallback if not found. ```cmake if((${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)) set(MYFLAGS "/O2 /WX- /MT") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MYFLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${MYFLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MYFLAGS}") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${MYFLAGS}") include(CheckSymbolExists) check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) if(NOT HAVE_SNPRINTF) add_definitions(-Dsnprintf=_snprintf) endif() endif() ``` -------------------------------- ### Smoothed Filter Design with Real-time Parameter Modulation Source: https://context7.com/vinniefalco/dspfilters/llms.txt Use SmoothedFilterDesign to wrap any FilterDesign for per-sample linear interpolation of coefficients. This prevents audible zipper noise when modulating parameters like cutoff frequency in real time. Ensure the transition window size is appropriate for the desired smoothness. ```cpp #include "DspFilters/Dsp.h" // Smoothed Butterworth Low Pass, 2 channels, 512-sample transition Dsp::SmoothedFilterDesign< Dsp::Butterworth::Design::LowPass<8>, 2> f(512); // Initial setup Dsp::Params p; p[0] = 44100.0; // sample rate p[1] = 4.0; // order p[2] = 500.0; // cutoff Hz f.setParams(p); float left[512], right[512]; float* channels[2] = { left, right }; f.process(512, channels); // processes with current params // Change cutoff — coefficients will interpolate over the next 512 samples p[2] = 2000.0; // new cutoff: 2 kHz f.setParams(p); f.process(512, channels); // smooth transition — no clicks ``` -------------------------------- ### Compute Group Delay for Filter Comparison Source: https://context7.com/vinniefalco/dspfilters/llms.txt Compare the group delay characteristics of different filter types (Butterworth vs. Bessel) across a range of frequencies. This function computes group delay in samples at a specified normalized frequency. ```cpp #include "DspFilters/Dsp.h" Dsp::SimpleFilter, 1> bw; bw.setup(4, 44100.0, 1000.0); Dsp::SimpleFilter, 1> bs; bs.setup(4, 44100.0, 1000.0); // Compare group delay across frequencies (normalized = freq/fs) printf("freq(Hz) Butterworth_GD(samp) Bessel_GD(samp)\n"); for (double freq = 100.0; freq < 5000.0; freq *= 1.5) { double normFreq = freq / 44100.0; double gdBw = Dsp::GroupDelay::compute(&bw, normFreq); double gdBs = Dsp::GroupDelay::compute(&bs, normFreq); printf(" %5.0f %6.2f %6.2f\n", freq, gdBw, gdBs); } // Bessel GD should be significantly flatter than Butterworth ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.