HulaLoop
Simple cross-platform audio loopback and recording.
Public Member Functions | List of all members
hula::HulaRingBuffer Class Reference

HulaLoop wrapper class for PortAudio ring buffer. More...

#include <HulaRingBuffer.h>

Public Member Functions

 HulaRingBuffer (float maxDuration)
 Create a new ring buffer. More...
 
ring_buffer_size_t read (SAMPLE *data, ring_buffer_size_t maxSamples)
 Read up to maxSamples from the ring buffer into the memory pointed to by data. More...
 
ring_buffer_size_t directRead (ring_buffer_size_t maxSamples, void **dataPtr1, ring_buffer_size_t *size1, void **dataPtr2, ring_buffer_size_t *size2)
 Fetch direct pointers to memory within the ring buffer. More...
 
ring_buffer_size_t write (const SAMPLE *data, ring_buffer_size_t maxSamples)
 Add data to the ring buffer. More...
 
 ~HulaRingBuffer ()
 Destructor for the ring buffer. More...
 

Detailed Description

HulaLoop wrapper class for PortAudio ring buffer.

Constructor & Destructor Documentation

HulaRingBuffer::HulaRingBuffer ( float  maxDuration)

Create a new ring buffer.

The ring buffer's size is determined using the formula:

maxDuration * sampleRate * channelCount * sampleSize
Parameters
maxDurationThe maximum length in seconds that the ring buffer should be capable of holding.

Member Function Documentation

ring_buffer_size_t HulaRingBuffer::directRead ( ring_buffer_size_t  maxSamples,
void **  dataPtr1,
ring_buffer_size_t *  size1,
void **  dataPtr2,
ring_buffer_size_t *  size2 
)

Fetch direct pointers to memory within the ring buffer.

This can be used to avoid allocating a secondary container. The second pointer/size pair is for when the ring buffer has split data between its tail and head. If the requested maxBytes are continuous in the underlying memory, only the first pointer/size pair is used.

Parameters
maxSamplesDesired number of samples.
dataPtr1The address where the first pointer should be stored.
size1Number of elements available from dataPtr1.
dataPtr2The address where the second pointer (if required) will be stored. NULL if not used.
size2Number of elements available from dataPtr2.
Returns
Number of samples read.
ring_buffer_size_t HulaRingBuffer::read ( SAMPLE *  data,
ring_buffer_size_t  maxSamples 
)

Read up to maxSamples from the ring buffer into the memory pointed to by data.

Parameters
dataPointer to allocated memory of at least maxSamples size.
maxSamplesDesired number of samples.
Returns
Number of samples read.
ring_buffer_size_t HulaRingBuffer::write ( const SAMPLE *  data,
ring_buffer_size_t  maxSamples 
)

Add data to the ring buffer.

Parameters
dataArray of samples to write to the ring buffer.
maxSamplesNumber of samples contained in the array.
Returns
Number of samples written.

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