HulaLoop
Simple cross-platform audio loopback and recording.
Functions
Memory Management

Commands related to any memory management required of library end-users. More...

Functions

HulaRingBufferhula::Controller::createBuffer (float duration)
 Allocate and initialize a HulaRingBuffer that can be added to the OSAudio ring buffer list via Controller::addBuffer. More...
 
HulaRingBufferhula::Controller::createAndAddBuffer (float duration)
 Allocate and initialize a HulaRingBuffer and automatically add it to the OSAudio ring buffer list.
 
void hula::Controller::removeBuffer (HulaRingBuffer *rb)
 Remove a buffer from the list of buffers that receive audio data. More...
 
std::vector< Device * > hula::Controller::getDevices (DeviceType type) const
 Fetch a list of devices for the given DeviceType. More...
 
bool hula::Controller::setActiveInputDevice (Device *device) const
 Set the device from which audio should be captured. More...
 
bool hula::Controller::setActiveOutputDevice (Device *device) const
 Set the device to which audio should be played back. More...
 
static void hula::Device::deleteDevices (std::vector< Device *> devices)
 Delete all the device pointers inside the vector.
 
 hula::Device::~Device ()
 Free any resources associated with the Device. More...
 
 hula::HulaRingBuffer::~HulaRingBuffer ()
 Destructor for the ring buffer. More...
 

Detailed Description

Commands related to any memory management required of library end-users.

A number of methods in the HulaLoop API return objects that must be deleted by the caller. Each of these is detailed below.

The methods fall into two groups: buffers and devices.

Example

#include <thread>
int main()
{
// Create the controller object
Controller c;
// Set the active input device
std::vector<Device *> devices = c.getDevices(LOOPBACK);
if (devices.size() > 0)
{
// This calls the copy constructor on the selected device
c.setActiveInputDevice(devices[0]);
}
// Delete the devices
Device::deleteDevices(devices);
// Add a buffer to start receiving data
HL_RingBuffer * rb = c.createAndAddBuffer();
std::thread t = std::thread(&listen, rb);
t.join();
// Remove and delete the buffer
c.removeBuffer(rb);
delete rb;
}
void listen(HulaRingBuffer *rb)
{
int maxSize = 256;
float *temp = new float[maxSize];
// Read 100 temp buffers
for (int i = 0; i < 100; i++)
{
size_t bytesRead = rb->read(temp, maxSize);
printf("Read %d bytes.@n", bytesRead);
}
delete [] temp;
}

Function Documentation

◆ createBuffer()

HulaRingBuffer * Controller::createBuffer ( float  duration)

Allocate and initialize a HulaRingBuffer that can be added to the OSAudio ring buffer list via Controller::addBuffer.

Returns
Newly allocated ring buffer

◆ getDevices()

std::vector< Device * > Controller::getDevices ( DeviceType  type) const

Fetch a list of devices for the given DeviceType.

For requests of more than one type, bitwise OR the types together and cast back to a DeviceType.

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

◆ removeBuffer()

void Controller::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.

This is a publicly exposed wrapper for the OSAudio method.

Parameters
rbHulaLoop ring buffer to remove from the list.

◆ setActiveInputDevice()

bool Controller::setActiveInputDevice ( Device device) const

Set the device from which audio should be captured.

This method will make a copy of the passed Device so that subsequent (and necessary) calls to Device::deleteDevices() can be used without issue.

Parameters
deviceDesired input device
Returns
Success of device switch

◆ setActiveOutputDevice()

bool Controller::setActiveOutputDevice ( Device device) const

Set the device to which audio should be played back.

This method will make a copy of the passed Device so that subsequent (and necessary) calls to Device::deleteDevices() can be used without issue.

Parameters
device- Device instance that is to be set as the active output device
Returns
Success of device switch

◆ ~Device()

Device::~Device ( )

Free any resources associated with the Device.

This does not typically need to be called directly. A call to Device::deleteDevices() using the vector received from Controller::getDevices() is usually more appropriate.

◆ ~HulaRingBuffer()

HulaRingBuffer::~HulaRingBuffer ( )

Destructor for the ring buffer.

A HulaRingBuffer should only be deleted after is has been removed from the OSAudio ring buffer list using a call to Controller::removeBuffer().