summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-10-22 21:48:16 +0000
committerLennart Poettering <lennart@poettering.net>2007-10-22 21:48:16 +0000
commit925eadd9e209da3bfcfef5d06ae324fa4966ecb5 (patch)
treef87cfb159c943aa3b4938b0e7ce56223455494a9
parent190081782c4f3a45b641d2dcda2337a396677684 (diff)
add interleaving/deinterleaving APIs
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1942 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/pulsecore/sample-util.c57
-rw-r--r--src/pulsecore/sample-util.h3
2 files changed, 60 insertions, 0 deletions
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index 56d89c8c..21771302 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <liboil/liboilfuncs.h>
+#include <liboil/liboil.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
@@ -485,3 +486,59 @@ int pa_frame_aligned(size_t l, const pa_sample_spec *ss) {
return l % fs == 0;
}
+
+void pa_interleave(const void *src[], unsigned channels, void *dst, size_t ss, unsigned n) {
+ unsigned c;
+ size_t fs;
+
+ pa_assert(src);
+ pa_assert(channels > 0);
+ pa_assert(dst);
+ pa_assert(ss > 0);
+ pa_assert(n > 0);
+
+ fs = ss * channels;
+
+ for (c = 0; c < channels; c++) {
+ unsigned j;
+ void *d;
+ const void *s;
+
+ s = src[c];
+ d = (uint8_t*) dst + c * ss;
+
+ for (j = 0; j < n; j ++) {
+ oil_memcpy(d, s, ss);
+ s = (uint8_t*) s + ss;
+ d = (uint8_t*) d + fs;
+ }
+ }
+}
+
+void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss, unsigned n) {
+ size_t fs;
+ unsigned c;
+
+ pa_assert(src);
+ pa_assert(dst);
+ pa_assert(channels > 0);
+ pa_assert(ss > 0);
+ pa_assert(n > 0);
+
+ fs = ss * channels;
+
+ for (c = 0; c < channels; c++) {
+ unsigned j;
+ const void *s;
+ void *d;
+
+ s = (uint8_t*) src + c * ss;
+ d = dst[c];
+
+ for (j = 0; j < n; j ++) {
+ oil_memcpy(d, s, ss);
+ s = (uint8_t*) s + fs;
+ d = (uint8_t*) d + ss;
+ }
+ }
+}
diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h
index 92c6e9ff..0a39d5ca 100644
--- a/src/pulsecore/sample-util.h
+++ b/src/pulsecore/sample-util.h
@@ -60,4 +60,7 @@ size_t pa_frame_align(size_t l, const pa_sample_spec *ss) PA_GCC_PURE;
int pa_frame_aligned(size_t l, const pa_sample_spec *ss) PA_GCC_PURE;
+void pa_interleave(const void *src[], unsigned channels, void *dst, size_t ss, unsigned n);
+void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss, unsigned n);
+
#endif