HulaLoop
Simple cross-platform audio loopback and recording.
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
hula::OSAudio Class Referenceabstract

Abstract class that defines the required components for OS specfic audio classes. More...

#include <OSAudio.h>

Inheritance diagram for hula::OSAudio:
Inheritance graph
[legend]
Collaboration diagram for hula::OSAudio:
Collaboration graph
[legend]

Public Member Functions

virtual ~OSAudio ()=0
 Virtual implementation of Destructor.
 
void setBufferSize (uint32_t size)
 Set the desired capture buffer size. More...
 
void addBuffer (HulaRingBuffer *rb)
 Add an initialized buffer to the list of buffers that receive audio data. More...
 
void removeBuffer (HulaRingBuffer *rb)
 Remove a buffer from the list of buffers that receive audio data. More...
 
void copyToBuffers (const void *data, uint32_t bytes)
 Write to each of the buffers contained in rbs.
 
virtual std::vector< Device * > getDevices (DeviceType type)=0
 Receive the list of available record, playback and/or loopback audio devices connected to the OS and return them as Device instances. More...
 
virtual void capture ()=0
 Execution loop for loopback capture.
 
virtual bool checkDeviceParams (Device *device)=0
 Verify the bit rate of set rate with the hardware device compatibility.
 
virtual bool setActiveInputDevice (Device *device)
 Set the selected input device and restart capture threads with new device. More...
 
virtual bool setActiveOutputDevice (Device *device)
 Set the selected output device and restart capture threads with new device. More...
 

Static Public Member Functions

static void backgroundCapture (OSAudio *_this)
 Static function to allow starting a thread with an instance's capture method. More...
 

Protected Member Functions

 OSAudio ()
 Constructor is protected since this class is abstract.
 

Protected Attributes

DeviceactiveInputDevice
 The selected input device.
 
DeviceactiveOutputDevice
 The selected output device.
 
std::vector< HulaRingBuffer * > rbs
 List of all added ring buffers. More...
 
std::vector< std::thread > inThreads
 Thread for input device activities.
 
std::vector< std::thread > outThreads
 Thread for output device activities.
 
std::atomic< bool > endCapture
 Flag to syncronize the capture thread for an instance. More...
 
uint32_t captureBufferSize
 I don't really know what this is for right now but I'm going to add this comment so that Doxygen will quit complaining. More...
 

Detailed Description

Abstract class that defines the required components for OS specfic audio classes.

Member Function Documentation

void OSAudio::addBuffer ( HulaRingBuffer rb)

Add an initialized buffer to the list of buffers that receive audio data.

If already present, the ring buffer will not be duplicated.

Parameters
rbHulaLoop ring buffer to add to the list.
void OSAudio::backgroundCapture ( OSAudio _this)
static

Static function to allow starting a thread with an instance's capture method.

This will block, so it should be called in a new thread.

Calling this directly outside of this class is dangerous. Any thread not in the inThreads vector cannot be guarenteed a valid endCapture signal since it won't be joined after a device switch or 0 buffer state. Sync flags might be reset before the independent thread sees them.

Parameters
_thisInstance of OSAudio subclass which capture should be called on.
virtual std::vector<Device *> hula::OSAudio::getDevices ( DeviceType  type)
pure virtual

Receive the list of available record, playback and/or loopback audio devices connected to the OS and return them as Device instances.

Parameters
typeDeviceType that is combination from the DeviceType enum
Returns
std::vector<Device*> A list of Device instances that carry the necessary device information

Implemented in hula::WindowsAudio, hula::LinuxAudio, and hula::OSXAudio.

void OSAudio::removeBuffer ( HulaRingBuffer rb)

Remove a buffer from the list of buffers that receive audio data.

The removed buffer is not deleted and must be deleted by the user.

This enables pausing retrieval when audio is not needed and re-adding the same buffer when audio data is again needed.

Parameters
rbHulaLoop ring buffer to remove from the list.
bool OSAudio::setActiveInputDevice ( Device device)
virtual

Set the selected input device and restart capture threads with new device.

Parameters
deviceInstance of Device that corresponds to the desired system device
Returns
Success of device switch

Reimplemented in hula::LinuxAudio.

bool OSAudio::setActiveOutputDevice ( Device device)
virtual

Set the selected output device and restart capture threads with new device.

Parameters
deviceInstance of Device that corresponds to the desired system device
Returns
Success of device switch
void OSAudio::setBufferSize ( uint32_t  size)

Set the desired capture buffer size.

Parameters
sizeInteger value representing the desired buffer size

Member Data Documentation

uint32_t hula::OSAudio::captureBufferSize
protected

I don't really know what this is for right now but I'm going to add this comment so that Doxygen will quit complaining.

Peace. Love. Happiness. Doxygen :)

std::atomic<bool> hula::OSAudio::endCapture
protected

Flag to syncronize the capture thread for an instance.

This is used to break the capture loop when switching devices or when 0 buffers are present.

Should never be set directly. Only by setActiveXXXDevice().

std::vector<HulaRingBuffer *> hula::OSAudio::rbs
protected

List of all added ring buffers.

Data received from the operating system is copied into each of these buffers.


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