Main Page Modules Class Hierarchy Compound List File List Compound Members File Members

# Pipe Class Reference

`#include <pipe.h>`

List of all members.

## Detailed Description

fast buffered threadsafe FIFO pipe

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

## Constructor & Destructor Documentation

Pipe::Pipe | ( | int | size = 16384 | ) |

| Pipe constructor class. The constructor initializes all buffers needed, which will be in fact the size of the buffer Definition at line 53 of file pipe.cpp.

## Member Function Documentation

void Pipe::block | ( | bool | val | ) |

| 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. Definition at line 269 of file pipe.cpp.

int Pipe::mix16stereo | ( | int | samples,
|  | int32_t * | mix
| ) |

  | 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. Parameters:
  samples | number of samples to be mixed (1= l&r 16bit)
  mix | 32bit integer mixing buffer
Returns: amount of samples mixed Definition at line 276 of file pipe.cpp.

int Pipe::read | ( | int | length,
|  | void * | data
| ) |

  | 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. Parameters:
  length | amount of data to be read in bytes
  data | buffer pointer where to read data, must be allocated allready
Returns: amount of data read, or -1 on error, if Pipe::blocking is true Definition at line 339 of file pipe.cpp.

int Pipe::read_float_bidi | ( | int | samples,
|  | float ** | buf,
|  | int | channels
| ) |

| 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 Definition at line 169 of file pipe.cpp.

int Pipe::read_float_intl | ( | int | samples,
|  | float * | buf,
|  | int | channels
| ) |

  | 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. Parameters:
  samples | amount of data to be read in samples (1= l&r float)
  buf | float buffer to be filled, must be allocated allready
  channels | number of channels (1=mono, 2=stereo)
Definition at line 76 of file pipe.cpp.

int Pipe::size | ( |  | ) |

| tell the amount of data contained in the Pipe Returns: amount in bytes Definition at line 446 of file pipe.cpp.

int Pipe::space | ( |  | ) |

| tell the amount of free space in the Pipe Returns: amount in bytes Definition at line 456 of file pipe.cpp.

int Pipe::write | ( | int | length,
|  | void * | data
| ) |

  | write into FIFO pipe Write data inside the FIFO pipe, locking to not overlap read operations (thread safe). Parameters:
  length | amount of bytes of data to be written
  data | buffer from where to take the data to be written
Returns: when Pipe::blocking is set, this functions returns -1, otherwise the amount of data written. Definition at line 396 of file pipe.cpp.

The documentation for this class was generated from the following files:

- pipe.h
- pipe.cpp