10 constructor for High Pass Filter
11 @tparam number fc cut-off frequency unit(hz)
12 @tparam number ts sampling time unit(s)
13 @treturn a.hpf High Pass Filter userdata
16 int liba_hpf_new(lua_State
*L
)
18 int top
= lua_gettop(L
);
21 a_float fc
= (a_float
)luaL_checknumber(L
, 1);
22 a_float ts
= (a_float
)luaL_checknumber(L
, 2);
23 a_hpf
*const ctx
= lua_newclass(L
, a_hpf
);
24 lua_registry_get(L
, liba_hpf_new
);
25 lua_setmetatable(L
, -2);
26 a_hpf_init(ctx
, A_HPF_GEN(fc
, ts
));
31 a_float alpha
= (a_float
)luaL_checknumber(L
, 1);
32 a_hpf
*const ctx
= lua_newclass(L
, a_hpf
);
33 lua_registry_get(L
, liba_hpf_new
);
34 lua_setmetatable(L
, -2);
35 a_hpf_init(ctx
, alpha
);
42 generate for High Pass Filter
43 @tparam a.hpf ctx High Pass Filter userdata
44 @tparam number fc cut-off frequency unit(hz)
45 @tparam number ts sampling time unit(s)
46 @treturn a.hpf High Pass Filter userdata
49 int liba_hpf_gen(lua_State
*L
)
51 int top
= lua_gettop(L
);
54 luaL_checktype(L
, 1, LUA_TUSERDATA
);
55 a_hpf
*const ctx
= (a_hpf
*)lua_touserdata(L
, 1);
56 a_float fc
= (a_float
)luaL_checknumber(L
, 2);
57 a_float ts
= (a_float
)luaL_checknumber(L
, 3);
58 ctx
->alpha
= A_HPF_GEN(fc
, ts
);
64 luaL_checktype(L
, 1, LUA_TUSERDATA
);
65 a_hpf
*const ctx
= (a_hpf
*)lua_touserdata(L
, 1);
66 ctx
->alpha
= (a_float
)luaL_checknumber(L
, 2);
74 calculate for High Pass Filter
75 @tparam a.hpf ctx High Pass Filter userdata
76 @tparam number x input value
77 @treturn number output value
80 int liba_hpf_iter(lua_State
*L
)
82 a_hpf
*const ctx
= (a_hpf
*)lua_touserdata(L
, 1);
85 a_float x
= (a_float
)luaL_checknumber(L
, 2);
86 lua_pushnumber(L
, (lua_Number
)a_hpf_iter(ctx
, x
));
93 zeroing for High Pass Filter
94 @tparam a.hpf ctx High Pass Filter userdata
95 @treturn a.hpf High Pass Filter userdata
98 int liba_hpf_zero(lua_State
*L
)
100 a_hpf
*const ctx
= (a_hpf
*)lua_touserdata(L
, 1);
109 static int liba_hpf_set(lua_State
*L
)
111 switch (a_hash_bkdr(lua_tostring(L
, 2), 0))
113 case 0xE8859EEB: // __name
114 case 0xE70C48C6: // __call
115 case 0xA65758B2: // __index
116 case 0xAEB551C6: // __newindex
119 lua_getmetatable(L
, 1);
126 static int liba_hpf_get(lua_State
*L
)
128 a_hpf
const *const ctx
= (a_hpf
const *)lua_touserdata(L
, 1);
129 switch (a_hash_bkdr(lua_tostring(L
, 2), 0))
131 case 0xB5485B9E: // alpha
132 lua_pushnumber(L
, (lua_Number
)ctx
->alpha
);
134 case 0x23C9C461: // output
135 lua_pushnumber(L
, (lua_Number
)ctx
->output
);
137 case 0x41FAB016: // input
138 lua_pushnumber(L
, (lua_Number
)ctx
->input
);
140 case 0xA65758B2: // __index
141 lua_registry_get(L
, liba_hpf_new
);
142 lua_num_set(L
, -1, "alpha", ctx
->alpha
);
143 lua_num_set(L
, -1, "input", ctx
->input
);
144 lua_num_set(L
, -1, "output", ctx
->output
);
147 lua_getmetatable(L
, 1);
154 static int liba_hpf_(lua_State
*L
)
156 lua_pushcfunction(L
, liba_hpf_new
);
158 lua_call(L
, lua_gettop(L
) - 1, 1);
162 int luaopen_liba_hpf(lua_State
*L
)
164 static lua_fun
const funcs
[] = {
165 {"new", liba_hpf_new
},
166 {"gen", liba_hpf_gen
},
167 {"iter", liba_hpf_iter
},
168 {"zero", liba_hpf_zero
},
170 lua_createtable(L
, 0, A_LEN(funcs
));
171 lua_fun_reg(L
, -1, funcs
, A_LEN(funcs
));
172 lua_createtable(L
, 0, 1);
173 lua_fun_set(L
, -1, "__call", liba_hpf_
);
174 lua_setmetatable(L
, -2);
176 static lua_fun
const metas
[] = {
177 {"__newindex", liba_hpf_set
},
178 {"__index", liba_hpf_get
},
179 {"__call", liba_hpf_iter
},
181 lua_createtable(L
, 0, A_LEN(metas
) + A_LEN(funcs
) + 1);
182 lua_fun_reg(L
, -1, metas
, A_LEN(metas
));
183 lua_fun_reg(L
, -1, funcs
, A_LEN(funcs
));
184 lua_str_set(L
, -1, "__name", "a.hpf");
185 lua_registry_set(L
, liba_hpf_new
);