summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-08 21:22:39 +0200
committerwm4 <wm4@nowhere>2015-05-08 21:22:39 +0200
commit00130651dac758f90bf98306a9d1e569ed4155ca (patch)
tree43e58cd511d0db7f1f312d1befe7562a6c283ab6 /audio
parent8d5924f2c9c7d80b45cd68b44cb9c74e7b0b5a8c (diff)
downloadmpv-00130651dac758f90bf98306a9d1e569ed4155ca.tar.bz2
mpv-00130651dac758f90bf98306a9d1e569ed4155ca.tar.xz
audio: simplify further
Drop mp_chmap_diff() (which is unused too now), and implement mp_chmap_diffn() in a slightly simpler way. (Too bad there is no standard function for counting set bits.)
Diffstat (limited to 'audio')
-rw-r--r--audio/chmap.c22
-rw-r--r--audio/chmap.h2
2 files changed, 8 insertions, 16 deletions
diff --git a/audio/chmap.c b/audio/chmap.c
index 4f76eedd59..4fd43e3bc7 100644
--- a/audio/chmap.c
+++ b/audio/chmap.c
@@ -395,26 +395,20 @@ void mp_chmap_get_reorder(int src[MP_NUM_CHANNELS], const struct mp_chmap *from,
assert(src[n] < 0 || (to->speaker[n] == from->speaker[src[n]]));
}
-// Return channels that are only in a.
-// Performs the difference between a and b, and store it in diff. If b has
-// channels that do not appear in a, those will not appear in the difference.
-// To get to those the argument ordering in the function call has to be
-// inverted. For the same reason, the diff with a superset will return no
-// speakers.
-void mp_chmap_diff(const struct mp_chmap *a, const struct mp_chmap *b,
- struct mp_chmap *diff)
+static int popcount64(uint64_t bits)
{
- uint64_t a_mask = mp_chmap_to_lavc_unchecked(a);
- uint64_t b_mask = mp_chmap_to_lavc_unchecked(b);
- mp_chmap_from_lavc(diff, (a_mask ^ b_mask) & a_mask);
+ int r = 0;
+ for (int n = 0; n < 64; n++)
+ r += !!(bits & (1ULL << n));
+ return r;
}
// Return the number of channels only in a.
int mp_chmap_diffn(const struct mp_chmap *a, const struct mp_chmap *b)
{
- struct mp_chmap diff;
- mp_chmap_diff(a, b, &diff);
- return diff.num;
+ uint64_t a_mask = mp_chmap_to_lavc_unchecked(a);
+ uint64_t b_mask = mp_chmap_to_lavc_unchecked(b);
+ return popcount64((a_mask ^ b_mask) & a_mask);
}
// Returns something like "fl-fr-fc". If there's a standard layout in lavc
diff --git a/audio/chmap.h b/audio/chmap.h
index c3826065ce..adb7481665 100644
--- a/audio/chmap.h
+++ b/audio/chmap.h
@@ -123,8 +123,6 @@ void mp_chmap_reorder_to_lavc(struct mp_chmap *map);
void mp_chmap_get_reorder(int src[MP_NUM_CHANNELS], const struct mp_chmap *from,
const struct mp_chmap *to);
-void mp_chmap_diff(const struct mp_chmap *a, const struct mp_chmap *b,
- struct mp_chmap *diff);
int mp_chmap_diffn(const struct mp_chmap *a, const struct mp_chmap *b);
char *mp_chmap_to_str_buf(char *buf, size_t buf_size, const struct mp_chmap *src);