OK, I found the code responsible for this in celt_encoder.c in the compute_vbr(...) function.
It's pretty ad-hoc and even says so in the code. Just don't allow instantaneous rate to exceed twice the target rate for any one frame.
I changed it to IMIN(base_target,target) and recompiled and it works fine. This is kind of what I was after since CBR is not really helpful. I need to transfer other data as well, not only audio. This other data is not time critical so I would lke Opus to gobble up as many bits as possible in order to maximize quality for those problematic frames.
Like I stated in my first question ideally there would be an encoding mode where for some number of frames the available bandwidth must never be exceeded.
Doesn't look to be trivial to implement though.
/* Make VBR less aggressive for constrained VBR because we can't keep a higher bitrate
for long. Needs tuning. */
if ((!has_surround_mask||lfe) && constrained_vbr)
{
target = base_target + (opus_int32)MULT16_32_Q15(QCONST16(0.67f, 15), target-base_target);
}
if (!has_surround_mask && tf_estimate < QCONST16(.2f, 14))
{
opus_val16 amount;
opus_val16 tvbr_factor;
amount = MULT16_16_Q15(QCONST16(.0000031f, 30), IMAX(0, IMIN(32000, 96000-bitrate)));
tvbr_factor = SHR32(MULT16_16(temporal_vbr, amount), DB_SHIFT);
target += (opus_int32)MULT16_32_Q15(tvbr_factor, target);
}
/* Don't allow more than doubling the rate */
// target = IMIN(2*base_target, target);
target = IMIN(base_target, target); // <----- Never exceed available bandwidth