summaryrefslogtreecommitdiffstats
path: root/src/pulsecore
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-08-28 17:53:01 +0200
committerLennart Poettering <lennart@poettering.net>2008-08-28 17:53:01 +0200
commitbb8263be6fbbb227989e8cb4f5dc7dc67216724d (patch)
tree4b5ac0c0714ac1d36db09ac8895b32a1061209d5 /src/pulsecore
parentf79c66581292fc76160e29c7e713354cb8037270 (diff)
add byte-to-usec and usec-to-byte converters that round up, not down
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/sample-util.c33
-rw-r--r--src/pulsecore/sample-util.h3
2 files changed, 36 insertions, 0 deletions
diff --git a/src/pulsecore/sample-util.c b/src/pulsecore/sample-util.c
index 4b2efe5e..b4234af5 100644
--- a/src/pulsecore/sample-util.c
+++ b/src/pulsecore/sample-util.c
@@ -31,6 +31,8 @@
#include <liboil/liboilfuncs.h>
#include <liboil/liboil.h>
+#include <pulse/timeval.h>
+
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/g711.h>
@@ -981,3 +983,34 @@ void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const vo
}
}
}
+
+/* Similar to pa_bytes_to_usec() but rounds up, not down */
+
+pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec) {
+ size_t fs;
+ pa_usec_t usec;
+
+ pa_assert(spec);
+
+ fs = pa_frame_size(spec);
+ length = (length + fs - 1) / fs;
+
+ usec = (pa_usec_t) length * PA_USEC_PER_SEC;
+
+ return (usec + spec->rate - 1) / spec->rate;
+}
+
+/* Similar to pa_usec_to_bytes() but rounds up, not down */
+
+size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec) {
+ uint64_t u;
+ pa_assert(spec);
+
+ u = (uint64_t) t * (uint64_t) spec->rate;
+
+ u = (u + PA_USEC_PER_SEC - 1) / PA_USEC_PER_SEC;
+
+ u *= pa_frame_size(spec);
+
+ return (size_t) u;
+}
diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h
index cef70750..06ecb724 100644
--- a/src/pulsecore/sample-util.h
+++ b/src/pulsecore/sample-util.h
@@ -78,4 +78,7 @@ void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss,
void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const void *src, size_t sstr, unsigned n);
+pa_usec_t pa_bytes_to_usec_round_up(uint64_t length, const pa_sample_spec *spec);
+size_t pa_usec_to_bytes_round_up(pa_usec_t t, const pa_sample_spec *spec);
+
#endif