windowf

Variants: windowcf, windowf

Sliding window first-in/first-out buffer with a fixed size

Public Functions

windowf windowf_create(unsigned int _n)
windowf windowf_recreate(windowf _q, unsigned int _n)
windowf windowf_copy(windowf _q)
int windowf_destroy(windowf _q)
int windowf_print(windowf _q)
int windowf_debug_print(windowf _q)
int windowf_reset(windowf _q)
int windowf_read(windowf _q, float ** _v)
int windowf_index(windowf _q, unsigned int _i, float * _v)
int windowf_push(windowf _q, float _v)
int windowf_write(windowf _q, float * _v, unsigned int _n)

Interfaces

windowf windowf_create(unsigned int _n)

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(windowf _q, unsigned int _n)

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(windowf _q)

Copy object including all internal objects and state

int windowf_destroy(windowf _q)

Destroy window object, freeing all internally memory

int windowf_print(windowf _q)

Print window object to stdout

int windowf_debug_print(windowf _q)

Print window object to stdout (with extra information)

int windowf_reset(windowf _q)

Reset window object (initialize to zeros)

int windowf_read(windowf _q, float ** _v)

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(windowf _q, unsigned int _i, float * _v)

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(windowf _q, float _v)

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(windowf _q, float * _v, unsigned int _n)

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