Async 1.8.0
Async::AudioThreadSource Class Reference

A threadsafe audio source base class. More...

#include <AsyncAudioThreadSource.h>

Inheritance diagram for Async::AudioThreadSource:
Async::AudioSource

Public Member Functions

 AudioThreadSource (void)
 Default constructor.
 
 AudioThreadSource (const AudioThreadSource &)=delete
 No copy constructor.
 
virtual ~AudioThreadSource (void)
 Destructor.
 
AudioThreadSourceoperator= (const AudioThreadSource &)=delete
 
- 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 int sinkWriteSamples (const float *samples, int count)
 Queue samples for delivery to the connected sink.
 
virtual void sinkFlushSamples (void)
 Flush samples in the connected sink when the queue is empty.
 
void waitForAllSamplesFlushed (void)
 Block execution until all samples have been flushed.
 
- 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 threadsafe audio source base class.

Author
Tobias Blomberg / SM0SVX
Date
2019-02-02

This is a base class for writing threadsafe audio source classes. This is of use when the audio source is running in a separate thread, not in the Async main thread.

Note that all administrative functions like connecting and disconnecting sinks must be executed from the main Async thread. The same goes for destroying an object. It is only the functions sinkWriteSamples and sinkFlushSamples that are threadsafe.

Definition at line 125 of file AsyncAudioThreadSource.h.

Constructor & Destructor Documentation

◆ AudioThreadSource() [1/2]

Async::AudioThreadSource::AudioThreadSource ( void )
inline

Default constructor.

Definition at line 131 of file AsyncAudioThreadSource.h.

◆ AudioThreadSource() [2/2]

Async::AudioThreadSource::AudioThreadSource ( const AudioThreadSource & )
delete

No copy constructor.

◆ ~AudioThreadSource()

virtual Async::AudioThreadSource::~AudioThreadSource ( void )
inlinevirtual

Destructor.

Definition at line 141 of file AsyncAudioThreadSource.h.

References Async::Application::app().

Member Function Documentation

◆ operator=()

AudioThreadSource & Async::AudioThreadSource::operator= ( const AudioThreadSource & )
delete

◆ sinkFlushSamples()

virtual void Async::AudioThreadSource::sinkFlushSamples ( void )
inlineprotectedvirtual

Flush samples in the connected sink when the queue is empty.

This function is used to tell the connected sink to flush previously written samples when the queue is empty. If the writeSamples function is called before the queue is empty, the flush is cancelled.

Definition at line 183 of file AsyncAudioThreadSource.h.

◆ sinkWriteSamples()

virtual int Async::AudioThreadSource::sinkWriteSamples ( const float * samples,
int count )
inlineprotectedvirtual

Queue samples for delivery to the connected sink.

Parameters
samplesThe buffer containing the samples
countThe number of samples in the buffer

This function is used to queue audio for later delivery to the connected audio sink. If a flush is pending, calling this function will cancel the flush.

Definition at line 161 of file AsyncAudioThreadSource.h.

◆ waitForAllSamplesFlushed()

void Async::AudioThreadSource::waitForAllSamplesFlushed ( void )
inlineprotected

Block execution until all samples have been flushed.

This function can be used to wait until the sink has flushed all sampled written to it. Note that calling this function must be preceeded by a call to sinkFlushSamples or it will block forever.

Definition at line 203 of file AsyncAudioThreadSource.h.


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