-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.h
37 lines (31 loc) · 942 Bytes
/
const.h
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
#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 of constant value.
*
* @param value Value to be returned during sampling.
* @return Func* Const function.
*/
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