avcodec/psymodel: add pair-synced window switching hook and pair state

Divergent block switching between the two channels of a CPE disables
common_window, and with it every joint stereo tool, on exactly the
frames that need them most; the lone short channel then codes its
transient alone, which is audible as one-channel garble at beats.

Add an optional window_pair() model hook so a psy model can decide both
channels of a pair together, and encoder-fed per-pair state: the
joint-tool candidacy fraction EMA and a Schmitt-gated decouple flag,
letting the model fall back to independent per-channel switching on
content whose joint tools are dead (diffuse, decorrelated pairs) where
forcing a common grid only costs quality.
This commit is contained in:
Lynne
2026-07-17 14:18:41 +08:00
parent 9bc73ba344
commit 26586c898f

View File

@@ -106,6 +106,8 @@ typedef struct FFPsyContext {
} bitres;
void* model_priv_data; ///< psychoacoustic model implementation private data
float pair_joint[16]; ///< encoder-fed per-CPE joint-tool candidacy fraction EMA (bands M/S would adopt or I/S renders; ~0 = joint tools dead); 0 = unseeded
uint8_t pair_decoupled[16]; ///< Schmitt state over pair_joint: 1 = joint tools dead on this pair, joint windowing/M-S coupling suspended
} FFPsyContext;
/**
@@ -128,6 +130,17 @@ typedef struct FFPsyModel {
*/
FFPsyWindowInfo (*window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type);
/**
* Suggest window sequences for both channels of a CPE with block switching
* synchronized across the pair (either channel's attack switches both), so
* common_window and the joint stereo tools stay available. Optional; when
* NULL the encoder decides each channel independently via window().
*/
void (*window_pair)(FFPsyContext *ctx, const float *audio0, const float *la0,
const float *audio1, const float *la1,
int channel0, int channel1,
int prev_type0, int prev_type1, FFPsyWindowInfo wi[2]);
/**
* Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels.
*