aboutsummaryrefslogtreecommitdiff
path: root/FifoAudioFrames.cpp
diff options
context:
space:
mode:
authorN.N <matju@users.sourceforge.net>2009-12-14 19:55:54 +0000
committerIOhannes m zmölnig <zmoelnig@iem.at>2015-10-14 15:04:53 +0200
commitc235f09fc5ef83827ac53375015f469cd7e13eec (patch)
tree4639e88e27e105709a2bbd6352cec17808fdc5c9 /FifoAudioFrames.cpp
parent40194041a1efbf98c45185098e3795150a0128a4 (diff)
import version 0.36
svn path=/trunk/externals/august/readanysf~/; revision=12836
Diffstat (limited to 'FifoAudioFrames.cpp')
-rw-r--r--FifoAudioFrames.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/FifoAudioFrames.cpp b/FifoAudioFrames.cpp
new file mode 100644
index 0000000..8209ab1
--- /dev/null
+++ b/FifoAudioFrames.cpp
@@ -0,0 +1,132 @@
+#include "FifoAudioFrames.h"
+
+/*
+#define RESET 0
+#define BRIGHT 1
+#define DIM 2
+#define UNDERLINE 3
+#define BLINK 4
+#define REVERSE 7
+#define HIDDEN 8
+
+#define BLACK 0
+#define RED 1
+#define GREEN 2
+#define YELLOW 3
+#define BLUE 4
+#define MAGENTA 5
+#define CYAN 6
+#define WHITE 7
+void textcolor(int attr, int fg, int bg) {
+ char command[13];
+ // Command is the control command to the terminal
+ sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
+ printf("%s", command);
+}
+*/
+
+
+Fifo::Fifo(int s, gavl_audio_format_t * f) {
+ size = s ;
+ start = 0 ;
+ end = 0 ;
+ count = 0;
+ format = new gavl_audio_format_t;
+ gavl_audio_format_copy(format, f);
+ fifoPtr = new gavl_audio_frame_t * [size] ;
+ for(int i=0; i < size; i++) {
+ fifoPtr[i] = gavl_audio_frame_create( format );
+ }
+ pthread_mutex_init (&mut, 0);
+ //printf("Fifo::size=%d\n", size);
+}
+
+Fifo::~Fifo() {
+ //printf("deleting fifo \n");
+ for(int i=0; i < size; i++) {
+ gavl_audio_frame_destroy( fifoPtr[i] );
+ }
+ delete format;
+ delete[] fifoPtr;
+
+ //printf("deleted fifo \n");
+}
+
+// empty the fifo of any content
+void Fifo::Flush() {
+ pthread_mutex_lock (&mut);
+ start = 0 ;
+ end = 0 ;
+ count = 0;
+ //printf("Fifo::flushed size=%d\n", count);
+ pthread_mutex_unlock (&mut);
+}
+
+// push an element onto the Fifo
+bool Fifo::Append( gavl_audio_frame_t * source) {
+ bool ret = false;
+ //Dump("Appending a frame ");
+ pthread_mutex_lock (&mut);
+ if ( count < size ) { // if there is room for one more
+ int vs = gavl_audio_frame_copy(format, fifoPtr[end], source, 0,0, format->samples_per_frame, format->samples_per_frame) ;
+ fifoPtr[end]->timestamp = source->timestamp;
+ fifoPtr[end]->valid_samples =vs;
+ if (++end >= size)
+ end = 0;
+ count++;
+ ret = true;
+ } // no room in fifo, return false
+ pthread_mutex_unlock (&mut);
+ //Dump("Appended a frame ");
+ return ret;
+}
+
+// get an element off the Fifo
+bool Fifo::Get( gavl_audio_frame_t * dest) {
+ bool ret = false;
+ //Dump("Getting a frame ");
+ pthread_mutex_lock (&mut);
+ if ( count > 0 ) { // if there any items in the fifo
+ int vs = gavl_audio_frame_copy(format, dest, fifoPtr[start], 0, 0, format->samples_per_frame, format->samples_per_frame) ;
+ dest->timestamp = fifoPtr[start]->timestamp;
+ dest->valid_samples = vs;
+ if ( ++start >= size )
+ start = 0;
+ count--;
+ ret = true;
+ }
+ pthread_mutex_unlock (&mut);
+ //Dump("Got a frame ");
+ return ret;
+}
+/*
+void Fifo::Dump( char * c) {
+ int i,j = 0;
+ pthread_mutex_lock (&mut);
+ printf("%s -----------------------\n", c);
+ for( i=0;i<size;i++) {
+ //j=start+i;
+ //if (j >= size)
+ // j = j -size;
+ j=i;
+ if ( j == start)
+ textcolor(BRIGHT, GREEN, BLACK);
+ if (j == end)
+ textcolor(BRIGHT, RED, BLACK);
+ if (j == end && j == start)
+ textcolor(BRIGHT, YELLOW, BLACK);
+ printf("[%d]=%ld ", j, fifoPtr[j]->timestamp);
+ textcolor(RESET, BLACK, WHITE);
+ }
+ printf("\n");
+ printf("start=%02d, end=%02d, count=%02d\n", start,end,count);
+ printf("-----------------------\n");
+ pthread_mutex_unlock (&mut);
+}
+*/
+bool Fifo::FreeSpace() { bool ret; pthread_mutex_lock(&mut); ret = (count < size);pthread_mutex_unlock (&mut); return ret;}
+bool Fifo::isEmpty() { bool c; pthread_mutex_lock(&mut); c = (count == 0) ; pthread_mutex_unlock (&mut); return c; }
+bool Fifo::isFull() { bool c; pthread_mutex_lock(&mut); c = (count == size ); pthread_mutex_unlock (&mut); return c; }
+gavl_audio_format_t * Fifo::getFormat() { return format; };
+float Fifo::getSizePercentage() { float ret; pthread_mutex_lock(&mut);ret = count / (float) size; pthread_mutex_unlock (&mut); return ret;};
+