From 2a6b10c9cac1f70a6dfa2d51f898f7c58f240282 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 28 Apr 2015 22:01:55 +0200 Subject: audio: separate fallbacks for upmix and downmix cases We always want to prefer upmix to downmix, as long as it makes sense. Even if the upmix is not "perfect" (not just adding channels), we want to prefer the upmix. Cleanup for commit d3c7fd9d. (cherry picked from commit c4aa13615501189c55c23448d436074e5f92c8cc) --- audio/chmap_sel.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/audio/chmap_sel.c b/audio/chmap_sel.c index b99f7bd834..272e3e4baf 100644 --- a/audio/chmap_sel.c +++ b/audio/chmap_sel.c @@ -199,12 +199,16 @@ bool mp_chmap_sel_adjust(const struct mp_chmap_sel *s, struct mp_chmap *map) return false; } -#define UPMIX_IDX 0 -#define FALLBACK_IDX 1 -#define DOWNMIX_IDX 2 +enum { + UPMIX_IDX, + FALLBACK_UPMIX_IDX, + DOWNMIX_IDX, + FALLBACK_DOWNMIX_IDX, + REMIX_COUNT +}; static bool test_fallbacks(struct mp_chmap *a, struct mp_chmap *b, - int best_diffs[2], struct mp_chmap best[2]) + int best_diffs[], struct mp_chmap best[]) { struct mp_chmap diff1, diff2; @@ -222,15 +226,15 @@ static bool test_fallbacks(struct mp_chmap *a, struct mp_chmap *b, return true; } - if (diff1.num > 0 && best_diffs[FALLBACK_IDX] > diff1.num) { - best[FALLBACK_IDX] = *a; - best_diffs[FALLBACK_IDX] = diff1.num; + if (diff1.num > 0 && best_diffs[FALLBACK_UPMIX_IDX] > diff1.num) { + best[FALLBACK_UPMIX_IDX] = *a; + best_diffs[FALLBACK_UPMIX_IDX] = diff1.num; return true; } - if (diff2.num > 0 && best_diffs[FALLBACK_IDX] > diff2.num) { - best[FALLBACK_IDX] = *a; - best_diffs[FALLBACK_IDX] = diff2.num; + if (diff2.num > 0 && best_diffs[FALLBACK_DOWNMIX_IDX] > diff2.num) { + best[FALLBACK_DOWNMIX_IDX] = *a; + best_diffs[FALLBACK_DOWNMIX_IDX] = diff2.num; return true; } @@ -255,8 +259,10 @@ bool mp_chmap_sel_fallback(const struct mp_chmap_sel *s, struct mp_chmap *map) return true; } - int best_diffs[] = { INT_MAX, INT_MAX, INT_MAX }; - struct mp_chmap best[] = { {0}, {0}, {0} }; + struct mp_chmap best[REMIX_COUNT] = {{0}}; + int best_diffs[REMIX_COUNT]; + for (int n = 0; n < REMIX_COUNT; n++) + best_diffs[n] = INT_MAX; for (int n = 0; n < s->num_chmaps; n++) { struct mp_chmap e = s->chmaps[n]; -- cgit v1.2.3