aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-ringbuf.c
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 12:25:22 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-07-20 12:25:22 +0200
commit712b3a2cda69422931b26283054e476e3d554a06 (patch)
tree108906755159da8c87c8d4d3fa0871b134c4c35d /plugins/alsa/alsa-ringbuf.c
parentafc7d62d02c523f3d3adc29f713f5a4395ca3f58 (diff)
added ringbuffer and time utils
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-ringbuf.c')
-rw-r--r--plugins/alsa/alsa-ringbuf.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/plugins/alsa/alsa-ringbuf.c b/plugins/alsa/alsa-ringbuf.c
new file mode 100644
index 0000000..2d77e4c
--- /dev/null
+++ b/plugins/alsa/alsa-ringbuf.c
@@ -0,0 +1,50 @@
+#include "alsa-ringbuf.h"
+
+alsa_ringbuf_t * alsa_ringbuf_new(snd_pcm_uframes_t capacity, size_t frameSize) {
+ alsa_ringbuf_t * rb = malloc(sizeof(alsa_ringbuf_t));
+
+ rb->rbuf = ringbuf_new(capacity*frameSize);
+ rb->frameSize = frameSize;
+ return rb;
+}
+
+snd_pcm_uframes_t alsa_ringbuf_buffer_size(const alsa_ringbuf_t *rb) {
+ return ringbuf_buffer_size(rb->rbuf)/rb->frameSize;
+}
+
+void alsa_ringbuf_free(alsa_ringbuf_t *rb) {
+ ringbuf_free(&rb->rbuf);
+ free(rb);
+}
+
+void alsa_ringbuf_reset(alsa_ringbuf_t * rb) {
+ ringbuf_reset(rb->rbuf);
+}
+
+snd_pcm_uframes_t alsa_ringbuf_capacity(const alsa_ringbuf_t *rb) {
+ return ringbuf_capacity(rb->rbuf)/rb->frameSize;
+}
+
+snd_pcm_uframes_t alsa_ringbuf_frames_free(const alsa_ringbuf_t *rb) {
+ return ringbuf_bytes_free(rb->rbuf)/rb->frameSize;
+}
+
+snd_pcm_uframes_t alsa_ringbuf_frames_used(const alsa_ringbuf_t *rb) {
+ return ringbuf_bytes_used(rb->rbuf)/rb->frameSize;
+}
+
+bool alsa_ringbuf_is_full(const alsa_ringbuf_t *rb) {
+ return ringbuf_is_full(rb->rbuf)==1;
+}
+
+bool alsa_ringbuf_is_empty(const alsa_ringbuf_t *rb) {
+ return ringbuf_is_empty(rb->rbuf)==1;
+}
+
+void alsa_ringbuf_frames_push(alsa_ringbuf_t * rb, const void * src, snd_pcm_uframes_t nb) {
+ ringbuf_memcpy_into(rb->rbuf, src, nb*rb->frameSize);
+}
+
+void alsa_ringbuf_frames_pop(alsa_ringbuf_t * rb, void * dst, snd_pcm_uframes_t nb) {
+ ringbuf_memcpy_from(dst, rb->rbuf, nb*rb->frameSize);
+}