Hi everyone, I need to change the sample rate of my plugin dynamically to a specific value. To my understanding, the main plugin process() is called let’s say 44100 time if the rack engine sample rate is 44100Hz. What I want to do, if possible, is to have a knob that can divide/multiply the main rack engine clock by a set amount (float, not integer) for it to be 1/4 of the main rack samplerate, etc… I don’t want to resample the plugin audio input but just re-clock the whole rack engine. This can be of course done manually from the engine menu to an integer value (x2,x4…) but I would like it to be a fraction of the current value. On top of this, I would also ideally be able to modulate this new rate (let’s say by a sine LFO modulating this knob). Is this even achievable? I am deep diving in libsamplerate but there is not much documentation or examples to pick up from. Thanks!!
Hi @foamborn83, and welcome to the forum!
To make sure I understand–you want your own module to be running at some arbitrary multiple of the Rack sample rate, or you want to change the Rack sample rate (for all modules) from within your module?
It might help to know a bit more about your module’s intended use. What effect do you want from changing the sample rate dynamically? Why do you want it to be continuous (arbitrary multiple) rather than only integer multiples? You mention LFOs–how quickly do you want it to change? Are you outputting audio or control signals? Are you wanting to avoid aliasing, or embrace it?
Thanks so much for your help! My scenario is a bit complicated, I’ll try to explain it. So basically I have a lot of guitar pedals that run on spin fv-1 dsp chip and there is a vcv rack plugin that emulates it. For many of these pedals, it was an easy task to get the assembler code from the eeprom, put them straight in the emulator, downsample the whole VCV rack engine to 32768Hz (so that it matches the actual clock on the hardware spin fv-1) and have the same sort of lo-fi feel. (if you run the same exact code at let’s say 44100Hz, everything would sound different from the actual pedal, specifically the length of the delays etc…). So what I have done so far is set and forget from the VCV rack engine settings file the sample rate to a fixed value of 32768Hz. So far so good, everything works spot on and I am super happy with the incredible results. Now, I reverse engineered a couple of pedals that on top of this modulate the clock (samplerate) of the spin-fv1 dsp chip in realtime to obtain a kind of “modulation” where the reverb goes from grainy to hifi with longer or shorter tails. At this stage, it would be equivalent to me manually modulating the sample rate of the whole VCV rack engine somehow by a lfo (or just the internal samplerate of the plugin so that I can change how many times the plugin process() method is called?) or at least be able to do the same thing that picking up from the engine samplerate menu does but with fractional values instead of integer values. I hope I kind of explained the whole thing, let me know if any questions and thanks for helping me out!! I went so far with this that this would be the very last thing I need to do or bail!!
Coming to your questions: the only module I run is the audio module and the fv-1 emulator so I am good in both cases, no other modules are running except for audio modules in and out to get the guitar signal. I would love to be able to have a knob in the plugin and eventually be able to modulate it by a LFO by a short amount (this is secondary and I would love to have this as well). I want it to be continuous cause the modulation is kind of subtle and its depth is less than an integer multiple of the samplerate. LFO rate should be slow, somewhere around 100Hz maximum I reckon. I am outputting audio, aliasing is expected and part of the lo-fi nature of the effect. Thanks again!
Got it! Thanks for your detailed reply, that makes total sense and is very helpful. Cool use of the FV-1 emulator! (Vari-clock hardware emulation was one of my hypotheses… )
I only have a moment right now, and am far from the most knowledgeable person on this forum about resampling issues, but maybe I can gesture vaguely in the right direction.
You can probably set the VCV engine sample rate programmatically by using the Engine methods–VCV’s internals are pretty much wide open–but I would expect catastrophic results from modulating that. Never tried it.
So I think the best approach is to try to simulate variclocking within your module. Sounds like you’re not wanting to overclock the Spin chip very much, so I think one basic strategy would be to set the VCV sample rate high (maybe 96kHz) and have a secondary function (process_spin()
) fill up a buffer at whatever modulated sample rate you derive from the controls, etc. process()
wraps process_spin()
, calls it when appropriate based on the ratio of the engine sample rate to the simulated sample rate, and runs SRC on what’s in the buffer when it needs to provide output. May require double-buffering.
Gotta run for now, but take a look at the Audible Instruments Clouds source code if you haven’t. It’s simulating hardware running at a different sample rate. No modulation, but you can switch it from 16kHz to 32kHz; integer multiple, so much easier to handle, but in general it may give you a starting point. Also check the VCV Delay code and how it does SRC on the delay buffer based on the (modulatable) freq
parameter.
Others are likely to have much better and more specific ideas!