#include <pipe.h>
This class defines the implementation of the FIFO (first in, first out) buffered threadsafe pipe. This component is massively used in MuSE's flow of audio data, connecting the Channel to the Stream_mixer and then to the OutChannel.
This Pipe implementation is fairly well tested and optimized, usesu pthread mutexes for fast atomical locking and has a mixing routine embedded for for reading data from the pipe.
When an application locks the Pipe, will be waiting until it reaches to gain the lock, then will (pthread_mutex_lock)
This pipe is never blocking, meaning that it never makes the calling process wait for result. The Pipe::blocking attribute of this class has to be intended in a different way.
Blocking means that the Pipe::read, Pipe::write and derivative functions will be returning -1 without moving any data, in case the aumount of data requested don't fit for pipe buffers.
Non-blocking means that the Pipe::read, Pipe::write and derivative functions will move all the data they can move, even if less than requested, and then return the amount of data moved.
I know, the above might sound weird, just because i used the word 'blocking' where i shouldn't. i beg your pardon and plan to change it in future.
Definition at line 70 of file pipe.h.
Public Member Functions | |
Pipe (int size=16384) | |
Pipe constructor class. | |
~Pipe () | |
Pipe destructor class. | |
int | read (int length, void *data) |
read from the pipe | |
int | read_float_intl (int samples, float *buf, int channels) |
read from FIFO pipe in a float stereo interpolated l/r array | |
int | read_float_bidi (int samples, float **buf, int channels) |
read from the pipe into a bidimensional float array | |
int | mix16stereo (int samples, int32_t *mix) |
Mix audio from FIFO pipe into a mixing buffer. | |
int | write (int length, void *data) |
write into FIFO pipe | |
void | block (bool val) |
Setup blocking behaviour of the Pipe. | |
int | size () |
tell the amount of data contained in the Pipe | |
int | space () |
tell the amount of free space in the Pipe | |
void | flush () |
flush all data contained in the Pipe, loosing it | |
void | flush (int size) |
flush a certain amount of bytes from FIFO Pipe | |
Public Attributes | |
bool | blocking |
|
Pipe constructor class. The constructor initializes all buffers needed, which will be in fact the size of the buffer |
|
Setup blocking behaviour of the Pipe. The term 'blocking' here is used in a quite improper way, read more about in the description of the Pipe class. |
|
Mix audio from FIFO pipe into a mixing buffer. Mixes the audio in the pipe into a given audio buffer. Assumes that the audio buffered is 16bit stereo. This implements the core mixing routine used in Stream_mixer::cafudda.
|
|
read from the pipe Reads out audio data from the pipe filling up the given buffer which has to be properly allocated. If the pipe is set 'blocking' then will return -1 if the pipe buffer is full. Otherwise, when non-blocking, will return the amount of data that could be pushed in the pipe.
|
|
read from the pipe into a bidimensional float array Read from FIFO pipe in a float bidimensional array. It is convenient to read float data for float routines, this one reads into a bidimensional buffer. TAKE CARE THIS FUNCTION IS NOT WELL TESTED i never use it in MuSE i just did it together with the _intl |
|
read from FIFO pipe in a float stereo interpolated l/r array This function is used to read from the pipe directly into a stereo interpolated float audio buffer, which is the ideal input for the secret rabbit code resampler.
|
|
tell the amount of data contained in the Pipe
|
|
tell the amount of free space in the Pipe
|
|
write into FIFO pipe Write data inside the FIFO pipe, locking to not overlap read operations (thread safe).
|