JackTrip

Public Member Functions | Protected Member Functions | List of all members
RingBuffer Class Reference

Provides a ring-buffer (or circular-buffer) that can be written to and read from asynchronously (blocking) or synchronously (non-blocking). More...

`#include <RingBuffer.h>`

Inheritance diagram for RingBuffer:
[legend]

## Public Member Functions
| RingBuffer (int SlotSize, int NumSlots)
| The class constructor. More...
virtual | ~RingBuffer ()
| The class destructor. More...
void | insertSlotBlocking (const int8_t *ptrToSlot)
| Insert a slot into the RingBuffer from ptrToSlot. This method will block until there's space in the buffer. More...
void | readSlotBlocking (int8_t *ptrToReadSlot)
| Read a slot from the RingBuffer into ptrToReadSlot. This method will block until there's space in the buffer. More...
void | insertSlotNonBlocking (const int8_t *ptrToSlot)
| Same as insertSlotBlocking but non-blocking (asynchronous) More...
void | readSlotNonBlocking (int8_t *ptrToReadSlot)
| Same as readSlotBlocking but non-blocking (asynchronous) More...

## Protected Member Functions
virtual void | setUnderrunReadSlot (int8_t *ptrToReadSlot)
| Sets the memory in the Read Slot when uderrun occurs. By default, this sets it to 0. Override this method in a subclass for a different behavior. More...
virtual void | setMemoryInReadSlotWithLastReadSlot (int8_t *ptrToReadSlot)
| Uses the last read slot to set the memory in the Read Slot. More...

## Detailed Description

Provides a ring-buffer (or circular-buffer) that can be written to and read from asynchronously (blocking) or synchronously (non-blocking).

The RingBuffer is an array of NumSlots slots of memory each of which is of size SlotSize bytes (8-bits). Slots can be read and written asynchronously/synchronously by multiple threads.

## Constructor & Destructor Documentation

## ◆ RingBuffer()

RingBuffer::RingBuffer | ( | int | SlotSize,
|  | int | NumSlots
| ) |  |

The class constructor.

Parameters

  SlotSize | Size of one slot in bytes
  NumSlots | Number of slots

## ◆ ~RingBuffer()

RingBuffer::~RingBuffer | ( |  | ) |
| virtual

The class destructor.

## Member Function Documentation

## ◆ insertSlotBlocking()

void RingBuffer::insertSlotBlocking | ( | const int8_t * | ptrToSlot | ) |

Insert a slot into the RingBuffer from ptrToSlot. This method will block until there's space in the buffer.

The caller is responsible to make sure sizeof(WriteSlot) = SlotSize. This method should be use when the caller can block against its output, like sending/receiving UDP packets. It shouldn't be used by audio. For that, use the insertSlotNonBlocking.

Parameters

  ptrToSlot | Pointer to slot to insert into the RingBuffer

## ◆ insertSlotNonBlocking()

void RingBuffer::insertSlotNonBlocking | ( | const int8_t * | ptrToSlot | ) |

Same as insertSlotBlocking but non-blocking (asynchronous)

Parameters

  ptrToSlot | Pointer to slot to insert into the RingBuffer

Todo:
  It may be better here to insert the slot anyways, instead of not writing anything

## ◆ readSlotBlocking()

void RingBuffer::readSlotBlocking | ( | int8_t * | ptrToReadSlot | ) |

Read a slot from the RingBuffer into ptrToReadSlot. This method will block until there's space in the buffer.

The caller is responsible to make sure sizeof(ptrToReadSlot) = SlotSize. This method should be use when the caller can block against its input, like sending/receiving UDP packets. It shouldn't be used by audio. For that, use the readSlotNonBlocking.

Parameters

  ptrToReadSlot | Pointer to read slot from the RingBuffer

## ◆ readSlotNonBlocking()

void RingBuffer::readSlotNonBlocking | ( | int8_t * | ptrToReadSlot | ) |

Same as readSlotBlocking but non-blocking (asynchronous)

Parameters

  ptrToReadSlot | Pointer to read slot from the RingBuffer

## ◆ setMemoryInReadSlotWithLastReadSlot()

void RingBuffer::setMemoryInReadSlotWithLastReadSlot | ( | int8_t * | ptrToReadSlot | ) |
| protected virtual

Uses the last read slot to set the memory in the Read Slot.

The last read slot is the last packet that arrived, so if no new packets are received, it keeps looping the same packet.

Parameters

  ptrToReadSlot | Pointer to read slot from the RingBuffer

## ◆ setUnderrunReadSlot()

void RingBuffer::setUnderrunReadSlot | ( | int8_t * | ptrToReadSlot | ) |
| protected virtual

Sets the memory in the Read Slot when uderrun occurs. By default, this sets it to 0. Override this method in a subclass for a different behavior.

Parameters

  ptrToReadSlot | Pointer to read slot from the RingBuffer

Reimplemented in RingBufferWavetable.

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

- src/RingBuffer.h
- src/RingBuffer.cpp