Sliding window first-in/first-out buffer with a fixed size
Public Functions
windowcf | windowcf_create( |
windowcf | windowcf_recreate( |
windowcf | windowcf_copy( |
int | windowcf_destroy( |
int | windowcf_print( |
int | windowcf_debug_print( |
int | windowcf_reset( |
int | windowcf_read( |
int | windowcf_index( |
int | windowcf_push( |
int | windowcf_write( |
Interfaces
windowcf windowcf_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]
windowcf windowcf_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]
windowcf windowcf_copy(
Copy object including all internal objects and state
int windowcf_destroy(
Destroy window object, freeing all internally memory
int windowcf_print(
Print window object to stdout
int windowcf_debug_print(
Print window object to stdout (with extra information)
int windowcf_reset(
Reset window object (initialize to zeros)
int windowcf_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 windowcf_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 windowcf_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 windowcf_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