leaf-electrical.h
1 /*
2  * leaf-electrical.h
3  *
4  * Created on: Sep 25, 2019
5  * Author: jeffsnyder
6  */
7 
8 #ifndef LEAF_INC_LEAF_ELECTRICAL_H_
9 #define LEAF_INC_LEAF_ELECTRICAL_H_
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15  //==============================================================================
16 
17 #include "leaf-global.h"
18 #include "leaf-math.h"
19 #include "leaf-mempool.h"
20 
29  //==============================================================================
30 
93  typedef enum WDFComponentType
94  {
95  SeriesAdaptor = 0,
96  ParallelAdaptor,
97  Resistor,
98  Capacitor,
99  Inductor,
100  Inverter,
101  ResistiveSource,
102  IdealSource,
103  Diode,
104  DiodePair,
105  RootNil,
106  WDFComponentNil
107  } WDFComponentType;
108 
109  typedef struct _tWDF _tWDF; // needed to allow tWDF pointers in struct
110  typedef _tWDF* tWDF;
111  struct _tWDF
112  {
113 
114  tMempool mempool;
115  WDFComponentType type;
116  float port_resistance_up;
117  float port_resistance_left;
118  float port_resistance_right;
119  float port_conductance_up;
120  float port_conductance_left;
121  float port_conductance_right;
122  float incident_wave_up;
123  float incident_wave_left;
124  float incident_wave_right;
125  float reflected_wave_up;
126  float reflected_wave_left;
127  float reflected_wave_right;
128  float gamma_zero;
129  float sample_rate;
130  float value;
131  tWDF* child_left;
132  tWDF* child_right;
133  float (*get_port_resistance)(tWDF* const);
134  float (*get_reflected_wave_up)(tWDF* const, float);
135  float (*get_reflected_wave_down)(tWDF* const, float, float);
136  void (*set_incident_wave)(tWDF* const, float, float);
137  };
138 
139  //WDF Linear Components
140  void tWDF_init (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, LEAF* const leaf);
141  void tWDF_initToPool (tWDF* const, WDFComponentType type, float value, tWDF* const rL, tWDF* const rR, tMempool* const);
142  void tWDF_free (tWDF* const);
143 
144  float tWDF_tick (tWDF* const, float sample, tWDF* const outputPoint, uint8_t paramsChanged);
145 
146  void tWDF_setValue (tWDF* const, float value);
147  void tWDF_setSampleRate (tWDF* const, float sample_rate);
148  uint8_t tWDF_isLeaf (tWDF* const);
149 
150  float tWDF_getPortResistance (tWDF* const);
151  float tWDF_getReflectedWaveUp (tWDF* const, float input); //for tree, only uses input for resistive source
152  float tWDF_getReflectedWaveDown (tWDF* const, float input, float incident_wave); //for roots
153  void tWDF_setIncidentWave (tWDF* const, float incident_wave, float input);
154 
155  float tWDF_getVoltage (tWDF* const);
156  float tWDF_getCurrent (tWDF* const);
157 
158 
159  //==============================================================================
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* LEAF_INC_LEAF_ELECTRICAL_H_ */
166 
tWDF_getCurrent
float tWDF_getCurrent(tWDF *const)
Definition: leaf-electrical.c:264
tWDF_isLeaf
uint8_t tWDF_isLeaf(tWDF *const)
Definition: leaf-electrical.c:227
tWDF_getReflectedWaveDown
float tWDF_getReflectedWaveDown(tWDF *const, float input, float incident_wave)
Definition: leaf-electrical.c:252
tWDF_setValue
void tWDF_setValue(tWDF *const, float value)
Definition: leaf-electrical.c:215
tWDF_init
void tWDF_init(tWDF *const, WDFComponentType type, float value, tWDF *const rL, tWDF *const rR, LEAF *const leaf)
Initialize a tWDF to the default mempool of a LEAF instance.
Definition: leaf-electrical.c:168
tWDF_initToPool
void tWDF_initToPool(tWDF *const, WDFComponentType type, float value, tWDF *const rL, tWDF *const rR, tMempool *const)
Initialize a tWDF to a specified mempool.
Definition: leaf-electrical.c:173
tWDF_getPortResistance
float tWDF_getPortResistance(tWDF *const)
Definition: leaf-electrical.c:234
tWDF_getVoltage
float tWDF_getVoltage(tWDF *const)
Definition: leaf-electrical.c:258
tWDF_setSampleRate
void tWDF_setSampleRate(tWDF *const, float sample_rate)
Definition: leaf-electrical.c:221
tWDF_setIncidentWave
void tWDF_setIncidentWave(tWDF *const, float incident_wave, float input)
Definition: leaf-electrical.c:240
tWDF_tick
float tWDF_tick(tWDF *const, float sample, tWDF *const outputPoint, uint8_t paramsChanged)
Definition: leaf-electrical.c:188
tWDF_free
void tWDF_free(tWDF *const)
Free a tWDF from its mempool.
Definition: leaf-electrical.c:181
tWDF_getReflectedWaveUp
float tWDF_getReflectedWaveUp(tWDF *const, float input)
Definition: leaf-electrical.c:246
LEAF
Struct for an instance of LEAF.
Definition: leaf-global.h:31