### 2x Oversampling Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/README.md Demonstrates 2x oversampling using Oversampler2xFIR. This includes upsampling, processing at the higher rate, and then downsampling. ```cpp signalsmith::rates::Oversampler2xFIR up(1, 512); up.up(input, 512); for (int i = 0; i < 1024; ++i) { up[0][i] = nonlinearEffect(up[0][i]); } up.down(output, 512); ``` -------------------------------- ### Reader Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/delay.md Demonstrates how to instantiate and use the Reader class with a specific buffer and interpolator to read a delayed sample. ```cpp signalsmith::delay::Buffer delayBuf(2048); signalsmith::delay::Reader reader; float sample = reader.read(delayBuf, 100.5f); ``` -------------------------------- ### Buffer Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/delay.md Demonstrates the basic usage of the Buffer class, including initialization, writing data, advancing the head, and accessing past samples using negative offsets. ```cpp signalsmith::delay::Buffer buffer(1024); buffer.write(inputData, 512); buffer++; float sample = buffer[-100]; // Access 100 samples in the past ``` -------------------------------- ### BoxSum Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/envelopes.md Illustrates the usage of the BoxSum class to compute a moving average of input samples. The example shows how to initialize BoxSum, write input samples, and use readWrite to efficiently calculate the average over a specified window width. ```cpp signalsmith::envelopes::BoxSum boxSum(256); boxSum.reset(); for (int i = 0; i < 1000; ++i) { // Compute 64-sample moving average float average = boxSum.readWrite(input[i], 64) / 64.0f; output[i] = average; } ``` -------------------------------- ### Basic Delay Line Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/README.md Demonstrates the basic usage of a delay line for audio processing. Initialize with the maximum delay size and then read and write samples in a loop. ```cpp signalsmith::delay::Delay delay(1024); for (size_t i = 0; i < blockSize; ++i) { float delayed = delay.read(100.0f); // 100 samples ago delay.write(input[i]); } ``` -------------------------------- ### FFT Size Optimization Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/fft.md Demonstrates how to use the fastSizeAbove function to find an optimal FFT size for a given minimum sample count and then initialize an FFT object with that size. ```cpp // Need at least 1000 samples - find best FFT size int optimalSize = signalsmith::fft::FFT::fastSizeAbove(1000); // Returns 1024 (2^10) signalsmith::fft::FFT fft(optimalSize); ``` -------------------------------- ### FFT Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/fft.md Demonstrates how to use the FFT class for forward and inverse complex transforms. Requires pre-filling input data and allocating output buffers. ```cpp signalsmith::fft::FFT fft(1024); std::vector> input(1024); std::vector> spectrum(1024); // ... fill input ... fft.fft(input, spectrum); // Forward transform fft.ifft(spectrum, input); // Inverse transform ``` -------------------------------- ### Reciprocal Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/curves.md Shows how to create a Bark-scale frequency map, map a normalized frequency to Hz, and compose this map with a linear map. ```cpp // Create Bark-scale frequency map for 50Hz-10kHz auto bark = signalsmith::curves::Reciprocal::barkRange(50, 10000); // Map normalized frequency to Hz float freq = bark(0.5f); // Returns frequency at 50% on Bark scale // Compose maps auto linear = signalsmith::curves::Reciprocal(0, 1, 2); auto composed = bark.then(linear); ``` -------------------------------- ### MultiDelay Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/delay.md Shows how to use the MultiDelay class for stereo processing, writing interleaved input and reading delayed stereo output. ```cpp signalsmith::delay::MultiDelay stereoDelay(2, 1024); for (int i = 0; i < blockSize; ++i) { float input[2] = {inputL[i], inputR[i]}; stereoDelay.write(input); auto delayed = stereoDelay.read(100.5f); outputL[i] = delayed[0]; outputR[i] = delayed[1]; } ``` -------------------------------- ### WindowedFFT Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/spectral.md Demonstrates creating a 512-point WindowedFFT, performing a forward FFT on audio data, modifying the resulting spectrum, and then performing an inverse FFT. It also shows how to modify the window function. ```cpp // Create 512-point FFT with default Blackman-Harris window signalsmith::spectral::WindowedFFT windowed(512); std::vector audio(512); std::vector> spectrum(256); // size/2 // ... fill audio ... // Forward: window, FFT, rotation windowed.fft(audio, spectrum); // Modify spectrum ... for (auto &bin : spectrum) { bin *= 0.5f; } // Inverse: unwindow, IFFT windowed.ifft(spectrum, audio); // Modify window for different spectral properties auto &window = windowed.setSizeWindow(512); for (int i = 0; i < 512; ++i) { double unit = (double)i / 512; window[i] = 0.5 * (1 - std::cos(2*M_PI*unit)); // Hann window } ``` -------------------------------- ### Kaiser Window Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/windows.md Demonstrates how to create a Kaiser window with a specified bandwidth, check its sidelobe performance, fill a vector with window values, and apply it to audio data. Also shows how to find a bandwidth for a desired sidelobe suppression. ```cpp // Create window with 3 octaves of main lobe width signalsmith::windows::Kaiser kaiser = signalsmith::windows::Kaiser::withBandwidth(3.0); // Check sidelobe performance double energy = signalsmith::windows::Kaiser::bandwidthToEnergyDb(3.0); // Returns ~24 dB // Fill array with window values std::vector window(512); kaiser.fill(window, 512); // Apply to audio for (int i = 0; i < 512; ++i) { windowed[i] = audio[i] * window[i]; } // Or inverse: find window that suppresses sidelobes by 60dB double bw = signalsmith::windows::Kaiser::energyDbToBandwidth(-60); auto aggressive = signalsmith::windows::Kaiser::withBandwidth(bw); ``` -------------------------------- ### MultiBuffer Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/delay.md Illustrates how to use the MultiBuffer class for stereo audio. It shows writing stereo samples and reading individual channels at the current position. ```cpp signalsmith::delay::MultiBuffer mbuffer(2, 512); mbuffer.write({0.5f, 0.3f}); // Write stereo sample mbuffer++; auto channels = mbuffer.view(); float left = channels[0][0]; // Read left channel float right = channels[1][0]; // Read right channel ``` -------------------------------- ### Spectral Processing (FFT) Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/README.md Illustrates spectral processing using a WindowedFFT. This involves performing a forward FFT, modifying the resulting spectrum, and then an inverse FFT. ```cpp signalsmith::spectral::WindowedFFT fft(512); std::vector> spectrum(256); fft.fft(input, spectrum); // Forward with windowing // ... modify spectrum ... fft.ifft(spectrum, output); // Inverse with windowing ``` -------------------------------- ### EQ Filter (Biquad) Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/README.md Shows how to use the Biquad filter for equalization. Initialize with a smoothing factor and then apply EQ adjustments like a peak boost. ```cpp signalsmith::filters::Biquad eq(64); // Smooth over 64 samples eq.peak(0.2, 1.0, 6.0); // 6dB boost at 20% Nyquist for (size_t i = 0; i < blockSize; ++i) { output[i] = eq(input[i]); } ``` -------------------------------- ### Hadamard Usage Example (Compile-time and Dynamic) Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/mix.md Demonstrates applying the Hadamard transform in-place for both compile-time fixed-size (8 channels) and dynamic runtime-sized (6 channels) configurations. Also shows how to retrieve the scaling factor. ```cpp // Compile-time 8-channel Hadamard std::array channels = {0.1, 0.2, 0.15, 0.05, -0.1, 0.3, -0.05, 0.2}; signalsmith::mix::Hadamard::inPlace(channels); // channels now contains mixed output // Check scaling float scale = signalsmith::mix::Hadamard::scalingFactor(); // Returns 1/√8 ≈ 0.3536 // Dynamic runtime size signalsmith::mix::Hadamard hadamard(6); std::vector data(6); // ... fill data ... hadamard.inPlace(data); ``` -------------------------------- ### Householder Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/mix.md Demonstrates applying the Householder reflection in-place for a dynamic runtime-sized matrix. It also shows how to apply the unscaled version and manually scale the result. ```cpp std::vector data(4); // ... fill data ... signalsmith::mix::Householder house(4); house.inPlace(data); // Apply Householder reflection // Or unscaled for intermediate calculations house.unscaledInPlace(data); float scale = house.scalingFactor(); for (auto &v : data) v *= scale; ``` -------------------------------- ### Biquad Filter Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/filters.md Demonstrates how to instantiate and use the Biquad filter. It shows initializing the filter with smoothing steps, setting initial filter characteristics, changing filter settings later for a smooth transition, and processing audio samples. ```cpp signalsmith::filters::Biquad filter(128); // Smooth over 128 samples filter.lowpass(0.15, 1.0); // Later, change filter settings with smooth transition filter.peak(0.25, 1.5, 6.0); for (int i = 0; i < blockSize; ++i) { output[i] = filter(input[i]); // Coefficients smoothly interpolate } ``` -------------------------------- ### Oversampler2xFIR Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/rates.md Demonstrates how to use the Oversampler2xFIR class for processing audio blocks. It shows initialization, upsampling input, processing at the higher rate, and downsampling the output. ```cpp signalsmith::rates::Oversampler2xFIR oversampler(2, 512, 16, 0.43); for (int blockIdx = 0; blockIdx < numBlocks; ++blockIdx) { // Upsample from input buffers (2 channels, 512 samples each) oversampler.up(inputBuffers, 512); // Process at higher rate (1024 samples per channel) for (int c = 0; c < 2; ++c) { float *channel = oversampler[c]; for (int i = 0; i < 1024; ++i) { channel[i] = processHighRate(channel[i]); } } // Downsample back oversampler.down(outputBuffers, 512); } ``` -------------------------------- ### Example: Using fillKaiserSinc for Oversampling Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/rates.md Demonstrates how to generate FIR filter coefficients for 2x oversampling using explicit frequency edges and then apply these coefficients in a basic FIR filter implementation. Also shows the usage of the heuristic-based signature for automatic transition width calculation. ```cpp // Create coefficients for 2x oversampling lowpass // Nyquist of original signal = 0.5 in oversampled domain std::vector kernel(33); signalsmith::rates::fillKaiserSinc(kernel, 33, 0.43, 0.48); // Passes up to 86% of original Nyquist, transitions by 10% // Apply in FIR filter float filtered = 0; for (int i = 0; i < 33; ++i) { filtered += kernel[i] * buffer[i]; } // Or with heuristic std::vector kernel2(33); signalsmith::rates::fillKaiserSinc(kernel2, 33, 0.45); // Automatically sets transition width ``` -------------------------------- ### CubicSegmentCurve Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/curves.md Demonstrates creating a CubicSegmentCurve, adding points to define an envelope, updating it for smoothness, and evaluating it over time. ```cpp signalsmith::curves::CubicSegmentCurve envelope; envelope.add(0, 0); // Attack point envelope.add(0.1, 1); // Peak envelope.add(0.5, 0.5); // Sustain envelope.add(1, 0); // Release point envelope.update(true); // Make smooth and monotonic for (float t = 0; t < 1; t += 0.01f) { float value = envelope(t); } ``` -------------------------------- ### Delay Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/delay.md Illustrates the typical usage of the Delay class within a processing loop, reading delayed samples and writing new input samples. ```cpp signalsmith::delay::Delay delay(512); for (int i = 0; i < blockSize; ++i) { float out = delay.read(delayTimeInSamples); delay.write(input[i]); } ``` -------------------------------- ### BoxFilter Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/envelopes.md Demonstrates how to instantiate and use the BoxFilter for processing audio samples. It shows setting the filter length and processing a block of input samples, as well as changing the filter length mid-stream. ```cpp signalsmith::envelopes::BoxFilter filter(256); filter.set(64); // 64-tap moving average for (int i = 0; i < blockSize; ++i) { output[i] = filter(input[i]); } // Change length mid-stream filter.set(32); // Shorter filter, no state reset ``` -------------------------------- ### BiquadStatic Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/filters.md Demonstrates creating and using a low-pass filter and a peaking EQ filter with BiquadStatic. Coefficients are set once before processing a block of audio samples. ```cpp signalsmith::filters::BiquadStatic lowpass; lowpass.lowpass(0.1, 2); // 10% Nyquist, 2 octaves wide for (int i = 0; i < blockSize; ++i) { output[i] = lowpass(input[i]); } // Create EQ filter signalsmith::filters::BiquadStatic peak; peak.peak(0.2, 1.0, 6.0); // Boost 6dB at 20% Nyquist with Q=1 output[i] = peak(input[i]); ``` -------------------------------- ### Include DSP Modules in C++ Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md Include specific header files for the DSP modules you intend to use in your C++ project. This example shows how to include headers for curves, delay, and filters. ```cpp #include "dsp/curves.h" // Include desired modules #include "dsp/delay.h" #include "dsp/filters.h" using Curve = signalsmith::curves::Linear; using Delay = signalsmith::delay::Delay; using Filter = signalsmith::filters::BiquadStatic; ``` -------------------------------- ### CubicLfo Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/envelopes.md Demonstrates how to instantiate and use the CubicLfo class to generate a frequency modulation signal. Configure the LFO with a seed for reproducibility and then use the set method to define its range and variation parameters before calling next() in a processing loop. ```cpp signalsmith::envelopes::CubicLfo lfo(12345); // Reproducible seed // Configure wobbling frequency parameter lfo.set(0.9, 1.1, 0.001, 0.3, 0.2); // ±10% with 0.3 rate variation, 0.2 depth for (int i = 0; i < blockSize; ++i) { float frequencyModulation = lfo.next(); float freq = baseFreq * frequencyModulation; // ... use freq ... } ``` -------------------------------- ### ModifiedRealFFT Usage Example Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/fft.md Illustrates the usage of ModifiedRealFFT for real-to-complex and complex-to-real transforms. The forward transform converts real audio samples to complex spectrum bins, and the inverse transform reconstructs the audio. ```cpp signalsmith::fft::ModifiedRealFFT mrfft(512); std::vector audio(512); std::vector> spectrum(256); // size/2 // ... fill audio ... mrfft.fft(audio, spectrum); // Forward: 512 samples → 256 bins mrfft.ifft(spectrum, audio); // Inverse: 256 bins → 512 samples // Bin k is centered at frequency (k + 0.5) / 512 ``` -------------------------------- ### Spectral Magnitude Compression Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/overview.md Modifies the spectral magnitude of an audio signal using a WindowedFFT. This example compresses the magnitude by taking its square root. ```cpp signalsmith::spectral::WindowedFFT fft(512); std::vector> spectrum(256); fft.fft(input, spectrum); for (auto &bin : spectrum) { float mag = std::abs(bin); bin *= std::pow(mag, 0.5); // Square root magnitude compression } fft.ifft(spectrum, output); ``` -------------------------------- ### Project Structure and CMakeLists.txt Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md Illustrates a typical project layout including source, include directories, and a basic CMakeLists.txt file for building an executable. Ensure the 'include_directories' command points to the DSP submodule. ```cmake include_directories(${PROJECT_SOURCE_DIR}/include) add_executable(myapp src/audio_processing.cpp src/effects.cpp) ``` -------------------------------- ### W-format to B-format Conversion with Hadamard Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/mix.md Demonstrates converting W-format ambisonic audio to B-format using a Hadamard matrix. This is useful for spatial audio encoding and decoding. ```cpp signalsmith::mix::Hadamard h4; float wXYZ[4] = {w, x, y, z}; // W-format input h4.inPlace(wXYZ); // Hadamard mixing // wXYZ now contains mixed ambisonics channels ``` -------------------------------- ### WindowedFFT Static Utilities Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/spectral.md Provides static methods to find optimal FFT sizes above or below a given target, optimized for factors of small primes. ```cpp static int fastSizeAbove(int size, int divisor=1); static int fastSizeBelow(int size, int divisor=1); ``` -------------------------------- ### Clone DSP Documentation Repository Source: https://github.com/signalsmith-audio/dsp/blob/main/README.md Clone the DSP documentation repository, which contains tests and source scripts for documentation generation. ```bash git clone https://signalsmith-audio.co.uk/code/dsp-doc.git ``` -------------------------------- ### Clone DSP Library Repository Source: https://github.com/signalsmith-audio/dsp/blob/main/README.md Clone the DSP library repository to your local machine. ```bash git clone https://signalsmith-audio.co.uk/code/dsp.git ``` -------------------------------- ### WindowedFFT Static Utilities Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/spectral.md Provides static utility methods for finding optimal FFT sizes. ```APIDOC ## WindowedFFT Static Utilities ### Description Provides static utility methods for finding optimal FFT sizes. ### Static Methods - **fastSizeAbove(size, divisor)** - Finds an optimal FFT size greater than or equal to the target size. - Parameters: - `size` (int) - The target size. - `divisor` (int, default 1) - An optional divisor to consider for optimization. - Returns: `int` - The optimal FFT size above the target. - Notes: Optimized for factors of small primes (2, 3, 5...). - **fastSizeBelow(size, divisor)** - Finds an optimal FFT size less than or equal to the target size. - Parameters: - `size` (int) - The target size. - `divisor` (int) - An optional divisor to consider for optimization. - Returns: `int` - The optimal FFT size below the target. - Notes: Optimized for factors of small primes (2, 3, 5...). ``` -------------------------------- ### Clean Build with CMake Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md Execute a clean build using CMake to resolve issues related to multiple library versions or conflicting include paths. ```bash cmake --build . --clean-first ``` -------------------------------- ### WindowedFFT Methods Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/spectral.md Provides methods to configure, access, and perform FFT and inverse FFT operations. Includes utilities for setting window size, retrieving window data, and executing transforms with optional windowing and scaling. ```APIDOC ## WindowedFFT Methods ### Description Provides methods to configure, access, and perform FFT and inverse FFT operations. Includes utilities for setting window size, retrieving window data, and executing transforms with optional windowing and scaling. ### Methods - **setSizeWindow(size, rotateSamples)** - Configures FFT with Blackman-Harris window and returns a modifiable window vector. - Parameters: - `size` (int) - The desired FFT size. - `rotateSamples` (int, default 0) - Circular shift of the time-domain signal. - Returns: `std::vector&` - Modifiable window vector. - Blackman-Harris formula: 0.35875 - 0.48829*cos(2πx) + 0.14128*cos(4πx) - 0.01168*cos(6πx) - **setSize(size, fn, windowOffset, rotateSamples)** - Configures FFT with a user-provided window function. - Parameters: - `size` (int) - The desired FFT size. - `fn` (callable) - A window function taking a double in [0,1] and returning a window value. - `windowOffset` (Sample, default 0.5) - Phase offset for window evaluation. - `rotateSamples` (int, default 0) - Circular shift of the time-domain signal. - Returns: void - **setSize(size, rotateSamples)** - Configures FFT with the default Blackman-Harris window. - Parameters: - `size` (int) - The desired FFT size. - `rotateSamples` (int, default 0) - Circular shift of the time-domain signal. - Returns: void - **window()** - Accessor for read-only window values. - Parameters: none - Returns: `const std::vector&` - Read-only window values. - **size()** - Returns the configured FFT size. - Parameters: none - Returns: `int` - The number of time-domain samples, which equals the number of output bins for Modified Real FFT. - **fft(input, output, withWindow, withScaling)** - Applies window, FFT, and optional rotation/scaling. - Template Parameters: - `withWindow` (bool, default true) - Whether to apply the window function. - `withScaling` (bool, default false) - Whether to divide by size for energy preservation. - Parameters: - `input` - Input array or iterator. - `output` - Output array or iterator. - Returns: void - Notes: Modified Real FFT produces size/2 complex bins centered at (i + 0.5)/size frequencies. A half-bin shift is applied internally. - **ifft(input, output, withWindow, withScaling)** - Performs the inverse FFT with optional windowing and rotation. - Template Parameters: - `withWindow` (bool, default true) - Whether to apply the window function. - `withScaling` (bool, default false) - Whether to divide by size for energy preservation. - Parameters: - `input` (size/2 bins) - Input array or iterator. - `output` (size samples) - Output array or iterator. - Returns: void - Notes: Includes 1/size scaling for a proper inverse. ``` -------------------------------- ### Select Optimal FFT Size Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md Use `fastSizeAbove` to find the smallest FFT size that is a product of small primes and is greater than or equal to the specified value. This is crucial for maximizing performance. ```cpp size_t optimal = signalsmith::fft::FFT::fastSizeAbove(1000); // Returns 1024 (2^10) ``` -------------------------------- ### Typical Real-Time Audio Processing Flow Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/overview.md Illustrates the standard data flow for real-time audio processing, including optional upsampling and downsampling stages. ```text Audio Input (blockSize samples) ↓ [Optional] Upsample (Oversampler2xFIR) ↓ Processing Layer (Filters, Delays, Curves, Envelopes) ↓ [Optional] Downsample (Oversampler2xFIR) ↓ Audio Output ``` -------------------------------- ### Include and Use Delay Class Source: https://github.com/signalsmith-audio/dsp/blob/main/README.md Include the delay header and instantiate a delay line. Ensure you have a compatible C++11 compiler. ```cpp #include "dsp/delay.h" using Delay = signalsmith::delay::Delay; Delay delayLine(1024); ``` -------------------------------- ### Householder Reflection Matrices Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/mix.md Provides methods for applying Householder reflection matrices for moderate mixing with O(N) complexity. Supports both compile-time and dynamic runtime sizes. ```APIDOC ## Householder Reflection Matrices ### Description Applies Householder reflection matrices for moderate mixing with linear O(N) complexity. Supports both compile-time fixed sizes and dynamic runtime sizes. ### Methods **Compile-time Size:** - `static void inPlace(Data &&data)`: Applies orthogonal Householder transform in-place, scaling to maintain energy. - `static Sample scalingFactor()`: Returns the scaling factor. - `static void unscaledInPlace(Data &&data)`: Applies raw Householder transform (no scaling). **Dynamic Size:** - `Householder(int size)`: Constructor for runtime-sized Householder operator. - `void inPlace(Data &&data) const`: Applies orthogonal Householder transform in-place. - `Sample scalingFactor() const`: Returns the scaling factor. - `void unscaledInPlace(Data &&data) const`: Applies raw Householder transform (no scaling). ### Characteristics - **Complexity**: O(N) operations (linear). - **Mixing**: Moderate mixing levels. - **Orthogonal**: Yes, maintains energy with scaling. - **Use case**: When log-N complexity is not required. ### Usage Example ```cpp std::vector data(4); // ... fill data ... signalsmith::mix::Householder house(4); house.inPlace(data); // Apply Householder reflection // Or unscaled for intermediate calculations house.unscaledInPlace(data); float scale = house.scalingFactor(); for (auto &v : data) v *= scale; ``` ``` -------------------------------- ### WindowedFFT Construction Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/spectral.md Constructs a WindowedFFT object with specified size and windowing options. The default constructor creates a size 0 FFT. Other constructors allow for fixed Blackman-Harris windows or custom window functions. ```APIDOC ## WindowedFFT Construction ### Description Constructs a WindowedFFT object with specified size and windowing options. The default constructor creates a size 0 FFT. Other constructors allow for fixed Blackman-Harris windows or custom window functions. ### Constructors - **WindowedFFT()** - Parameters: — - Description: Default, size 0 - **WindowedFFT(size, rotateSamples)** - Parameters: - `size` (int) - The desired FFT size. - `rotateSamples` (int, default 0) - Number of samples to circularly shift the time-domain signal. - Description: Fixed size with Blackman-Harris window. - **WindowedFFT(size, fn, windowOffset, rotateSamples)** - Parameters: - `size` (int) - The desired FFT size. - `fn` (callable) - A window function that takes a double in [0,1] and returns a window value. - `windowOffset` (Sample, default 0.5) - Phase offset for window evaluation. - `rotateSamples` (int, default 0) - Circular shift of the time-domain signal. - Description: Custom window function. ``` -------------------------------- ### Define _USE_MATH_DEFINES for M_PI Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md Include this define before including cmath to resolve the 'M_PI not defined' compiler error, especially on MSVC. ```cpp #define _USE_MATH_DEFINES #include #include "dsp/curves.h" ``` -------------------------------- ### Oversampler2xFIR Methods Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/rates.md Provides documentation for the various methods available in the Oversampler2xFIR class, including resizing, resetting, accessing latency, and performing upsampling and downsampling operations. ```APIDOC ## resize ### Description Reallocates internal buffers for the oversampler. Can be called with or without FIR parameters. ### Method void resize(int nChannels, int maxBlockLength) void resize(int nChannels, int maxBlockLength, int halfLatency, double passFreq = 0.43) ### Parameters #### Path Parameters - **nChannels** (int) - Required - Number of audio channels - **maxBlockLength** (int) - Required - Maximum block size - **halfLatency** (int) - Optional - Half the FIR kernel length - **passFreq** (double) - Optional - Pass-band frequency (0-0.5 normalized) ## reset ### Description Clears the internal state of the oversampler. ### Method void reset() ### Parameters None ## latency ### Description Static method returning the round-trip latency in samples. ### Method static int latency() ### Returns - **int** - The round-trip latency, equal to `2 * halfLatency`. ## inputLatency ### Description Instance method for the current latency of the oversampler object. ### Method int inputLatency() const ### Returns - **int** - The latency of this object, which may vary if reconfigured. ## up ### Description Upsamples an input block by 2x. Inserts zeros between input samples and then filters. ### Method void up(Input &&input, int blockLength) ### Parameters #### Path Parameters - **input** (Input &&) - Required - Input data - **blockLength** (int) - Required - The length of the input block ### Returns - void ### Output Length `2 * blockLength` samples per channel. ## down ### Description Downsamples the currently upsampled content by 2x, returning samples to the original rate. Must be called after `up()` for matching block lengths. ### Method void down(Output &&output, int blockLength) ### Parameters #### Path Parameters - **output** (Output &&) - Required - Output data buffer - **blockLength** (int) - Required - The original block length before upsampling ### Returns - void ## upDown ### Description Combines upsampling and downsampling for a single block. Equivalent to calling `up()` then `down()`. ### Method void upDown(Input &&input, Output &&output, int blockLength) ### Parameters #### Path Parameters - **input** (Input &&) - Required - Input data - **output** (Output &&) - Required - Output data buffer - **blockLength** (int) - Required - The length of the input block ### Returns - void ## upChannel, downChannel ### Description Process a single channel (indices 0 to channels-1). Useful when input/output channel counts differ. ### Method void upChannel(Input &&input, int channel, int blockLength) void downChannel(Output &&output, int channel, int blockLength) ### Parameters #### Path Parameters - **input** (Input &&) - Required - Input data (for upChannel) - **output** (Output &&) - Required - Output data (for downChannel) - **channel** (int) - Required - The channel index to process - **blockLength** (int) - Required - The length of the block ### Returns - void ## operator[] ### Description Accesses the upsampled buffer for a specific channel. Use for in-place processing between `up()` and `down()` calls. ### Method Sample* operator[](int channel) ### Parameters #### Path Parameters - **channel** (int) - Required - The channel index ### Returns - **Sample*** - Pointer to the channel data at the higher rate. ## channels, bufferLength ### Description Accessors for the number of channels and the current buffer length. ### Method int channels() const int bufferLength() const ### Returns - **int** - The number of channels or the buffer length. ``` -------------------------------- ### Handle Multiple Header Inclusions Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/configuration.md The library uses include guards with version checking to prevent accidental mixing of incompatible library versions within the same compilation unit. Ensure that all included versions match the expected library version. ```cpp #ifndef SIGNALSMITH_DSP_CURVES_H #define SIGNALSMITH_DSP_CURVES_H // ... curves.h content ... #else // Check that all included versions match static_assert(SIGNALSMITH_DSP_VERSION_MAJOR == 1 && SIGNALSMITH_DSP_VERSION_MINOR == 7 && SIGNALSMITH_DSP_VERSION_PATCH == 0, "multiple versions of the Signalsmith DSP library"); #endif ``` -------------------------------- ### Static FFT Size Optimization Functions Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/fft.md Declares static functions to find optimal FFT sizes above or below a target size, used for efficient transform size selection. ```cpp static size_t fastSizeAbove(size_t size); // FFT for size >= target static size_t fastSizeBelow(size_t size); // FFT for size <= target ``` -------------------------------- ### Buffer Mutable and Const Views (C++) Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/types.md Aliases for `Buffer::View` template specializations, providing mutable and constant access to buffer data. ```cpp using MutableView = View; using ConstView = View; ``` -------------------------------- ### Linear Curve Construction and Usage Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/curves.md Demonstrates creating a linear mapping and its inverse. Useful for scaling values within a specific range, like audio frequencies. ```cpp signalsmith::curves::Linear freq(20, 20000); // Maps 0-1 to 20-20000 Hz double hertz = freq(0.5); // Returns 10010 Hz signalsmith::curves::Linear inverse = freq.inverse(); double normalized = inverse(10010); // Returns ~0.5 ``` -------------------------------- ### Namespace Hierarchy in Signalsmith DSP Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/types.md Visualizes the directory structure and class hierarchy within the signalsmith namespace, illustrating the organization of different DSP components. ```tree signalsmith/ ├── curves/ │ ├── Linear │ ├── Cubic │ ├── CubicSegmentCurve │ └── Reciprocal ├── delay/ │ ├── Buffer │ ├── MultiBuffer │ ├── Reader │ ├── Delay │ ├── MultiDelay │ ├── InterpolatorNearest │ ├── InterpolatorLinear │ ├── InterpolatorCubic │ ├── InterpolatorLagrangeN │ ├── InterpolatorKaiserSincN │ └── [Aliases for common instantiations] ├── filters/ │ ├── BiquadDesign (enum) │ ├── BiquadStatic │ └── Biquad ├── fft/ │ ├── FFT │ └── ModifiedRealFFT ├── windows/ │ └── Kaiser ├── envelopes/ │ ├── CubicLfo │ ├── BoxSum │ └── BoxFilter ├── spectral/ │ └── WindowedFFT ├── mix/ │ ├── Hadamard │ └── Householder └── rates/ ├── fillKaiserSinc() (function) └── Oversampler2xFIR ``` -------------------------------- ### Cubic Curve Construction and Usage Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/curves.md Shows how to create a smooth cubic interpolation through four points, optionally preserving monotonicity. Suitable for complex, non-linear mappings. ```cpp signalsmith::curves::Cubic curve = signalsmith::curves::Cubic::smooth(0, 1, 2, 3, // x values 0, 0.5, 0.8, 1, // y values true); // monotonic float y = curve(1.5f); // Evaluate at x=1.5 ``` -------------------------------- ### Oversampler2xFIR Construction Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/rates.md Constructs an Oversampler2xFIR object. The constructor allows specifying the number of channels, maximum block size, half latency, and pass-band frequency. ```APIDOC ## Oversampler2xFIR() ### Description Default constructor for Oversampler2xFIR. ### Method Constructor ### Parameters None ## Oversampler2xFIR(int channels, int maxBlock, int halfLatency = 16, double passFreq = 0.43) ### Description Constructs an Oversampler2xFIR object with specified parameters. ### Method Constructor ### Parameters #### Path Parameters - **channels** (int) - Required - Number of audio channels - **maxBlock** (int) - Required - Maximum block size processed at once - **halfLatency** (int) - Optional - Half the FIR kernel length (default: 16) - **passFreq** (double) - Optional - Pass-band frequency (0-0.5 normalized) (default: 0.43) ``` -------------------------------- ### ModifiedRealFFT Class Source: https://github.com/signalsmith-audio/dsp/blob/main/_autodocs/api-reference/fft.md Implements a real-input FFT that applies a half-bin shift, simplifying processing by avoiding DC and Nyquist bin complexities. It offers efficient real-signal analysis. ```APIDOC ## ModifiedRealFFT Class ### Description Real-input FFT that applies half-bin shift, avoiding DC and Nyquist complexity. ### Template Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | V | typename | double | Floating-point type (float or double) | ### Construction | Constructor | Parameters | Description | |-------------|-----------|-------------| | ModifiedRealFFT() | — | Default, size 0 | | ModifiedRealFFT(size) | `size` (size_t) | Pre-allocate for transform | ### Methods #### setSize - Parameters: `size` (size_t) - transform size - Returns: void - Allocates for modified real FFT #### size - Parameters: none - Returns: size_t - FFT size - Output has size/2 complex bins #### fft (real-to-complex) - Input: `size` real values - Output: `size/2` complex values - Half-bin shift applied before transform - Returns: void - Bins centered at (i + 0.5)/size frequencies #### ifft (complex-to-real) - Input: `size/2` complex values (from fft output) - Output: `size` real values - Returns: void - Includes 2/size scaling for proper inverse #### fastSizeAbove, fastSizeBelow - Static methods for finding optimal FFT sizes - Parameters: `size` (size_t) - minimum/maximum size needed - Returns: size_t - nearest optimal size above/below - Useful for allocating properly-sized transforms ### Advantages Over Standard Real FFT - No awkward DC and Nyquist bins (both have imaginary parts in standard real FFT) - All bins naturally centered at fractional frequencies - Simpler for spectral processing (no special-case handling) - Size/2 output bins instead of size/2 + 1 ### Usage Example ```cpp signalsmith::fft::ModifiedRealFFT mrfft(512); std::vector audio(512); std::vector> spectrum(256); // size/2 // ... fill audio ... mrfft.fft(audio, spectrum); // Forward: 512 samples → 256 bins mrfft.ifft(spectrum, audio); // Inverse: 256 bins → 512 samples // Bin k is centered at frequency (k + 0.5) / 512 ``` ```