LMMS
Loading...
Searching...
No Matches
lmms::RingBuffer Class Reference

A basic LMMS ring buffer for single-thread use. For thread and realtime safe alternative see LocklessRingBuffer. More...

#include <RingBuffer.h>

Inheritance diagram for lmms::RingBuffer:

Public Member Functions

 RingBuffer (f_cnt_t size)
 Constructs a ringbuffer of specified size, will not care about samplerate changes.
 RingBuffer (float size)
 Constructs a ringbuffer of specified samplerate-dependent size, which will be updated when samplerate changes.
 ~RingBuffer () override
void reset ()
 Clears the ringbuffer of any data and resets the position to 0.
void changeSize (f_cnt_t size)
 Changes the size of the ringbuffer. Clears all data.
void changeSize (float size)
 Changes the size of the ringbuffer. Clears all data.
void setSamplerateAware (bool b)
 Sets whether the ringbuffer size is adjusted for samplerate when samplerate changes.
void advance ()
 Advances the position by one period.
void movePosition (f_cnt_t amount)
 Moves position forwards/backwards by an amount of frames.
void movePosition (float amount)
 Moves position forwards/backwards by an amount of milliseconds.
void pop (SampleFrame *dst)
 Destructively reads a period-sized buffer from the current position, writes it to a specified destination, and advances the position by one period.
void read (SampleFrame *dst, f_cnt_t offset=0)
 Reads a period-sized buffer from the ringbuffer and writes it to a specified destination.
void read (SampleFrame *dst, float offset)
 Reads a period-sized buffer from the ringbuffer and writes it to a specified destination.
void read (SampleFrame *dst, f_cnt_t offset, f_cnt_t length)
 Reads a buffer of specified size from the ringbuffer and writes it to a specified destination.
void read (SampleFrame *dst, float offset, f_cnt_t length)
 Reads a buffer of specified size from the ringbuffer and writes it to a specified destination.
void write (SampleFrame *src, f_cnt_t offset=0, f_cnt_t length=0)
 Writes a buffer of sampleframes to the ringbuffer at specified position.
void write (SampleFrame *src, float offset, f_cnt_t length=0)
 Writes a buffer of sampleframes to the ringbuffer at specified position.
void writeAdding (SampleFrame *src, f_cnt_t offset=0, f_cnt_t length=0)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position.
void writeAdding (SampleFrame *src, float offset, f_cnt_t length=0)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position.
void writeAddingMultiplied (SampleFrame *src, f_cnt_t offset, f_cnt_t length, float level)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames.
void writeAddingMultiplied (SampleFrame *src, float offset, f_cnt_t length, float level)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames.
void writeSwappedAddingMultiplied (SampleFrame *src, f_cnt_t offset, f_cnt_t length, float level)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames, with swapped channels.
void writeSwappedAddingMultiplied (SampleFrame *src, float offset, f_cnt_t length, float level)
 Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames, with swapped channels.

Protected Slots

void updateSamplerate ()

Private Member Functions

f_cnt_t msToFrames (float ms)

Private Attributes

const f_cnt_t m_fpp
sample_rate_t m_samplerate
size_t m_size
SampleFramem_buffer
volatile unsigned int m_position

Detailed Description

A basic LMMS ring buffer for single-thread use. For thread and realtime safe alternative see LocklessRingBuffer.

Constructor & Destructor Documentation

◆ RingBuffer() [1/2]

lmms::RingBuffer::RingBuffer ( f_cnt_t size)

Constructs a ringbuffer of specified size, will not care about samplerate changes.

Parameters
sizeThe size of the buffer in frames. The actual size will be size + period size

◆ RingBuffer() [2/2]

lmms::RingBuffer::RingBuffer ( float size)

Constructs a ringbuffer of specified samplerate-dependent size, which will be updated when samplerate changes.

Parameters
sizeThe size of the buffer in milliseconds. The actual size will be size + period size

◆ ~RingBuffer()

lmms::RingBuffer::~RingBuffer ( )
override

Member Function Documentation

◆ advance()

void lmms::RingBuffer::advance ( )

Advances the position by one period.

◆ changeSize() [1/2]

void lmms::RingBuffer::changeSize ( f_cnt_t size)

Changes the size of the ringbuffer. Clears all data.

Parameters
sizeNew size in frames

◆ changeSize() [2/2]

void lmms::RingBuffer::changeSize ( float size)

Changes the size of the ringbuffer. Clears all data.

Parameters
sizeNew size in milliseconds

◆ movePosition() [1/2]

void lmms::RingBuffer::movePosition ( f_cnt_t amount)

Moves position forwards/backwards by an amount of frames.

Parameters
amountNumber of frames to move, may be negative

◆ movePosition() [2/2]

void lmms::RingBuffer::movePosition ( float amount)

Moves position forwards/backwards by an amount of milliseconds.

Parameters
amountNumber of milliseconds to move, may be negative

◆ msToFrames()

f_cnt_t lmms::RingBuffer::msToFrames ( float ms)
inlineprivate

◆ pop()

