Sliding window first-in/first-out buffer with a fixed size
Public Functions
windowf | windowf_create( |
windowf | windowf_recreate( |
windowf | windowf_copy( |
int | windowf_destroy( |
int | windowf_print( |
int | windowf_debug_print( |
int | windowf_reset( |
int | windowf_read( |
int | windowf_index( |
int | windowf_push( |
int | windowf_write( |
Interfaces
windowf windowf_create(
Create window buffer object of a fixed length. Samples may be pushed into the buffer which retains the most recent \(n\) samples.
- _n : length of the window buffer [samples]
windowf windowf_recreate(
Recreate window buffer object with new length. This extends an existing window's size, similar to the standard C library's realloc() to n samples. If the size of the new window is larger than the old one, the newest values are retained at the beginning of the buffer and the oldest values are truncated. If the size of the new window is smaller than the old one, the oldest values are truncated.
- _q : old window object
- _n : new window length [samples]
windowf windowf_copy(
Copy object including all internal objects and state
int windowf_destroy(
Destroy window object, freeing all internally memory
int windowf_print(
Print window object to stdout
int windowf_debug_print(
Print window object to stdout (with extra information)
int windowf_reset(
Reset window object (initialize to zeros)
int windowf_read(
Read the contents of the window by returning a pointer to the aligned internal memory array. This method guarantees that the elements are linearized. This method should only be used for reading; writing values to the buffer has unspecified results. Note that the returned pointer is only valid until another operation is performed on the window buffer object
- _q : window object
- _v : output pointer (set to internal array)
int windowf_index(
Index single element in buffer at a particular index This retrieves the \(i^{th}\) sample in the window, storing the output value in _v. This is equivalent to first invoking read() and then indexing on the resulting pointer; however the result is obtained much faster. Therefore setting the index to 0 returns the oldest value in the window.
- _q : window object
- _i : index of element to read
- _v : output value pointer
int windowf_push(
Shifts a single sample into the right side of the window, pushing the oldest (left-most) sample out of the end. Unlike stacks, the window object has no equivalent "pop" method, as values are retained in memory until they are overwritten.
- _q : window object
- _v : single input element
int windowf_write(
Write array of elements onto window buffer Effectively, this is equivalent to pushing each sample one at a time, but executes much faster.
- _q : window object
- _v : input array of values to write
- _n : number of input values to write