Originally, the FFmpeg/Libav AC-3 encoder used a fixed bandwidth cutoff of 21kHz for 48kHz sample rate content. For low-to-moderate bitrates (80kbps to 160kbps, stereo) this was way too high and ended up with audible, annoying high frequency artifacts and dull/tinny sounding cymbals. It also made the lower frequencies sound worse at the lower settings. As a remedy for this, I changed the default bandwidth setting to adapt to the bitrate and number of channels. The values I chose matched content produced by professional AC-3 encoders.
This fixed the issue of high-frequency artifacts, but the downside was that some content that would sound much better with the higher frequencies was getting cutoff much lower than necessary. The way I tried to solve this problem previously in Aften was to implement a variable bandwidth mode that would adjust the bandwidth per-frame to adapt to changing content. The idea was ok, but the result ended up sounding weird in some cases because of large fluctuations in bandwidth in a short period of time. It turns out that the human ear is quite sensitive to changes in bandwidth. If you start out at a low bandwidth, your ears don't know what they're missing, but if you go from high bandwidth to low bandwidth it is very noticeable.
For the Libav AC-3 encoder, I decided to revisit the Aften variable bandwidth (VBW) encoding mode to see if I could improve it. What I wanted to do was to somehow smooth out the transitions so that the changes are not as noticeable. The solution I ended up with works pretty well. I started by defining the minimum bandwidth as the existing default bandwidth and then creating a new table for maximum bandwidth. For high and very low bitrates the max and min are the same, which disables the VBW mode. For low-to-moderate bitrates the VBW mode selects a value between min and max that will result in a decent quality (fixed SNR offset of -1dB). The rate of change between frames is moderated using an exponential moving average with a half-life of 2.2 seconds. This allows for decent transition speed without being too volatile.
The VBW mode is the first step toward adaptive channel coupling. The goal will be to adaptively turn coupling on/off and to adapt the coupling start/end bands based on content.