Async 1.8.0
Async::AudioFifo Class Reference

A FIFO class for handling audio samples. More...

#include <AsyncAudioFifo.h>

Inheritance diagram for Async::AudioFifo:
Async::AudioSink Async::AudioSource

Public Member Functions

 AudioFifo (unsigned fifo_size)
 Constuctor.
 
virtual ~AudioFifo (void)
 Destructor.
 
void setSize (unsigned new_size)
 Set the size of the FIFO.
 
bool empty (void) const
 Check if the FIFO is empty.
 
bool full (void) const
 Check if the FIFO is full.
 
unsigned samplesInFifo (bool ignore_prebuf=false) const
 Find out how many samples there are in the FIFO.
 
void setOverwrite (bool overwrite)
 Set the overwrite mode.
 
bool overwrite (void) const
 Check the overwrite mode.
 
void clear (void)
 Clear all samples from the FIFO.
 
void setPrebufSamples (unsigned prebuf_samples)
 Set the number of samples that must be in the fifo before any samples are written out from it.
 
void enableBuffering (bool enable)
 Enable/disable the fifo buffer.
 
bool bufferingEnabled (void) const
 Check if buffering is enabled or disabled.
 
virtual int writeSamples (const float *samples, int count)
 Write samples into the FIFO.
 
virtual void flushSamples (void)
 Tell the FIFO to flush the previously written samples.
 
virtual void resumeOutput (void)
 Resume audio output to the connected sink.
 
- Public Member Functions inherited from Async::AudioSink
 AudioSink (void)
 Default constuctor.
 
virtual ~AudioSink (void)
 Destructor.
 
bool registerSource (AudioSource *source)
 Register an audio source to provide samples to this sink.
 
void unregisterSource (void)
 Unregister the previously registered audio source.
 
bool isRegistered (void) const
 Check if an audio source has been registered.
 
AudioSourcesource (void) const
 Get the registered audio source.
 
- Public Member Functions inherited from Async::AudioSource
 AudioSource (void)
 Default constuctor.
 
virtual ~AudioSource (void)
 Destructor.
 
bool registerSink (AudioSink *sink, bool managed=false)
 Register an audio sink to provide samples to.
 
void unregisterSink (void)
 Unregister the previously registered audio sink.
 
bool isRegistered (void) const
 Check if an audio sink has been registered.
 
AudioSinksink (void) const
 Get the registered audio sink.
 
bool sinkManaged (void) const
 Check if the sink is managed or not.
 
void handleAllSamplesFlushed (void)
 The registered sink has flushed all samples.
 

Protected Member Functions

virtual void allSamplesFlushed (void)
 The registered sink has flushed all samples.
 
- Protected Member Functions inherited from Async::AudioSink
void sourceResumeOutput (void)
 Tell the source that we are ready to accept more samples.
 
void sourceAllSamplesFlushed (void)
 Tell the source that all samples have been flushed.
 
bool setHandler (AudioSink *handler)
 Setup another sink to handle the incoming audio.
 
void clearHandler (void)
 Clear a handler that was previously setup with setHandler.
 
AudioSinkhandler (void) const
 
- Protected Member Functions inherited from Async::AudioSource
int sinkWriteSamples (const float *samples, int len)
 
void sinkFlushSamples (void)
 
bool setHandler (AudioSource *handler)
 Setup another source to handle the outgoing audio.
 
AudioSourcehandler (void) const
 
void clearHandler (void)
 Clear a handler that was previously setup with setHandler.
 

Detailed Description

A FIFO class for handling audio samples.

Author
Tobias Blomberg / SM0SVX
Date
2007-10-06

This class implements a FIFO for handling audio samples. The FIFO also have some additional features. Output can be started or stopped and it can be instructed to buffer some samples before starting to output audio. Samples can be automatically output using the normal audio pipe infrastructure or samples could be read on demand using the readSamples method.

Definition at line 119 of file AsyncAudioFifo.h.

Constructor & Destructor Documentation

◆ AudioFifo()

Async::AudioFifo::AudioFifo ( unsigned fifo_size)
explicit

Constuctor.

Parameters
fifo_sizeThis is the size of the fifo expressed in number of samples.

◆ ~AudioFifo()

virtual Async::AudioFifo::~AudioFifo ( void )
virtual

Destructor.

Member Function Documentation

◆ allSamplesFlushed()

virtual void Async::AudioFifo::allSamplesFlushed ( void )
protectedvirtual

The registered sink has flushed all samples.

This function will be called when all samples have been flushed in the registered sink. This function is normally only called from a connected sink object.

