1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-03 21:13:42 +00:00
lovr/src/api/types/soundData.c

59 lines
1.7 KiB
C
Raw Normal View History

2018-07-06 03:23:46 +00:00
#include "api.h"
#include "data/soundData.h"
int l_lovrSoundDataGetBitDepth(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushinteger(L, soundData->bitDepth);
return 1;
}
int l_lovrSoundDataGetChannelCount(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushinteger(L, soundData->channelCount);
return 1;
}
int l_lovrSoundDataGetDuration(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushnumber(L, soundData->samples / (float) soundData->sampleRate);
return 1;
}
int l_lovrSoundDataGetSample(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
int index = luaL_checkinteger(L, 2);
lua_pushnumber(L, lovrSoundDataGetSample(soundData, index));
return 1;
}
2018-07-06 03:23:46 +00:00
int l_lovrSoundDataGetSampleCount(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushinteger(L, soundData->samples);
return 1;
}
int l_lovrSoundDataGetSampleRate(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
lua_pushinteger(L, soundData->sampleRate);
return 1;
}
int l_lovrSoundDataSetSample(lua_State* L) {
SoundData* soundData = luax_checktype(L, 1, SoundData);
int index = luaL_checkinteger(L, 2);
float value = luaL_checknumber(L, 3);
lovrSoundDataSetSample(soundData, index, value);
return 0;
}
2018-07-06 03:23:46 +00:00
const luaL_Reg lovrSoundData[] = {
{ "getBitDepth", l_lovrSoundDataGetBitDepth },
{ "getChannelCount", l_lovrSoundDataGetChannelCount },
{ "getDuration", l_lovrSoundDataGetDuration },
{ "getSample", l_lovrSoundDataGetSample },
2018-07-06 03:23:46 +00:00
{ "getSampleCount", l_lovrSoundDataGetSampleCount },
{ "getSampleRate", l_lovrSoundDataGetSampleRate },
{ "setSample", l_lovrSoundDataSetSample },
2018-07-06 03:23:46 +00:00
{ NULL, NULL }
};