Monado OpenXR Runtime
m_lowpass_float.h
Go to the documentation of this file.
1// Copyright 2019, 2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Low-pass IIR filter for floats - C wrapper
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 * @ingroup aux_math
8 */
9
10#pragma once
11
12#include "util/u_time.h"
13
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19/*!
20 * An IIR (low pass) filter for scalar float values.
21 *
22 * Wraps xrt::auxiliary::math::LowPassIIRFilter - see that if you need a different scalar type, or its related types if
23 * you want to filter a vector.
24 *
25 */
26struct m_lowpass_float;
27
28/*!
29 * Constructor
30 *
31 * @param cutoff_hz A cutoff frequency in Hertz: signal changes much
32 * lower in frequency will be passed through the filter, while signal
33 * changes much higher in frequency will be blocked.
34 *
35 * @public @memberof m_lowpass_float
36 */
37struct m_lowpass_float *
38m_lowpass_float_create(float cutoff_hz);
39
40
41/*!
42 * Filter a sample
43 *
44 * @param mlf self-pointer
45 * @param sample The value to filter
46 * @param timestamp_ns The time that this sample was measured.
47 *
48 * @public @memberof m_lowpass_float
49 */
50void
51m_lowpass_float_add_sample(struct m_lowpass_float *mlf, float sample, timepoint_ns timestamp_ns);
52
53/*!
54 * Get the filtered value.
55 *
56 * Probably 0 or other meaningless value if it's not initialized: see @ref m_lowpass_float_is_initialized
57 *
58 * @param mlf self-pointer
59 *
60 * @public @memberof m_lowpass_float
61 */
62float
64
65/*!
66 * Get the time of last update
67 *
68 * @param mlf self-pointer
69 *
70 * @public @memberof m_lowpass_float
71 */
74
75/*!
76 * Get whether we have initialized state.
77 *
78 * @param mlf self-pointer
79 *
80 * @public @memberof m_lowpass_float
81 */
82bool
84
85/*!
86 * Destroy a lowpass integer filter.
87 *
88 * Does null checks.
89 *
90 * @param ptr_to_mlf Address of your lowpass integer filter. Will be set to zero.
91 *
92 * @public @memberof m_lowpass_float
93 */
94void
95m_lowpass_float_destroy(struct m_lowpass_float **ptr_to_mlf);
96
97#ifdef __cplusplus
98}
99#endif
int64_t timepoint_ns
Integer timestamp type.
Definition: u_time.h:70
Definition: m_lowpass_float.cpp:20
bool m_lowpass_float_is_initialized(const struct m_lowpass_float *mlf)
Get whether we have initialized state.
Definition: m_lowpass_float.cpp:77
timepoint_ns m_lowpass_float_get_timestamp_ns(const struct m_lowpass_float *mlf)
Get the time of last update.
Definition: m_lowpass_float.cpp:68
float m_lowpass_float_get_state(const struct m_lowpass_float *mlf)
Get the filtered value.
Definition: m_lowpass_float.cpp:58
void m_lowpass_float_destroy(struct m_lowpass_float **ptr_to_mlf)
Destroy a lowpass integer filter.
Definition: m_lowpass_float.cpp:87
struct m_lowpass_float * m_lowpass_float_create(float cutoff_hz)
Constructor.
Definition: m_lowpass_float.cpp:39
void m_lowpass_float_add_sample(struct m_lowpass_float *mlf, float sample, timepoint_ns timestamp_ns)
Filter a sample.
Definition: m_lowpass_float.cpp:49
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.