mirror of https://github.com/bjornbytes/lovr.git
phonon: rearrange Source accessors;
This commit is contained in:
parent
584138c937
commit
0af7e98fad
|
@ -64,6 +64,30 @@ static int l_lovrSourceSetVolume(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetDuration(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
TimeUnit units = luax_checkenum(L, 2, TimeUnit, "seconds");
|
||||
double duration = lovrSourceGetDuration(source, units);
|
||||
lua_pushnumber(L, duration);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetTime(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
TimeUnit units = luax_checkenum(L, 2, TimeUnit, "seconds");
|
||||
double time = lovrSourceGetTime(source, units);
|
||||
lua_pushnumber(L, time);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetTime(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
double seconds = luaL_checknumber(L, 2);
|
||||
TimeUnit units = luax_checkenum(L, 3, TimeUnit, "seconds");
|
||||
lovrSourceSetTime(source, seconds, units);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceIsSpatial(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
lua_pushboolean(L, lovrSourceIsSpatial(source));
|
||||
|
@ -95,30 +119,6 @@ static int l_lovrSourceSetPose(lua_State *L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetDuration(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
TimeUnit units = luax_checkenum(L, 2, TimeUnit, "seconds");
|
||||
double duration = lovrSourceGetDuration(source, units);
|
||||
lua_pushnumber(L, duration);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceGetTime(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
TimeUnit units = luax_checkenum(L, 2, TimeUnit, "seconds");
|
||||
double time = lovrSourceGetTime(source, units);
|
||||
lua_pushnumber(L, time);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrSourceSetTime(lua_State* L) {
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
double seconds = luaL_checknumber(L, 2);
|
||||
TimeUnit units = luax_checkenum(L, 3, TimeUnit, "seconds");
|
||||
lovrSourceSetTime(source, seconds, units);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrSource[] = {
|
||||
{ "clone", l_lovrSourceClone },
|
||||
{ "play", l_lovrSourcePlay },
|
||||
|
@ -129,11 +129,11 @@ const luaL_Reg lovrSource[] = {
|
|||
{ "setLooping", l_lovrSourceSetLooping },
|
||||
{ "getVolume", l_lovrSourceGetVolume },
|
||||
{ "setVolume", l_lovrSourceSetVolume },
|
||||
{ "isSpatial", l_lovrSourceIsSpatial },
|
||||
{ "getPose", l_lovrSourceGetPose },
|
||||
{ "setPose", l_lovrSourceSetPose },
|
||||
{ "getDuration", l_lovrSourceGetDuration },
|
||||
{ "getTime", l_lovrSourceGetTime },
|
||||
{ "setTime", l_lovrSourceSetTime },
|
||||
{ "isSpatial", l_lovrSourceIsSpatial },
|
||||
{ "getPose", l_lovrSourceGetPose },
|
||||
{ "setPose", l_lovrSourceSetPose },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -452,6 +452,21 @@ void lovrSourceSetVolume(Source* source, float volume) {
|
|||
ma_mutex_unlock(&state.lock);
|
||||
}
|
||||
|
||||
double lovrSourceGetDuration(Source* source, TimeUnit units) {
|
||||
uint32_t frames = lovrSoundGetFrameCount(source->sound);
|
||||
return units == UNIT_SECONDS ? (double) frames / lovrSoundGetSampleRate(source->sound) : frames;
|
||||
}
|
||||
|
||||
double lovrSourceGetTime(Source* source, TimeUnit units) {
|
||||
return units == UNIT_SECONDS ? (double) source->offset / lovrSoundGetSampleRate(source->sound) : source->offset;
|
||||
}
|
||||
|
||||
void lovrSourceSetTime(Source* source, double time, TimeUnit units) {
|
||||
ma_mutex_lock(&state.lock);
|
||||
source->offset = units == UNIT_SECONDS ? (uint32_t) (time * lovrSoundGetSampleRate(source->sound) + .5) : (uint32_t) time;
|
||||
ma_mutex_unlock(&state.lock);
|
||||
}
|
||||
|
||||
bool lovrSourceIsSpatial(Source *source) {
|
||||
return source->spatial;
|
||||
}
|
||||
|
@ -468,21 +483,6 @@ void lovrSourceSetPose(Source *source, float position[4], float orientation[4])
|
|||
ma_mutex_unlock(&state.lock);
|
||||
}
|
||||
|
||||
double lovrSourceGetDuration(Source* source, TimeUnit units) {
|
||||
uint32_t frames = lovrSoundGetFrameCount(source->sound);
|
||||
return units == UNIT_SECONDS ? (double) frames / lovrSoundGetSampleRate(source->sound) : frames;
|
||||
}
|
||||
|
||||
double lovrSourceGetTime(Source* source, TimeUnit units) {
|
||||
return units == UNIT_SECONDS ? (double) source->offset / lovrSoundGetSampleRate(source->sound) : source->offset;
|
||||
}
|
||||
|
||||
void lovrSourceSetTime(Source* source, double time, TimeUnit units) {
|
||||
ma_mutex_lock(&state.lock);
|
||||
source->offset = units == UNIT_SECONDS ? (uint32_t) (time * lovrSoundGetSampleRate(source->sound) + .5) : (uint32_t) time;
|
||||
ma_mutex_unlock(&state.lock);
|
||||
}
|
||||
|
||||
intptr_t* lovrSourceGetSpatializerMemoField(Source* source) {
|
||||
return &source->spatializerMemo;
|
||||
}
|
||||
|
|
|
@ -50,10 +50,10 @@ bool lovrSourceIsLooping(Source* source);
|
|||
void lovrSourceSetLooping(Source* source, bool loop);
|
||||
float lovrSourceGetVolume(Source* source);
|
||||
void lovrSourceSetVolume(Source* source, float volume);
|
||||
bool lovrSourceIsSpatial(Source* source);
|
||||
void lovrSourceGetPose(Source* source, float position[4], float orientation[4]);
|
||||
void lovrSourceSetPose(Source* source, float position[4], float orientation[4]);
|
||||
double lovrSourceGetDuration(Source* source, TimeUnit units);
|
||||
double lovrSourceGetTime(Source* source, TimeUnit units);
|
||||
void lovrSourceSetTime(Source* source, double time, TimeUnit units);
|
||||
bool lovrSourceIsSpatial(Source* source);
|
||||
void lovrSourceGetPose(Source* source, float position[4], float orientation[4]);
|
||||
void lovrSourceSetPose(Source* source, float position[4], float orientation[4]);
|
||||
intptr_t* lovrSourceGetSpatializerMemoField(Source* source);
|
||||
|
|
Loading…
Reference in New Issue