-typedef struct
-{
- int16_t *buffer;
- int size;
- int used;
- pthread_mutex_t mutex;
-} *sample_fifo;
-
-static sample_fifo sample_fifo_init()
-{
- sample_fifo fifo = (sample_fifo) calloc( 1, sizeof( *fifo ) );
- pthread_mutex_init( &fifo->mutex, NULL );
- return fifo;
-}
-
-static void sample_fifo_append( sample_fifo fifo, int16_t *samples, int count )
-{
- pthread_mutex_lock( &fifo->mutex );
- if ( ( fifo->size - fifo->used ) < count )
- {
- fifo->size += count * 5;
- fifo->buffer = (int16_t*) realloc( fifo->buffer, fifo->size * sizeof( int16_t ) );
- }
- memcpy( fifo->buffer + fifo->used, samples, count * sizeof( int16_t ) );
- fifo->used += count;
- pthread_mutex_unlock( &fifo->mutex );
-}
-
-static void sample_fifo_remove( sample_fifo fifo, int count )
-{
- pthread_mutex_lock( &fifo->mutex );
- if ( count > fifo->used )
- count = fifo->used;
- fifo->used -= count;
- memmove( fifo->buffer, fifo->buffer + count, fifo->used * sizeof( int16_t ) );
- pthread_mutex_unlock( &fifo->mutex );
-}
-
-static void sample_fifo_close( sample_fifo fifo )
-{
- free( fifo->buffer );
- pthread_mutex_destroy( &fifo->mutex );
- free( fifo );
-}
-
-