void lmms::RingBuffer::pop ( SampleFrame * dst)

Destructively reads a period-sized buffer from the current position, writes it to a specified destination, and advances the position by one period.

Parameters
dstDestination pointer

◆ read() [1/4]

void lmms::RingBuffer::read ( SampleFrame * dst,
f_cnt_t offset,
f_cnt_t length )

Reads a buffer of specified size from the ringbuffer and writes it to a specified destination.

Parameters
dstDestination pointer
offsetOffset in frames against current position, may be negative
lengthLength in frames of the buffer to read - must not be higher than the size of the ringbuffer!

◆ read() [2/4]

void lmms::RingBuffer::read ( SampleFrame * dst,
f_cnt_t offset = 0 )

Reads a period-sized buffer from the ringbuffer and writes it to a specified destination.

Parameters
dstDestination pointer
offsetOffset in frames against current position, may be negative

◆ read() [3/4]

void lmms::RingBuffer::read ( SampleFrame * dst,
float offset )

Reads a period-sized buffer from the ringbuffer and writes it to a specified destination.

Parameters
dstDestination pointer
offsetOffset in milliseconds against current position, may be negative

◆ read() [4/4]

void lmms::RingBuffer::read ( SampleFrame * dst,
float offset,
f_cnt_t length )

Reads a buffer of specified size from the ringbuffer and writes it to a specified destination.

Parameters
dstDestination pointer
offsetOffset in milliseconds against current position, may be negative
lengthLength in frames of the buffer to read - must not be higher than the size of the ringbuffer!

◆ reset()

void lmms::RingBuffer::reset ( )

Clears the ringbuffer of any data and resets the position to 0.

◆ setSamplerateAware()

void lmms::RingBuffer::setSamplerateAware ( bool b)

Sets whether the ringbuffer size is adjusted for samplerate when samplerate changes.

Parameters
bTrue if samplerate should affect buffer size

◆ updateSamplerate

void lmms::RingBuffer::updateSamplerate ( )
protectedslot

◆ write() [1/2]

void lmms::RingBuffer::write ( SampleFrame * src,
f_cnt_t offset = 0,
f_cnt_t length = 0 )

Writes a buffer of sampleframes to the ringbuffer at specified position.

Parameters
srcPointer to the source buffer
offsetOffset in frames against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!

◆ write() [2/2]

void lmms::RingBuffer::write ( SampleFrame * src,
float offset,
f_cnt_t length = 0 )

Writes a buffer of sampleframes to the ringbuffer at specified position.

Parameters
srcPointer to the source buffer
offsetOffset in milliseconds against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!

◆ writeAdding() [1/2]

void lmms::RingBuffer::writeAdding ( SampleFrame * src,
f_cnt_t offset = 0,
f_cnt_t length = 0 )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position.

Parameters
srcPointer to the source buffer
offsetOffset in frames against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!

◆ writeAdding() [2/2]

void lmms::RingBuffer::writeAdding ( SampleFrame * src,
float offset,
f_cnt_t length = 0 )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position.

Parameters
srcPointer to the source buffer
offsetOffset in milliseconds against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!

◆ writeAddingMultiplied() [1/2]

void lmms::RingBuffer::writeAddingMultiplied ( SampleFrame * src,
f_cnt_t offset,
f_cnt_t length,
float level )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames.

Parameters
srcPointer to the source buffer
offsetOffset in frames against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
levelMultiplier applied to the frames before they're written to the ringbuffer

◆ writeAddingMultiplied() [2/2]

void lmms::RingBuffer::writeAddingMultiplied ( SampleFrame * src,
float offset,
f_cnt_t length,
float level )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames.

Parameters
srcPointer to the source buffer
offsetOffset in milliseconds against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used
levelMultiplier applied to the frames before they're written to the ringbuffer

◆ writeSwappedAddingMultiplied() [1/2]

void lmms::RingBuffer::writeSwappedAddingMultiplied ( SampleFrame * src,
f_cnt_t offset,
f_cnt_t length,
float level )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames, with swapped channels.

Parameters
srcPointer to the source buffer
offsetOffset in frames against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
levelMultiplier applied to the frames before they're written to the ringbuffer

◆ writeSwappedAddingMultiplied() [2/2]

void lmms::RingBuffer::writeSwappedAddingMultiplied ( SampleFrame * src,
float offset,
f_cnt_t length,
float level )

Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with a specified multiplier applied to the frames, with swapped channels.

Parameters
srcPointer to the source buffer
offsetOffset in milliseconds against current position, may NOT be negative
lengthLength of the source buffer, if zero, period size is used
levelMultiplier applied to the frames before they're written to the ringbuffer

Member Data Documentation

◆ m_buffer

SampleFrame* lmms::RingBuffer::m_buffer
private

◆ m_fpp

const f_cnt_t lmms::RingBuffer::m_fpp
private

◆ m_position

volatile unsigned int lmms::RingBuffer::m_position
private

◆ m_samplerate

sample_rate_t lmms::RingBuffer::m_samplerate
private

◆ m_size

size_t lmms::RingBuffer::m_size
private

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