History

chmap_sel: improve speaker replacement handling

This didn't really work since the last time the channel map fallback code was touched. In some cases, quite bad results were selected.

wm4 committed 11 years ago

Commit afdc0601 parent 55624a72 files · +48 −17Browse files

Unified · Split

2 files
  1. audio/chmap_sel.c +33 −17
  2. test/chmap_sel.c +15 −0
audio/chmap_sel.c+33−17
@@ -234,29 +234,45 @@ bool mp_chmap_sel_fallback(const struct mp_chmap_sel *s, struct mp_chmap *map) · 233 unmodified lines
234234 return true;
235235 }
236236
237− struct mp_chmap best = {0};
237+ struct mp_chmap best_of_best = {0};
238+
239+ for (int i = -1; i < (int)MP_ARRAY_SIZE(speaker_replacements); i++) {
240+ struct mp_chmap best = {0};
241+ struct mp_chmap t = *map;
242+
243+ if (i >= 0) {
244+ struct mp_chmap *r = (struct mp_chmap *)speaker_replacements[i];
245+ if (!replace_speakers(&t, r))
246+ continue;
247+ }
248+
249+ for (int n = 0; n < s->num_chmaps; n++) {
250+ struct mp_chmap e = s->chmaps[n];
251+
252+ if (mp_chmap_is_unknown(&e))
253+ continue;
238254
239− for (int n = 0; n < s->num_chmaps; n++) {
240− struct mp_chmap e = s->chmaps[n];
241−
242− if (mp_chmap_is_unknown(&e))
243− continue;
244−
245− // in case we didn't match any fallback retry after replacing speakers
246− for (int i = -1; i < (int)MP_ARRAY_SIZE(speaker_replacements); i++) {
247− struct mp_chmap t = *map;
248− if (i >= 0) {
249− struct mp_chmap *r = (struct mp_chmap *)speaker_replacements[i];
250− if (!replace_speakers(&t, r))
251− continue;
252− }
253255 if (mp_chmap_is_better(&t, &best, &e))
254256 best = e;
255257 }
258+
259+ if (best.num) {
260+ if (best_of_best.num) {
261+ // If best (without replacements) is not worse, but is actually
262+ // better with replacements applied, pick it.
263+ int bbest_lost = mp_chmap_diffn(map, &best_of_best);
264+ int best_lost = mp_chmap_diffn(map, &best);
265+ int repl_lost = mp_chmap_diffn(&t, &best);
266+ if (best_lost <= bbest_lost && repl_lost < bbest_lost)
267+ best_of_best = best;
268+ } else {
269+ best_of_best = best;
270+ }
271+ }
256272 }
257273
258− if (best.num) {
259− *map = best;
274+ if (best_of_best.num) {
275+ *map = best_of_best;
260276 return true;
261277 }
262278
test/chmap_sel.c+15−0
@@ -87,6 +87,20 @@ static void test_mp_chmap_sel_fallback_reject_unknown(void **state) { · 86 unmodified lines
8787 assert_string_equal(mp_chmap_to_str(&b), "5.1");
8888 }
8989
90+static void test_mp_chmap_sel_fallback_more_replacements(void **state) {
91+ test_sel("quad", "quad(side)", LAYOUTS("quad(side)", "stereo"));
92+ test_sel("quad", "7.0", LAYOUTS("quad(side)", "7.0"));
93+ test_sel("quad", "7.0", LAYOUTS("7.0", "quad(side)"));
94+ test_sel("quad", "7.1(wide-side)", LAYOUTS("7.1(wide-side)", "stereo"));
95+ test_sel("quad", "7.1(wide-side)", LAYOUTS("stereo", "7.1(wide-side)"));
96+ test_sel("quad", "fl-fr-fc-bl-br",
97+ LAYOUTS("fl-fr-fc-bl-br", "fl-fr-sl-sr"));
98+ test_sel("quad", "fl-fr-bl-br-na-na-na-na",
99+ LAYOUTS("fl-fr-bl-br-na-na-na-na", "quad(side)", "stereo"));
100+ test_sel("quad", "fl-fr-bl-br-na-na-na-na",
101+ LAYOUTS("stereo", "quad(side)", "fl-fr-bl-br-na-na-na-na"));
102+}
103+
90104 int main(void) {
91105 const UnitTest tests[] = {
92106 unit_test(test_mp_chmap_sel_fallback_upmix),
@@ -101,6 +115,7 @@ int main(void) { · 8 unmodified lines
101115 unit_test(test_mp_chmap_sel_fallback_no_downmix),
102116 unit_test(test_mp_chmap_sel_fallback_minimal_downmix),
103117 unit_test(test_mp_chmap_sel_fallback_reject_unknown),
118+ unit_test(test_mp_chmap_sel_fallback_more_replacements),
104119 };
105120 return run_tests(tests);
106121 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t