-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconst.h
More file actions
49 lines (43 loc) · 1.49 KB
/
Copy pathconst.h
File metadata and controls
49 lines (43 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef CSYNTH_CONST_H
#define CSYNTH_CONST_H
#include "../../core/func.h"
#include "../../core/gen.h"
/** @see const_create */
typedef struct
{
/** @brief Constant value. */
double value;
} ConstContext;
static double const_eval(__U size_t count, __U Gen **args, __U Eval *eval, void *context_)
{
ConstContext *context = (ConstContext *)context_;
return context->value;
}
/**
* @brief Create a function that outputs a constant value.
*
* This function creates a generator that always outputs the same value,
* regardless of time or other inputs. It is useful for:
* - Setting fixed parameter values
* - Creating DC offsets
* - Testing and debugging
* - Providing constant modulation values
*
* The constant function is one of the simplest generators, with O(1) time
* complexity since it just returns a stored value.
*
* @param value The fixed numerical value that will be output every time the
* function is evaluated. Can be any double precision floating
* point number.
* @return Func* A constant function that always returns the specified value.
*/
Func *const_create(double value)
{
ConstContext initial = {.value = value};
return func_create(NULL, const_eval, NULL, NULL, sizeof(ConstContext), &initial, FuncFlagNone);
}
/** @brief Shorthand for `const_create`. */
Func *const_(double value) { return const_create(value); }
/** @brief Shorthand for `const_create`. */
Func *_(double value) { return const_(value); }
#endif // CSYNTH_CONST_H