Reimplemented from Async::AudioSource.

◆ bufferingEnabled()

bool Async::AudioFifo::bufferingEnabled ( void ) const
inline

Check if buffering is enabled or disabled.

Returns
Returns true if buffering is enabled or else false

Definition at line 227 of file AsyncAudioFifo.h.

◆ clear()

void Async::AudioFifo::clear ( void )

Clear all samples from the FIFO.

This will immediately reset the FIFO and discard all samples. The source will be told that all samples have been flushed.

◆ empty()

bool Async::AudioFifo::empty ( void ) const
inline

Check if the FIFO is empty.

Returns
Returns true if the FIFO is empty or else false

Definition at line 148 of file AsyncAudioFifo.h.

◆ enableBuffering()

void Async::AudioFifo::enableBuffering ( bool enable)

Enable/disable the fifo buffer.

Parameters
enableSet to true to enable buffering or else false

Use this method to turn buffering on and off. When buffering is off, no incoming samples will be stored in the fifo. If there are samples in the fifo at the time when buffering is disabled they will be sent out in the normal way. Don't disable buffering when pre-buffering is used. This will get you into trouble.

◆ flushSamples()

virtual void Async::AudioFifo::flushSamples ( void )
virtual

Tell the FIFO to flush the previously written samples.

This function is used to tell the FIFO to flush previously written samples. This function is normally only called from a connected source object.

Reimplemented from Async::AudioSink.

◆ full()

bool Async::AudioFifo::full ( void ) const
inline

Check if the FIFO is full.

Returns
Returns true if the FIFO is full or else false

This function is used to check if the FIFO is full or not. The FIFO can only reach the buffer full condition if overwrite is false. The overwrite mode is set by the setOverwrite function.

Definition at line 158 of file AsyncAudioFifo.h.

◆ overwrite()

bool Async::AudioFifo::overwrite ( void ) const
inline

Check the overwrite mode.

Returns
Returns true if overwrite is enabled or else false

The FIFO can operate in overwrite or normal mode. When in normal mode, it will not be possible to add any more samples to the FIFO when it is full. Samples has to be removed first. When overwrite is set, newly added samples will overwrite the oldest samples in the buffer so the FIFO will never get full but instead samples are lost. Use this function the check the current overwrite mode. Use the setOverwrite function to set the overwrite mode.

Definition at line 193 of file AsyncAudioFifo.h.

Referenced by setOverwrite().

◆ resumeOutput()

virtual void Async::AudioFifo::resumeOutput ( void )
virtual

Resume audio output to the connected sink.

This function will be called when the registered audio sink is ready to accept more samples. This function is normally only called from a connected sink object.

Reimplemented from Async::AudioSource.

◆ samplesInFifo()

unsigned Async::AudioFifo::samplesInFifo ( bool ignore_prebuf = false) const

Find out how many samples there are in the FIFO.

Parameters
ignore_prebufSet to true to not report pre-buffered samples.
Returns
Returns the number of samples in the FIFO

◆ setOverwrite()

void Async::AudioFifo::setOverwrite ( bool overwrite)
inline

Set the overwrite mode.

Parameters
overwriteSet to true to overwrite or else false

The FIFO can operate in overwrite or normal mode. When in normal mode, it will not be possible to add any more samples to the FIFO when it is full. Samples has to be removed first. When overwrite is set, newly added samples will overwrite the oldest samples in the buffer so the FIFO will never get full but instead samples are lost. Use this function to set the overwrite mode.

Definition at line 179 of file AsyncAudioFifo.h.

References overwrite().

◆ setPrebufSamples()

void Async::AudioFifo::setPrebufSamples ( unsigned prebuf_samples)

Set the number of samples that must be in the fifo before any samples are written out from it.

Parameters
prebuf_samplesThe number of samples

◆ setSize()

void Async::AudioFifo::setSize ( unsigned new_size)

Set the size of the FIFO.

Parameters
new_sizeThis is the size of the fifo expressed in number of samples.

Use this function to set the size of the FIFO. In doing this, the FIFO will also be cleared.

◆ writeSamples()

virtual int Async::AudioFifo::writeSamples ( const float * samples,
int count )
virtual

Write samples into the FIFO.

Parameters
samplesThe buffer containing the samples
countThe number of samples in the buffer
Returns
Returns the number of samples that has been taken care of

This function is used to write audio into the FIFO. If it returns 0, no more samples should be written until the resumeOutput function in the source have been called. This function is normally only called from a connected source object.

Reimplemented from Async::AudioSink.


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