[pulseaudio-discuss] [PATCH RFCv3 36/51] sample-util: Add inlineable functions

Peter Meerwald pmeerw at pmeerw.net
Tue Nov 4 15:26:31 PST 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

duplicating similar functionality in sample.h but inlineable and
without validity checks:
PA_FRAME_SIZE(), PA_BYTES_PER_SECOND(), PA_BYTES_TO_USEC(), PA_USEC_TO_BYTES()

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/sample-util.h | 53 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/src/pulsecore/sample-util.h b/src/pulsecore/sample-util.h
index 7e7fb92..e892012 100644
--- a/src/pulsecore/sample-util.h
+++ b/src/pulsecore/sample-util.h
@@ -30,6 +30,7 @@
 #include <pulse/sample.h>
 #include <pulse/volume.h>
 #include <pulse/channelmap.h>
+#include <pulse/timeval.h>
 
 #include <pulsecore/memblock.h>
 #include <pulsecore/memchunk.h>
@@ -56,6 +57,35 @@ 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);
 
+extern const size_t pa_sample_size_table[];
+static inline size_t PA_FRAME_SIZE(const pa_sample_spec *spec) {
+    pa_assert_fp(spec);
+    pa_assert_fp(pa_sample_spec_valid(spec));
+
+    return pa_sample_size_table[spec->format] * spec->channels;
+}
+
+static inline size_t PA_BYTES_PER_SECOND(const pa_sample_spec *spec) {
+    pa_assert_fp(spec);
+    pa_assert_fp(pa_sample_spec_valid(spec));
+
+    return spec->rate * pa_sample_size_table[spec->format] * spec->channels;
+}
+
+static inline pa_usec_t PA_BYTES_TO_USEC(uint64_t length, const pa_sample_spec *spec) {
+    pa_assert_fp(spec);
+    pa_assert_fp(pa_sample_spec_valid(spec));
+
+    return (((pa_usec_t) (length / PA_FRAME_SIZE(spec)) * PA_USEC_PER_SEC) / spec->rate);
+}
+
+static inline size_t PA_USEC_TO_BYTES(pa_usec_t t, const pa_sample_spec *spec) {
+    pa_assert_fp(spec);
+    pa_assert_fp(pa_sample_spec_valid(spec));
+
+    return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * PA_FRAME_SIZE(spec);
+}
+
 static inline int32_t pa_mult_s16_volume(int16_t v, int32_t cv) {
 #if __WORDSIZE == 64 || ((ULONG_MAX) > (UINT_MAX))
     /* Multiply with 64 bit integers on 64 bit platforms */
@@ -145,4 +175,27 @@ size_t pa_convert_size(size_t size, const pa_sample_spec *from, const pa_sample_
 #define PA_CHANNEL_POSITION_MASK_ALL            \
     ((pa_channel_position_mask_t) (PA_CHANNEL_POSITION_MASK(PA_CHANNEL_POSITION_MAX)-1))
 
+static inline int PA_CHANNEL_MAP_EQUAL(const pa_channel_map *a, const pa_channel_map *b) {
+    unsigned c;
+
+    pa_assert_fp(a);
+    pa_assert_fp(b);
+
+    pa_assert_fp(pa_channel_map_valid(a));
+
+    if (PA_UNLIKELY(a == b))
+        return 1;
+
+    pa_assert_fp(pa_channel_map_valid(b));
+
+    if (a->channels != b->channels)
+        return 0;
+
+    for (c = 0; c < a->channels; c++)
+        if (a->map[c] != b->map[c])
+            return 0;
+
+    return 1;
+}
+
 #endif
-- 
1.9.1



More information about the pulseaudio-discuss mailing list