### Complete C++ Reverb Integration Example Source: https://context7.com/sinshu/freeverb/llms.txt This C++ example shows how to integrate the Freeverb library into a custom audio application. It includes real-time parameter control, stereo audio processing, and preset management. Ensure the 'revmodel.hpp' header is available. ```cpp #include "revmodel.hpp" #include class ReverbProcessor { private: revmodel reverb; public: ReverbProcessor() { // Initialize with sensible defaults reverb.setroomsize(0.6f); reverb.setdamp(0.4f); reverb.setwet(0.25f); reverb.setdry(0.75f); reverb.setwidth(1.0f); reverb.setmode(0.0f); } // Process interleaved stereo audio void processInterleaved(float* buffer, int numFrames) { // Deinterleave float* tempL = new float[numFrames]; float* tempR = new float[numFrames]; for (int i = 0; i < numFrames; i++) { tempL[i] = buffer[i * 2]; tempR[i] = buffer[i * 2 + 1]; } // Process with replace mode reverb.processreplace(tempL, tempR, tempL, tempR, numFrames, 1); // Reinterleave for (int i = 0; i < numFrames; i++) { buffer[i * 2] = tempL[i]; buffer[i * 2 + 1] = tempR[i]; } delete[] tempL; delete[] tempR; } // Preset management void setSmallRoom() { reverb.setroomsize(0.3f); reverb.setdamp(0.7f); reverb.setwet(0.2f); } void setLargeHall() { reverb.setroomsize(0.9f); reverb.setdamp(0.3f); reverb.setwet(0.35f); } void setFreezeMode(bool freeze) { reverb.setmode(freeze ? 1.0f : 0.0f); } void reset() { reverb.mute(); } }; // Usage int main() { ReverbProcessor processor; // Simulate processing a buffer of audio const int bufferSize = 512; float audioBuffer[bufferSize * 2]; // Stereo interleaved // Fill with test signal (sine wave) for (int i = 0; i < bufferSize; i++) { float sample = 0.5f * sinf(2.0f * 3.14159f * 440.0f * i / 44100.0f); audioBuffer[i * 2] = sample; // Left audioBuffer[i * 2 + 1] = sample; // Right } // Process with reverb processor.processInterleaved(audioBuffer, bufferSize); // Switch to large hall preset processor.setLargeHall(); processor.processInterleaved(audioBuffer, bufferSize); return 0; } ``` -------------------------------- ### Freeverb VST Plugin Instantiation Source: https://context7.com/sinshu/freeverb/llms.txt Provides the entry point for VST hosts to create an instance of the Freeverb plugin. Supports various audio channel configurations. ```cpp #include "Freeverb.hpp" // VST plugin instantiation (called by host) AudioEffect* createEffectInstance(audioMasterCallback audioMaster) { return new Freeverb(audioMaster); } // The plugin supports: // - Stereo input/output (2in2out) // - Mono to stereo (1in2out) // - Mono processing (1in1out) // - Both accumulating and replacing output modes ``` -------------------------------- ### Initialize and Configure revmodel Source: https://context7.com/sinshu/freeverb/llms.txt Instantiate the main reverb model and set its parameters. All configuration values are normalized between 0.0 and 1.0. Ensure input and output buffers are prepared before processing. ```cpp #include "revmodel.hpp" // Create a reverb model instance revmodel reverb; // Configure reverb parameters (all values normalized 0.0 - 1.0) reverb.setroomsize(0.8f); // Large room (0.0 = small, 1.0 = large) reverb.setdamp(0.5f); // Medium damping (0.0 = bright, 1.0 = dark) reverb.setwet(0.3f); // 30% wet signal reverb.setdry(0.7f); // 70% dry signal reverb.setwidth(1.0f); // Full stereo width (0.0 = mono, 1.0 = stereo) reverb.setmode(0.0f); // Normal mode (>= 0.5 = freeze mode) ``` -------------------------------- ### Initialize and Configure allpass Filter Source: https://context7.com/sinshu/freeverb/llms.txt Create an allpass filter instance and assign a buffer. Set the feedback parameter, which is typically 0.5 for Freeverb to achieve diffusion. ```cpp #include "allpass.hpp" // Create allpass filter and assign buffer allpass allpassFilter; float buffer[556]; // Buffer size determines diffusion delay allpassFilter.setbuffer(buffer, 556); // Set feedback (typically 0.5 for Freeverb) allpassFilter.setfeedback(0.5f); ``` -------------------------------- ### Initialize and Configure comb Filter Source: https://context7.com/sinshu/freeverb/llms.txt Create a comb filter instance and assign a buffer for its delay line. Configure the feedback and damping parameters to control the decay and frequency response. ```cpp #include "comb.hpp" // Create comb filter and assign buffer comb combFilter; float buffer[1116]; // Buffer size determines delay time (~25ms at 44.1kHz) combFilter.setbuffer(buffer, 1116); // Configure filter parameters combFilter.setfeedback(0.84f); // Feedback amount (controls decay time) combFilter.setdamp(0.2f); // Damping (0.0 = no damping, 1.0 = full) ``` -------------------------------- ### Process Audio with revmodel Source: https://context7.com/sinshu/freeverb/llms.txt Process audio input buffers using either 'processreplace' (overwrites output) or 'processmix' (adds to output). The 'skip' parameter should be 1 for non-interleaved buffers. ```cpp // Process audio buffers (replace mode - overwrites output) float inputL[512], inputR[512]; float outputL[512], outputR[512]; // ... fill input buffers with audio samples ... reverb.processreplace(inputL, inputR, outputL, outputR, 512, 1); // skip=1 for non-interleaved buffers // Or use mix mode - adds to existing output reverb.processmix(inputL, inputR, outputL, outputR, 512, 1); ``` -------------------------------- ### Freeverb VST Plugin Parameters Source: https://context7.com/sinshu/freeverb/llms.txt Defines the indices for the 6 automatable VST plugin parameters. These control the reverb's Mode, Room Size, Damping, Width, Wet Level, and Dry Level. ```cpp // Plugin parameter indices enum { KMode, // 0 = Normal, 1 = Freeze KRoomSize, // Room size (0.0 - 1.0) KDamp, // Damping amount (0.0 - 1.0) KWidth, // Stereo width (0.0 - 1.0) KWet, // Wet signal level (0.0 - 1.0) KDry, // Dry signal level (0.0 - 1.0) KNumParams // Total parameter count (6) }; ``` -------------------------------- ### Read comb Filter Parameters Source: https://context7.com/sinshu/freeverb/llms.txt Retrieve the current feedback and damping settings of the comb filter. ```cpp // Get current parameters float feedback = combFilter.getfeedback(); float damping = combFilter.getdamp(); ``` -------------------------------- ### Read revmodel Parameters Source: https://context7.com/sinshu/freeverb/llms.txt Retrieve the current settings of the reverb model. These values reflect the last set parameters. ```cpp // Read back current parameter values float roomSize = reverb.getroomsize(); float dampAmount = reverb.getdamp(); float wetLevel = reverb.getwet(); float dryLevel = reverb.getdry(); float stereoWidth = reverb.getwidth(); float mode = reverb.getmode(); // Returns 0 (normal) or 1 (frozen) ``` -------------------------------- ### Freeverb Tuning Constants Source: https://context7.com/sinshu/freeverb/llms.txt Defines filter tuning values and default parameters for a natural-sounding reverb at 44.1KHz. Assumes specific sample rates for comb and allpass filter tunings. ```cpp #include "tuning.h" // Filter counts const int numcombs = 8; // 8 comb filters per channel const int numallpasses = 4; // 4 allpass filters per channel // Gain and scaling values const float fixedgain = 0.015f; // Input gain to prevent clipping const float scalewet = 3; // Wet output scaling const float scaledry = 2; // Dry output scaling const float scaledamp = 0.4f; // Damping scaling const float scaleroom = 0.28f; // Room size scaling const float offsetroom = 0.7f; // Room size offset // Default initial values const float initialroom = 0.5f; // Medium room size const float initialdamp = 0.5f; // Medium damping const float initialwet = 1/scalewet; // ~0.33 wet level const float initialdry = 0; // No dry signal const float initialwidth = 1; // Full stereo width const float initialmode = 0; // Normal mode const float freezemode = 0.5f; // Threshold for freeze mode // Stereo spread (samples offset between L/R channels) const int stereospread = 23; // Comb filter tunings (buffer sizes in samples @ 44.1kHz) const int combtuningL1 = 1116; // ~25.3ms const int combtuningL2 = 1188; // ~26.9ms const int combtuningL3 = 1277; // ~29.0ms const int combtuningL4 = 1356; // ~30.7ms const int combtuningL5 = 1422; // ~32.2ms const int combtuningL6 = 1491; // ~33.8ms const int combtuningL7 = 1557; // ~35.3ms const int combtuningL8 = 1617; // ~36.7ms // Right channel = Left + stereospread // Allpass filter tunings (buffer sizes in samples @ 44.1kHz) const int allpasstuningL1 = 556; // ~12.6ms const int allpasstuningL2 = 441; // ~10.0ms const int allpasstuningL3 = 341; // ~7.7ms const int allpasstuningL4 = 225; // ~5.1ms // Right channel = Left + stereospread ``` -------------------------------- ### Process Sample with comb Filter Source: https://context7.com/sinshu/freeverb/llms.txt Process a single audio sample through the configured comb filter. The output is the delayed and filtered input. ```cpp // Process a single sample float inputSample = 0.5f; float outputSample = combFilter.process(inputSample); ``` -------------------------------- ### Process Sample with allpass Filter Source: https://context7.com/sinshu/freeverb/llms.txt Process a single audio sample through the configured allpass filter. This helps to smooth and diffuse the reverb sound. ```cpp // Process a single sample float inputSample = 0.5f; float outputSample = allpassFilter.process(inputSample); ``` -------------------------------- ### Read allpass Filter Feedback Source: https://context7.com/sinshu/freeverb/llms.txt Retrieve the current feedback value set for the allpass filter. ```cpp // Get current feedback value float feedback = allpassFilter.getfeedback(); ``` -------------------------------- ### Mute revmodel Source: https://context7.com/sinshu/freeverb/llms.txt Clears all internal filter buffers of the reverb model, effectively silencing the reverb tail. ```cpp // Mute reverb (clear all filter buffers) reverb.mute(); ``` -------------------------------- ### Mute allpass Filter Source: https://context7.com/sinshu/freeverb/llms.txt Clears the allpass filter's internal buffer, stopping any ongoing delayed signal. ```cpp // Clear buffer allpassFilter.mute(); ``` -------------------------------- ### Mute comb Filter Source: https://context7.com/sinshu/freeverb/llms.txt Clears the comb filter's internal buffer, effectively stopping any ongoing delayed signal. ```cpp // Clear buffer (silence reverb tail) combFilter.mute(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.