forked from bkacjios/lua-mumble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.c
37 lines (29 loc) · 954 Bytes
/
encoder.c
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
#include "mumble.h"
int encoder_new(lua_State *l)
{
opus_int32 samplerate = luaL_optinteger(l, 1, 48000);
OpusEncoder *encoder = lua_newuserdata(l, opus_encoder_get_size(1));
luaL_getmetatable(l, METATABLE_ENCODER);
lua_setmetatable(l, -2);
int error = opus_encoder_init(encoder, samplerate, 1, OPUS_APPLICATION_AUDIO);
if (error != OPUS_OK) {
lua_pushnil(l);
lua_pushfstring(l, "could not initialize the Opus encoder: %s", opus_strerror(error));
return 2;
}
opus_encoder_ctl(encoder, OPUS_SET_VBR(0));
opus_encoder_ctl(encoder, OPUS_SET_BITRATE(40000));
return 1;
}
int encoder_setBitRate(lua_State *l)
{
OpusEncoder *encoder = luaL_checkudata(l, 1, METATABLE_ENCODER);
opus_encoder_ctl(encoder, OPUS_SET_BITRATE(luaL_checkinteger(l, 2)));
return 0;
}
int encoder_tostring(lua_State *l)
{
OpusEncoder *encoder = luaL_checkudata(l, 1, METATABLE_ENCODER);
lua_pushfstring(l, "%s: %p", METATABLE_ENCODER, encoder);
return 1;
}