A time-stretcher such as Rubber Band Library has to be handled a little differently from a typical audio effect.
When speeding up or slowing down audio, there is by definition a difference between the input and output "rates" of the processor. If you supply N samples as input to the processor, then you will get more than N (when slowing down) or fewer (when speeding up) as output.
This must be the case for any audio time stretcher library, but on top of this, with Rubber Band the effective rate can also differ locally depending on the locations of detected features such as percussive transients, which it usually tries to pass through unmodified. This means that the input and output rates are not always in a stable ratio: the ratio you set behaves like a long-term average, rather than a fixed ratio for every processing block. This is true to some extent even if you are using the processor only for pitch-shifting.
For real-time use especially, it may be simplest to use Rubber Band if you are able to integrate it using a "pull" configuration rather than a "push" one, so that the number of samples it obtains for a given number of output samples is allowed to vary freely. That is:
available), as there may be some in its internal buffers;
This structure can be seen at work in the Mini Example with Qt and Sonic Visualiser code examples below.
Here are some code examples. We don't recommend trying to use any of these as a cut-and-paste source, but they may help as documentation to address specific points of concern.
Illustrative examples published by Breakfast Quay:
Third-party examples from open-source code using Rubber Band Library:
There is also a pitch-shifter example in the Rubber Band Library source distribution.