lovr/src/api/l_data_soundData.c

42 lines
1.2 KiB
C
Raw Normal View History

2018-07-06 03:23:46 +00:00
#include "api.h"
#include "data/soundData.h"
2020-11-26 21:14:02 +00:00
#include "data/blob.h"
static int l_lovrSoundDataGetBlob(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
Blob* blob = soundData->blob;
luax_pushtype(L, Blob, blob);
return 1;
}
2018-07-06 03:23:46 +00:00
2020-12-10 12:29:42 +00:00
static int l_lovrSoundDataAppend(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
Blob* blob = luax_totype(L, 2, Blob);
SoundData* sound = luax_totype(L, 2, SoundData);
2020-12-15 09:16:58 +00:00
size_t appendedSamples = 0;
2020-12-10 12:29:42 +00:00
if (sound) {
appendedSamples = lovrSoundDataStreamAppendSound(soundData, sound);
} else if (blob) {
appendedSamples = lovrSoundDataStreamAppendBlob(soundData, blob);
2020-12-15 09:32:00 +00:00
} else {
luaL_argerror(L, 2, "Invalid blob appended");
2020-12-10 12:29:42 +00:00
}
lua_pushinteger(L, appendedSamples);
return 1;
}
2020-12-10 13:23:35 +00:00
static int l_lovrSoundDataSetSample(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
int index = luaL_checkinteger(L, 2);
float value = luax_checkfloat(L, 3);
lovrSoundDataSetSample(soundData, index, value);
return 0;
}
2018-07-06 03:23:46 +00:00
const luaL_Reg lovrSoundData[] = {
2020-12-03 16:07:55 +00:00
{ "getBlob", l_lovrSoundDataGetBlob },
2020-12-10 12:29:42 +00:00
{ "append", l_lovrSoundDataAppend },
2020-12-10 13:23:35 +00:00
{ "setSample", l_lovrSoundDataSetSample },
2020-12-03 16:07:55 +00:00
{ NULL, NULL }
2018-07-06 03:23:46 +00:00
};