af_scaletempo2: prioritize louder channels for similarity measure

Playback with many audio channels could be distorted when using
scaletempo2. This was most noticeable when there were a lot of quiet
channels and few louder channels.

Fix this by increasing the weight of louder channels in relation to
quieter channels. Each channel's target block energy is factored into
the usual similarity measure.

This should have little effect on very correlated channels (such as most
stereo media), where the factors are very similar for all channels.

See-Also: #8705
See-Also: #13737
This commit is contained in:
ferreum 2024-03-21 21:18:37 +01:00 committed by Dudemanguy
parent a5269d7a73
commit 096d35dac7
1 changed files with 4 additions and 4 deletions

View File

@ -93,15 +93,15 @@ static void multi_channel_moving_block_energies(
}
static float multi_channel_similarity_measure(
const float* dot_prod_a_b,
const float* energy_a, const float* energy_b,
const float* dot_prod,
const float* energy_target, const float* energy_candidate,
int channels)
{
const float epsilon = 1e-12f;
float similarity_measure = 0.0f;
for (int n = 0; n < channels; ++n) {
similarity_measure += dot_prod_a_b[n]
/ sqrtf(energy_a[n] * energy_b[n] + epsilon);
similarity_measure += dot_prod[n] * energy_target[n]
/ sqrtf(energy_target[n] * energy_candidate[n] + epsilon);
}
return similarity_measure;
}