2018-07-06 03:23:46 +00:00
|
|
|
#include "api.h"
|
|
|
|
#include "data/soundData.h"
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetBitDepth(lua_State* L) {
|
2018-07-06 03:23:46 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
lua_pushinteger(L, soundData->bitDepth);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetChannelCount(lua_State* L) {
|
2018-07-06 03:23:46 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
lua_pushinteger(L, soundData->channelCount);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetDuration(lua_State* L) {
|
2018-07-06 03:23:46 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
lua_pushnumber(L, soundData->samples / (float) soundData->sampleRate);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetSample(lua_State* L) {
|
2018-07-06 03:45:09 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
int index = luaL_checkinteger(L, 2);
|
|
|
|
lua_pushnumber(L, lovrSoundDataGetSample(soundData, index));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetSampleCount(lua_State* L) {
|
2018-07-06 03:23:46 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
lua_pushinteger(L, soundData->samples);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataGetSampleRate(lua_State* L) {
|
2018-07-06 03:23:46 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
lua_pushinteger(L, soundData->sampleRate);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrSoundDataSetSample(lua_State* L) {
|
2018-07-06 03:45:09 +00:00
|
|
|
SoundData* soundData = luax_checktype(L, 1, SoundData);
|
|
|
|
int index = luaL_checkinteger(L, 2);
|
2019-01-29 10:28:55 +00:00
|
|
|
float value = luax_checkfloat(L, 3);
|
2018-07-06 03:45:09 +00:00
|
|
|
lovrSoundDataSetSample(soundData, index, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-19 16:26:24 +00:00
|
|
|
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
|
|
|
const luaL_Reg lovrSoundData[] = {
|
|
|
|
{ "getBitDepth", l_lovrSoundDataGetBitDepth },
|
|
|
|
{ "getChannelCount", l_lovrSoundDataGetChannelCount },
|
|
|
|
{ "getDuration", l_lovrSoundDataGetDuration },
|
2018-07-06 03:45:09 +00:00
|
|
|
{ "getSample", l_lovrSoundDataGetSample },
|
2018-07-06 03:23:46 +00:00
|
|
|
{ "getSampleCount", l_lovrSoundDataGetSampleCount },
|
|
|
|
{ "getSampleRate", l_lovrSoundDataGetSampleRate },
|
2018-07-06 03:45:09 +00:00
|
|
|
{ "setSample", l_lovrSoundDataSetSample },
|
2020-01-19 16:26:24 +00:00
|
|
|
{ "getBlob", l_lovrSoundDataGetBlob },
|
2018-07-06 03:23:46 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|