### Rubberband Command-Line Tool Usage Examples Source: https://context7.com/breakfastquay/rubberband/llms.txt Provides various examples of using the `rubberband` command-line utility for batch audio processing. Demonstrates options for time stretching, pitch shifting, selecting different processing engines, and handling tempo notation. ```bash # Basic usage: stretch time by 1.5x and shift pitch up 2 semitones rubberband -t 1.5 -p 2.0 input.wav output.wav # Use R3 (Finer) engine for higher quality rubberband -3 -t 1.5 -p 2.0 input.wav output.wav # Use R2 (Faster) engine explicitly rubberband -2 -t 1.0 -p 5.0 input.wav output.wav # Double tempo (0.5 = half duration) without pitch change rubberband -t 0.5 -p 0 input.wav output.wav # Pitch shift down one octave with formant preservation rubberband -t 1.0 -p -12.0 --formant input.wav output.wav # Tempo notation: 120bpm to 140bpm rubberband -T 140:120 input.wav output.wav # Crisp transients for percussive material rubberband -t 0.75 -c 6 input.wav output.wav # Real-time mode (no study pass) rubberband --realtime -t 1.2 -p 0 input.wav output.wav # Quiet mode with crispness setting rubberband -q -t 1.5 -c 3 input.wav output.wav # Process multiple files for file in *.wav; do rubberband -t 1.25 -p 0 "$file" "stretched_$file" done ``` -------------------------------- ### Meson Configuration with Options Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Example of configuring the Meson build with a specific option, such as setting the path for the Intel IPP library. This demonstrates how to pass custom build parameters. ```bash $ meson setup build -Dipp_path=/opt/intel/ipp ``` -------------------------------- ### Meson Build Setup and Compilation Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Standard command to set up and build the Rubber Band Library using Meson and Ninja. This process checks for dependencies and compiles all available targets. ```bash $ meson setup build && ninja -C build ``` -------------------------------- ### Initialize and Use RubberBandLiveShifter for Pitch Shifting (C++) Source: https://context7.com/breakfastquay/rubberband/llms.txt Demonstrates how to initialize and use the RubberBandLiveShifter class in C++ for real-time pitch shifting. It shows setting options, getting block size and delay, preparing input/output buffers, setting the initial pitch scale, and processing audio blocks with dynamic pitch adjustments. This class is suitable for applications requiring constant block size and low latency. ```cpp #include #include #include #include using namespace RubberBand; void useLiveShifter() { size_t sampleRate = 44100; size_t channels = 2; // Create live shifter with formant preservation RubberBandLiveShifter::Options options = RubberBandLiveShifter::OptionWindowMedium | RubberBandLiveShifter::OptionFormantPreserved | RubberBandLiveShifter::OptionChannelsTogether; RubberBandLiveShifter shifter(sampleRate, channels, options); // Get fixed block size (determined by shifter) size_t blockSize = shifter.getBlockSize(); size_t startDelay = shifter.getStartDelay(); std::cout << "Block size: " << blockSize << " frames" << std::endl; std::cout << "Start delay: " << startDelay << " frames" << std::endl; // Allocate fixed-size buffers std::vector inChannel0(blockSize); std::vector inChannel1(blockSize); float* inputBuffers[2] = { inChannel0.data(), inChannel1.data() }; std::vector outChannel0(blockSize); std::vector outChannel1(blockSize); float* outputBuffers[2] = { outChannel0.data(), outChannel1.data() }; // Set initial pitch shift (+7 semitones = perfect fifth) double semitones = 7.0; double pitchScale = std::pow(2.0, semitones / 12.0); shifter.setPitchScale(pitchScale); // Processing loop - always exactly blockSize in and out for (int i = 0; i < 100; ++i) { // Load exactly blockSize frames into inputBuffers // ... // Dynamically adjust pitch (e.g., for vibrato effect) if (i % 10 == 0) { double vibrato = std::sin(i * 0.1) * 0.5; // ±0.5 semitones double newPitch = std::pow(2.0, (semitones + vibrato) / 12.0); shifter.setPitchScale(newPitch); } // Process: always returns exactly blockSize frames shifter.shift(inputBuffers, outputBuffers); // Output exactly blockSize frames // ... } // Reset if needed shifter.reset(); std::cout << "Shifter reset, ready for new audio" << std::endl; } ``` -------------------------------- ### Dynamic Pitch and Time Ratio Control in Rubber Band (C++) Source: https://context7.com/breakfastquay/rubberband/llms.txt Demonstrates how to dynamically control pitch scaling and time ratio independently using the Rubber Band library. This example showcases setting various pitch shifts (semitones) and tempo adjustments (time ratio), including options for formant preservation and custom formant scaling. These parameters can be safely changed during real-time processing. ```cpp #include #include #include using namespace RubberBand; void demonstratePitchControl() { size_t sampleRate = 44100; size_t channels = 2; RubberBandStretcher stretcher( sampleRate, channels, RubberBandStretcher::OptionProcessRealTime | RubberBandStretcher::OptionEngineFaster, 1.0, 1.0 ); // Example 1: Shift pitch up one octave stretcher.setPitchScale(2.0); std::cout << "Pitch: +12 semitones (1 octave up)" << std::endl; // Example 2: Shift pitch down 5 semitones // Formula: pow(2.0, semitones / 12.0) double semitonesDown = -5.0; double pitchScale = std::pow(2.0, semitonesDown / 12.0); stretcher.setPitchScale(pitchScale); std::cout << "Pitch: " << semitonesDown << " semitones" << std::endl; // Example 3: Change tempo to 150% (1.5x slower) // Note: timeRatio is stretched/unstretched duration stretcher.setTimeRatio(1.5); std::cout << "Duration: 150% (slower)" << std::endl; // Example 4: Double tempo (2x faster) with formant preservation stretcher.setTimeRatio(0.5); // 0.5 = half duration = double tempo stretcher.setFormantOption(RubberBandStretcher::OptionFormantPreserved); std::cout << "Tempo: 2x with formant preservation" << std::endl; // Example 5: Custom formant scaling (R3 engine only) // Shift formants independently of pitch stretcher.setFormantScale(0.8); std::cout << "Custom formant scale: 0.8" << std::endl; // Verify current settings std::cout << "\nCurrent settings:" << std::endl; std::cout << " Time ratio: " << stretcher.getTimeRatio() << std::endl; std::cout << " Pitch scale: " << stretcher.getPitchScale() << std::endl; std::cout << " Formant scale: " << stretcher.getFormantScale() << std::endl; } ``` -------------------------------- ### Meson Auto-Features Configuration Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Example of using Meson's 'auto_features' flag to disable all optional components by default and then explicitly enabling specific ones, like the command-line utilities. This ensures only desired features are built. ```bash $ meson setup build -Dauto_features=disabled -Dcmdline=enabled ``` -------------------------------- ### Initialize Rubber Band Stretcher Constructor Source: https://context7.com/breakfastquay/rubberband/llms.txt Demonstrates how to create and initialize a Rubber Band stretcher instance. It shows configuration for offline mode, engine selection (R3), and setting initial time ratio and pitch scale. Dependencies include , , and . ```cpp #include #include #include using namespace RubberBand; int main() { // Audio configuration size_t sampleRate = 44100; size_t channels = 2; // Create stretcher in offline mode with R3 engine // Time ratio 1.5 = 50% slower, pitch scale 1.0 = no pitch change RubberBandStretcher::Options options = RubberBandStretcher::OptionProcessOffline | RubberBandStretcher::OptionEngineFiner | RubberBandStretcher::OptionChannelsTogether; RubberBandStretcher stretcher( sampleRate, channels, options, 1.5, // initialTimeRatio (1.5 = 50% slower) 1.0 // initialPitchScale (1.0 = no change) ); // Verify engine version int engineVersion = stretcher.getEngineVersion(); std::cout << "Using R" << engineVersion << " engine" << std::endl; return 0; } ``` -------------------------------- ### C API for Rubberband Live Shifter Source: https://context7.com/breakfastquay/rubberband/llms.txt Illustrates the usage of the C API for the Rubberband live audio shifter, focusing on real-time processing. This includes initializing the live shifter, setting parameters like pitch scale, and processing blocks of audio data. ```c /* C API for RubberBandLiveShifter */ void use_live_shifter_c_api() { unsigned int sampleRate = 48000; unsigned int channels = 2; RubberBandLiveOptions options = RubberBandLiveOptionWindowMedium | RubberBandLiveOptionFormantPreserved; RubberBandLiveState state = rubberband_live_new( sampleRate, channels, options ); unsigned int blockSize = rubberband_live_get_block_size(state); printf("Live shifter block size: %u\n", blockSize); // Allocate exact block size float* input[2]; float* output[2]; input[0] = (float*)malloc(blockSize * sizeof(float)); input[1] = (float*)malloc(blockSize * sizeof(float)); output[0] = (float*)malloc(blockSize * sizeof(float)); output[1] = (float*)malloc(blockSize * sizeof(float)); // Set pitch shift rubberband_live_set_pitch_scale(state, 1.5); /* perfect fifth up */ // Process for (int i = 0; i < 100; ++i) { // Load exactly blockSize frames // ... rubberband_live_shift( state, (const float* const*)input, (float* const*)output ); // Output exactly blockSize frames // ... } free(input[0]); free(input[1]); free(output[0]); free(output[1]); rubberband_live_delete(state); } ``` -------------------------------- ### Build Rubber Band on Windows (Meson) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library on Windows using the Meson build system. Requires Meson, Ninja, and compiler tools in the path. ```shell > meson setup build > ninja -C build ``` -------------------------------- ### C API for Rubberband Audio Stretching Source: https://context7.com/breakfastquay/rubberband/llms.txt Demonstrates using the C API to create and configure a Rubberband audio stretching state, process audio buffers, and retrieve results. It includes setting parameters like sample rate, channels, options, pitch scale, and managing input/output buffers. ```c #include #include #include #include void use_c_api() { unsigned int sampleRate = 44100; unsigned int channels = 2; // Create stretcher state RubberBandOptions options = RubberBandOptionProcessRealTime | RubberBandOptionEngineFaster | RubberBandOptionFormantPreserved; RubberBandState state = rubberband_new( sampleRate, channels, options, 1.0, /* time ratio */ 1.0 /* pitch scale */ ); // Check engine version int engine = rubberband_get_engine_version(state); printf("Using R%d engine\n", engine); // Set pitch shift: +3 semitones double pitchScale = pow(2.0, 3.0 / 12.0); rubberband_set_pitch_scale(state, pitchScale); // Get padding requirements unsigned int startPad = rubberband_get_preferred_start_pad(state); unsigned int startDelay = rubberband_get_start_delay(state); printf("Pad: %u, Delay: %u\n", startPad, startDelay); // Set max process size rubberband_set_max_process_size(state, 512); // Allocate buffers float* input[2]; float* output[2]; input[0] = (float*)malloc(512 * sizeof(float)); input[1] = (float*)malloc(512 * sizeof(float)); output[0] = (float*)malloc(2048 * sizeof(float)); output[1] = (float*)malloc(2048 * sizeof(float)); // Processing loop for (int i = 0; i < 100; ++i) { // Load audio into input buffers // ... int isFinal = (i == 99) ? 1 : 0; rubberband_process(state, (const float* const*)input, 512, isFinal); // Retrieve output int available = rubberband_available(state); if (available > 0) { unsigned int retrieved = rubberband_retrieve( state, (float* const*)output, (unsigned int)available ); printf("Retrieved %u frames\n", retrieved); // Write output } } // Cleanup free(input[0]); free(input[1]); free(output[0]); free(output[1]); rubberband_delete(state); printf("Processing complete\n"); } ``` -------------------------------- ### Build Properties Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios-simulator.txt Defines general properties for the build process. In this case, it indicates whether an executable wrapper is needed. ```ini [properties] needs_exe_wrapper = true ``` -------------------------------- ### Build Rubber Band on macOS (Universal Binary) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds a universal binary library for both Apple Silicon and Intel architectures on macOS using Meson and a cross-file. Requires Xcode command-line tools and optionally libsndfile. ```shell meson setup build --cross-file cross/macos-universal.txt && ninja -C build ``` -------------------------------- ### Rubber Band Command-Line Tool Usage Source: https://github.com/breakfastquay/rubberband/blob/default/README.md Demonstrates the basic and advanced usage of the Rubber Band command-line tool for audio processing. It specifies parameters for time stretching, pitch shifting, and engine selection (R2/R3). ```bash $ rubberband -t -p $ rubberband -t 1.5 -p 2.0 test.wav output.wav $ rubberband -h $ rubberband -2 $ rubberband -3 $ rubberband -c ``` -------------------------------- ### Build Rubber Band on Windows (Visual C++ Runtime) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library on Windows using Meson, specifying the Visual C++ runtime. Requires Meson, Ninja, and compiler tools. ```shell > meson setup build -Db_vscrt=mt ``` -------------------------------- ### Binary Paths Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios-simulator.txt Specifies the paths or names of essential binary tools used in the build process, such as the C compiler, C++ compiler, and the strip utility. ```ini [binaries] c = 'cc' cpp = 'c++' strip = 'strip' ``` -------------------------------- ### Build Rubber Band for iOS Simulator Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library for the iOS simulator using Meson and a cross-file. Requires Xcode command-line tools. ```shell meson setup build_sim --cross-file cross/ios-simulator.txt && ninja -C build_sim ``` -------------------------------- ### Build System Constants and Arguments Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios-simulator.txt Defines the sysroot path for iOS simulators and common arguments used in compilation. These arguments are essential for targeting specific architectures and minimum iOS versions. ```python sysroot = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk' common_args = [ '-isysroot', sysroot, '-arch', 'x86_64', '-mios-version-min=8' ] ``` -------------------------------- ### Configure Rubber Band Stretcher Engine Options in C++ Source: https://context7.com/breakfastquay/rubberband/llms.txt Demonstrates setting various processing options for the Rubber Band stretcher in C++. It covers configurations for high-quality offline processing, low-latency real-time performance, and specific settings for percussive material. Options include engine quality, formant preservation, real-time vs. offline mode, and transient handling. Dynamic option changes in real-time mode are also shown. ```cpp #include #include using namespace RubberBand; void demonstrateOptions() { size_t sampleRate = 44100; size_t channels = 2; // Example 1: High-quality offline processing for vocals RubberBandStretcher::Options vocalOptions = RubberBandStretcher::OptionProcessOffline | RubberBandStretcher::OptionEngineFiner | RubberBandStretcher::OptionFormantPreserved | RubberBandStretcher::OptionChannelsTogether; RubberBandStretcher vocalStretcher(sampleRate, channels, vocalOptions, 1.0, 1.0); std::cout << "Vocal stretcher: R3 engine, formant preservation" << std::endl; // Example 2: Low-latency real-time for live performance RubberBandStretcher::Options liveOptions = RubberBandStretcher::OptionProcessRealTime | RubberBandStretcher::OptionEngineFaster | RubberBandStretcher::OptionWindowShort | RubberBandStretcher::OptionPitchHighConsistency | RubberBandStretcher::OptionThreadingNever; RubberBandStretcher liveStretcher(sampleRate, channels, liveOptions, 1.0, 1.0); std::cout << "Live stretcher delay: " << liveStretcher.getStartDelay() << " samples" << std::endl; // Example 3: Percussive material with R2 engine RubberBandStretcher::Options percussiveOptions = RubberBandStretcher::OptionProcessOffline | RubberBandStretcher::OptionEngineFaster | RubberBandStretcher::OptionTransientsCrisp | RubberBandStretcher::OptionDetectorPercussive | RubberBandStretcher::OptionPhaseIndependent; RubberBandStretcher drumStretcher(sampleRate, channels, percussiveOptions, 1.0, 1.0); std::cout << "Percussive stretcher: crisp transients" << std::endl; // Example 4: Change options dynamically (real-time mode only) RubberBandStretcher dynamicStretcher( sampleRate, channels, RubberBandStretcher::OptionProcessRealTime, 1.0, 1.0 ); // Can change these options in real-time mode dynamicStretcher.setTransientsOption(RubberBandStretcher::OptionTransientsSmooth); dynamicStretcher.setDetectorOption(RubberBandStretcher::OptionDetectorSoft); dynamicStretcher.setPhaseOption(RubberBandStretcher::OptionPhaseLaminar); dynamicStretcher.setFormantOption(RubberBandStretcher::OptionFormantPreserved); std::cout << "Dynamic options changed during processing" << std::endl; } ``` -------------------------------- ### Build Rubber Band for iOS Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library for iOS using Meson and a cross-file. Requires Xcode command-line tools. ```shell meson setup build_ios --cross-file cross/ios.txt && ninja -C build_ios ``` -------------------------------- ### iOS Build Arguments Configuration Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios.txt Defines common compiler and linker arguments for building on iOS. It specifies the system root, target architectures (arm64, armv7), and minimum iOS version. C++ specific arguments include the C++ standard library. ```meson sysroot = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk' common_args = [ '-isysroot', sysroot, '-arch', 'arm64', '-arch', 'armv7', '-mios-version-min=8' ] c_args = common_args cpp_args = common_args + [ '-stdlib=libc++' ] cpp_link_args = cpp_args ``` -------------------------------- ### Perform Offline Audio Processing (Two-Pass) Source: https://context7.com/breakfastquay/rubberband/llms.txt Illustrates the two-pass offline audio processing workflow for high-quality stretching. It covers setting up the stretcher for offline mode, studying the audio in the first pass, and then processing and retrieving the stretched audio in the second pass. Dependencies include , , and . ```cpp #include #include #include using namespace RubberBand; void processAudioOffline() { size_t sampleRate = 48000; size_t channels = 2; size_t totalFrames = 100000; size_t blockSize = 1024; // Create offline stretcher - double tempo (0.5 = twice as fast) RubberBandStretcher stretcher( sampleRate, channels, RubberBandStretcher::OptionProcessOffline | RubberBandStretcher::OptionEngineFaster, 0.5, // timeRatio (0.5 = double speed) 1.0 // pitchScale (1.0 = no pitch change) ); // Tell stretcher total input duration stretcher.setExpectedInputDuration(totalFrames); // Allocate buffers (de-interleaved) std::vector channel0(blockSize); std::vector channel1(blockSize); float* inputBuffers[2] = { channel0.data(), channel1.data() }; // PASS 1: Study the entire audio std::cout << "Pass 1: Studying audio..." << std::endl; for (size_t i = 0; i < totalFrames; i += blockSize) { size_t frames = std::min(blockSize, totalFrames - i); bool final = (i + frames >= totalFrames); // Load audio data into inputBuffers here // ... stretcher.study(inputBuffers, frames, final); } // PASS 2: Process and retrieve output std::cout << "Pass 2: Processing audio..." << std::endl; std::vector outChannel0(blockSize); std::vector outChannel1(blockSize); float* outputBuffers[2] = { outChannel0.data(), outChannel1.data() }; for (size_t i = 0; i < totalFrames; i += blockSize) { size_t frames = std::min(blockSize, totalFrames - i); bool final = (i + frames >= totalFrames); // Load audio data into inputBuffers here // ... stretcher.process(inputBuffers, frames, final); // Retrieve all available output while (stretcher.available() > 0) { size_t received = stretcher.retrieve(outputBuffers, blockSize); // Write received frames to output file std::cout << "Retrieved " << received << " frames" << std::endl; } } // Check if processing is complete if (stretcher.available() == -1) { std::cout << "Processing complete" << std::endl; } } ``` -------------------------------- ### Build Rubber Band on macOS (Default Architecture) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library on macOS using the Meson build system for the default architecture. Requires Xcode command-line tools and optionally libsndfile. ```shell meson setup build && ninja -C build ``` -------------------------------- ### Built-in Compiler Options Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios-simulator.txt Defines specific compiler and linker arguments for C and C++. This includes applying common arguments and adding C++ specific standard library flags. ```ini [built-in options] c_args = common_args cpp_args = common_args + [ '-stdlib=libc++' ] cpp_link_args = cpp_args ``` -------------------------------- ### Build Rubber Band on macOS (Intel) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library on macOS for Intel (x86_64) processors using Meson and a cross-file. Requires Xcode command-line tools and optionally libsndfile. ```shell meson setup build --cross-file cross/macos-x86_64.txt && ninja -C build ``` -------------------------------- ### Build Rubber Band on macOS (Apple Silicon) Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Builds the Rubber Band library on macOS for Apple Silicon (arm64) using Meson and a cross-file. Requires Xcode command-line tools and optionally libsndfile. ```shell meson setup build --cross-file cross/macos-arm64.txt && ninja -C build ``` -------------------------------- ### Host Machine Properties Source: https://github.com/breakfastquay/rubberband/blob/default/cross/ios-simulator.txt Specifies the properties of the host machine where the build will take place, including CPU family, CPU type, operating system, and endianness. These are crucial for cross-compilation or ensuring compatibility. ```ini [host_machine] cpu_family = 'x86_64' cpu = 'x86_64' system = 'darwin' endian = 'little' ``` -------------------------------- ### Implement Variable Time Stretching with Key Frame Mapping in C++ Source: https://context7.com/breakfastquay/rubberband/llms.txt Illustrates how to use key frame mapping with the Rubber Band stretcher in C++ for non-uniform time stretching. This feature allows for custom tempo manipulation by defining specific source-to-output sample mappings, enabling variable speed changes across an audio track. It requires offline processing mode and careful calculation of the overall time ratio. ```cpp #include #include #include using namespace RubberBand; void demonstrateKeyFrameMapping() { size_t sampleRate = 44100; size_t channels = 2; // Must use offline mode for key frame mapping RubberBandStretcher stretcher( sampleRate, channels, RubberBandStretcher::OptionProcessOffline | RubberBandStretcher::OptionEngineFaster, 1.5, // overall time ratio 1.0 ); // Define key frame map: source sample -> output sample // This creates variable stretching across the audio std::map keyFrameMap; // Example: Slow down middle section, speed up ending keyFrameMap[0] = 0; // Start: no offset keyFrameMap[44100] = 44100; // 1 sec -> 1 sec (normal speed) keyFrameMap[88200] = 132300; // 2 sec -> 3 sec (1.5x slower) keyFrameMap[132300] = 198450; // 3 sec -> 4.5 sec (still slow) keyFrameMap[176400] = 220500; // 4 sec -> 5 sec (back to normal) keyFrameMap[220500] = 242550; // 5 sec -> 5.5 sec (2x faster ending) // Apply the mapping stretcher.setKeyFrameMap(keyFrameMap); // The overall time ratio must still be set correctly // Calculate: total_output / total_input double overallRatio = 242550.0 / 220500.0; stretcher.setTimeRatio(overallRatio); std::cout << "Key frame map applied with " << keyFrameMap.size() << " key points" << std::endl; std::cout << "Overall ratio: " << overallRatio << std::endl; // Now process with study() and process() as usual // The stretcher will interpolate between key frames } ``` -------------------------------- ### Makefile Build for Linux Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Alternative build command for Linux using a Makefile, specifically for users who prefer Makefiles over Meson and only need the static library. This is found in the 'otherbuilds' directory. ```bash $ make -f otherbuilds/Makefile.linux ``` -------------------------------- ### Rubber Band Library C API Source: https://github.com/breakfastquay/rubberband/blob/default/README.md Shows how to include the C language bindings header for the Rubber Band Library. This C API is a wrapper around the C++ implementation and requires linkage against C++ standard libraries. ```c #include ``` -------------------------------- ### Real-Time Audio Processing with Dynamic Ratio Changes (C++) Source: https://context7.com/breakfastquay/rubberband/llms.txt Processes audio in real-time using Rubber Band, enabling dynamic changes to pitch and time ratios with minimal latency. This function utilizes high consistency pitch shifting and demonstrates buffer management for continuous audio streams. Input and output buffer sizes may differ, requiring careful handling of retrieved frames. ```cpp #include #include #include using namespace RubberBand; void processAudioRealtime() { size_t sampleRate = 44100; size_t channels = 2; // Create real-time stretcher with high consistency pitch shifting RubberBandStretcher stretcher( sampleRate, channels, RubberBandStretcher::OptionProcessRealTime | RubberBandStretcher::OptionEngineFaster | RubberBandStretcher::OptionPitchHighConsistency, 1.0, // timeRatio 1.0 // pitchScale ); // Get padding and delay info for alignment size_t startPad = stretcher.getPreferredStartPad(); size_t startDelay = stretcher.getStartDelay(); std::cout << "Pad start with " << startPad << " silent frames" << std::endl; std::cout << "Discard first " << startDelay << " output frames" << std::endl; // Set max process size for fixed buffer operation size_t blockSize = 512; stretcher.setMaxProcessSize(blockSize); // Allocate buffers std::vector channel0(blockSize); std::vector channel1(blockSize); float* inputBuffers[2] = { channel0.data(), channel1.data() }; std::vector outChannel0(blockSize * 4); std::vector outChannel1(blockSize * 4); float* outputBuffers[2] = { outChannel0.data(), outChannel1.data() }; // Process loop - ratios can be changed dynamically bool processing = true; size_t framesProcessed = 0; while (processing) { // Dynamically change pitch (e.g., based on user input) if (framesProcessed == 10000) { // Shift up 2 semitones: pow(2.0, 2.0/12.0) = 1.1225 stretcher.setPitchScale(std::pow(2.0, 2.0 / 12.0)); std::cout << "Changed pitch to +2 semitones" << std::endl; } // Load audio into inputBuffers here // ... bool isFinal = false; // set to true on last block stretcher.process(inputBuffers, blockSize, isFinal); // Retrieve output (may be more or less than input) int available = stretcher.available(); if (available > 0) { size_t toRetrieve = std::min((size_t)available, blockSize * 4); size_t received = stretcher.retrieve(outputBuffers, toRetrieve); std::cout << "Retrieved " << received << " frames" << std::endl; // Output received frames } framesProcessed += blockSize; if (framesProcessed > 50000) processing = false; } } ``` -------------------------------- ### Rubber Band Library C++ API Source: https://github.com/breakfastquay/rubberband/blob/default/README.md Illustrates the inclusion of C++ headers for the Rubber Band Library, which provides classes for time and pitch manipulation. It requires including either C++ or C headers, but not both. ```cpp #include #include ``` -------------------------------- ### Meson Default Library Type Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Commands to configure the Meson build to produce only a static or only a shared library. This allows control over the type of library artifact generated. ```bash $ meson setup build -Ddefault_library=static $ meson setup build -Ddefault_library=shared ``` -------------------------------- ### Meson Feature Management Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Demonstrates disabling a specific Meson feature, like JNI, to prevent it from being built even if its requirements are met. This is useful for customizing the build output. ```bash $ meson setup build -Djni=disabled ``` -------------------------------- ### Android NDK Build File Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Provides an Android NDK build file (Android.mk) for compiling a shared library for ARM architectures, intended for loading from Java applications via the Android NDK. ```makefile # otherbuilds/Android.mk # (Content not provided in the input text, only the filename is mentioned) ``` -------------------------------- ### Java Native Interface for Rubber Band Source: https://github.com/breakfastquay/rubberband/blob/default/COMPILING.md Java code for the native interface to the Rubber Band library, enabling integration with Android applications using the Java Native Interface (JNI). ```java // com/breakfastquay/rubberband/RubberBandStretcher.java // (Content not provided in the input text, only the filename is mentioned) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.