feat(volume): Add conversion functions
This commit is contained in:
parent
3173460b17
commit
1745e5d4ad
2 changed files with 84 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "volume.h"
|
#include "volume.h"
|
||||||
|
|
||||||
|
#include "lua_util.h"
|
||||||
|
|
||||||
#include <pulse/xmalloc.h>
|
#include <pulse/xmalloc.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -311,3 +313,31 @@ int volume_divide(lua_State* L) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int volume_from_dB(lua_State* L) {
|
||||||
|
double value = (double) luaL_checknumber(L, 1);
|
||||||
|
lua_pushinteger(L, pa_sw_volume_from_dB(value));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int volume_to_dB(lua_State* L) {
|
||||||
|
pa_volume_t value = luaL_checkinteger(L, 1);
|
||||||
|
lua_pushnumber(L, pa_sw_volume_to_dB(value));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int volume_from_linear(lua_State* L) {
|
||||||
|
double value = (double) luaL_checknumber(L, 1);
|
||||||
|
lua_pushinteger(L, pa_sw_volume_from_linear(value));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int volume_to_linear(lua_State* L) {
|
||||||
|
pa_volume_t value = luaL_checkinteger(L, 1);
|
||||||
|
lua_pushnumber(L, pa_sw_volume_to_linear(value));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -55,7 +55,6 @@ int volume__newindex(lua_State*);
|
||||||
*/
|
*/
|
||||||
int volume_new(lua_State*);
|
int volume_new(lua_State*);
|
||||||
|
|
||||||
|
|
||||||
/** Checks whether a value is a valid @{Volume}.
|
/** Checks whether a value is a valid @{Volume}.
|
||||||
*
|
*
|
||||||
* @function is_valid
|
* @function is_valid
|
||||||
|
@ -64,6 +63,53 @@ int volume_new(lua_State*);
|
||||||
*/
|
*/
|
||||||
int volume_is_valid(lua_State*);
|
int volume_is_valid(lua_State*);
|
||||||
|
|
||||||
|
/** Converts a decibel value to an integer volume value.
|
||||||
|
*
|
||||||
|
* This is only valid for software volumes. It does not operate
|
||||||
|
* on instances of @{Volume}.
|
||||||
|
*
|
||||||
|
* @function from_dB
|
||||||
|
* @tparam number value
|
||||||
|
* @treturn number
|
||||||
|
*/
|
||||||
|
int volume_from_dB(lua_State*);
|
||||||
|
|
||||||
|
/** Converts an integer volume value to a decibel value.
|
||||||
|
*
|
||||||
|
* This is only valid for software volumes. It does not operate
|
||||||
|
* on instances of @{Volume}.
|
||||||
|
*
|
||||||
|
* @function to_dB
|
||||||
|
* @tparam number value
|
||||||
|
* @treturn number
|
||||||
|
*/
|
||||||
|
int volume_to_dB(lua_State*);
|
||||||
|
|
||||||
|
/** Converts a linear factor to an integer volume value.
|
||||||
|
*
|
||||||
|
* `0.0` and less is muted, `1.0` is normal volume.
|
||||||
|
*
|
||||||
|
* This is only valid for software volumes. It does not operate
|
||||||
|
* on instances of @{Volume}.
|
||||||
|
*
|
||||||
|
* @function from_linear
|
||||||
|
* @tparam number value
|
||||||
|
* @treturn number
|
||||||
|
*/
|
||||||
|
int volume_from_linear(lua_State*);
|
||||||
|
|
||||||
|
/** Converts an integer volume value to linear factor.
|
||||||
|
*
|
||||||
|
* This is only valid for software volumes. It does not operate
|
||||||
|
* on instances of @{Volume}.
|
||||||
|
*
|
||||||
|
* @function to_linear
|
||||||
|
* @tparam number value
|
||||||
|
* @treturn number
|
||||||
|
*/
|
||||||
|
int volume_to_linear(lua_State*);
|
||||||
|
|
||||||
|
|
||||||
/// Volume
|
/// Volume
|
||||||
/// @type Volume
|
/// @type Volume
|
||||||
|
|
||||||
|
@ -236,9 +282,13 @@ static const struct luaL_Reg volume_mt[] = {
|
||||||
|
|
||||||
|
|
||||||
static const struct luaL_Reg volume_lib[] = {
|
static const struct luaL_Reg volume_lib[] = {
|
||||||
{"new", volume_new },
|
{"new", volume_new },
|
||||||
{ "is_valid", volume_is_valid},
|
{ "from_dB", volume_from_dB },
|
||||||
{ NULL, NULL }
|
{ "to_dB", volume_to_dB },
|
||||||
|
{ "from_linear", volume_from_linear},
|
||||||
|
{ "to_linear", volume_to_linear },
|
||||||
|
{ "is_valid", volume_is_valid },
|
||||||
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue