mirror of https://github.com/bjornbytes/lovr.git
Global pause/resume/rewind/stop for lovr.audio;
This commit is contained in:
parent
c2c1e8aac5
commit
84bbe291d1
|
@ -31,19 +31,28 @@ void lovrAudioDestroy() {
|
|||
void lovrAudioUpdate() {
|
||||
int i; Source* source;
|
||||
vec_foreach_rev(&state.sources, source, i) {
|
||||
if (lovrSourceIsStopped(source) && !source->isLooping) {
|
||||
int isStopped = lovrSourceIsStopped(source);
|
||||
ALint processed;
|
||||
alGetSourcei(source->id, AL_BUFFERS_PROCESSED, &processed);
|
||||
|
||||
if (processed) {
|
||||
ALuint buffers[SOURCE_BUFFERS];
|
||||
alSourceUnqueueBuffers(source->id, processed, buffers);
|
||||
lovrSourceStream(source, buffers, processed);
|
||||
if (isStopped) {
|
||||
alSourcePlay(source->id);
|
||||
}
|
||||
} else if (isStopped) {
|
||||
vec_splice(&state.sources, i, 1);
|
||||
lovrRelease(&source->ref);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ALint count;
|
||||
alGetSourcei(source->id, AL_BUFFERS_PROCESSED, &count);
|
||||
if (count > 0) {
|
||||
ALuint buffers[SOURCE_BUFFERS];
|
||||
alSourceUnqueueBuffers(source->id, count, buffers);
|
||||
lovrSourceStream(source, buffers, count);
|
||||
}
|
||||
void lovrAudioAdd(Source* source) {
|
||||
if (!lovrAudioHas(source)) {
|
||||
lovrRetain(&source->ref);
|
||||
vec_push(&state.sources, source);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,9 +71,31 @@ void lovrAudioGetPosition(float* x, float* y, float* z) {
|
|||
alGetListener3f(AL_POSITION, x, y, z);
|
||||
}
|
||||
|
||||
void lovrAudioPlay(Source* source) {
|
||||
lovrRetain(&source->ref);
|
||||
vec_push(&state.sources, source);
|
||||
int lovrAudioHas(Source* source) {
|
||||
int index;
|
||||
vec_find(&state.sources, source, index);
|
||||
return index >= 0;
|
||||
}
|
||||
|
||||
void lovrAudioPause() {
|
||||
int i; Source* source;
|
||||
vec_foreach(&state.sources, source, i) {
|
||||
lovrSourcePause(source);
|
||||
}
|
||||
}
|
||||
|
||||
void lovrAudioResume() {
|
||||
int i; Source* source;
|
||||
vec_foreach(&state.sources, source, i) {
|
||||
lovrSourceResume(source);
|
||||
}
|
||||
}
|
||||
|
||||
void lovrAudioRewind() {
|
||||
int i; Source* source;
|
||||
vec_foreach(&state.sources, source, i) {
|
||||
lovrSourceRewind(source);
|
||||
}
|
||||
}
|
||||
|
||||
void lovrAudioSetOrientation(float fx, float fy, float fz, float ux, float uy, float uz) {
|
||||
|
@ -75,3 +106,10 @@ void lovrAudioSetOrientation(float fx, float fy, float fz, float ux, float uy, f
|
|||
void lovrAudioSetPosition(float x, float y, float z) {
|
||||
alListener3f(AL_POSITION, x, y, z);
|
||||
}
|
||||
|
||||
void lovrAudioStop() {
|
||||
int i; Source* source;
|
||||
vec_foreach(&state.sources, source, i) {
|
||||
lovrSourceStop(source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,13 @@ typedef struct {
|
|||
void lovrAudioInit();
|
||||
void lovrAudioDestroy();
|
||||
void lovrAudioUpdate();
|
||||
void lovrAudioAdd(Source* source);
|
||||
void lovrAudioGetOrientation(float* fx, float* fy, float* fz, float* ux, float* uy, float* uz);
|
||||
void lovrAudioGetPosition(float* x, float* y, float* z);
|
||||
void lovrAudioPlay(Source* source);
|
||||
int lovrAudioHas(Source* source);
|
||||
void lovrAudioPause();
|
||||
void lovrAudioResume();
|
||||
void lovrAudioRewind();
|
||||
void lovrAudioSetOrientation(float fx, float fy, float fz, float ux, float uy, float uz);
|
||||
void lovrAudioSetPosition(float x, float y, float z);
|
||||
void lovrAudioStop();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "audio/source.h"
|
||||
#include "audio/audio.h"
|
||||
#include "loaders/source.h"
|
||||
|
||||
static ALenum lovrSourceGetState(Source* source) {
|
||||
|
@ -111,7 +110,6 @@ void lovrSourcePlay(Source* source) {
|
|||
|
||||
lovrSourceStream(source, source->buffers, SOURCE_BUFFERS);
|
||||
alSourcePlay(source->id);
|
||||
lovrAudioPlay(source);
|
||||
}
|
||||
|
||||
void lovrSourceResume(Source* source) {
|
||||
|
|
|
@ -10,8 +10,12 @@ const luaL_Reg lovrAudio[] = {
|
|||
{ "getOrientation", l_lovrAudioGetOrientation },
|
||||
{ "getPosition", l_lovrAudioGetPosition },
|
||||
{ "newSource", l_lovrAudioNewSource },
|
||||
{ "pause", l_lovrAudioPause },
|
||||
{ "resume", l_lovrAudioResume },
|
||||
{ "rewind", l_lovrAudioRewind },
|
||||
{ "setOrientation", l_lovrAudioSetOrientation },
|
||||
{ "setPosition", l_lovrAudioSetPosition },
|
||||
{ "stop", l_lovrAudioStop },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
@ -71,6 +75,21 @@ int l_lovrAudioNewSource(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrAudioPause(lua_State* L) {
|
||||
lovrAudioPause();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrAudioResume(lua_State* L) {
|
||||
lovrAudioResume();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrAudioRewind(lua_State* L) {
|
||||
lovrAudioRewind();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrAudioSetOrientation(lua_State* L) {
|
||||
float fx = luaL_checknumber(L, 1);
|
||||
float fy = luaL_checknumber(L, 2);
|
||||
|
@ -89,3 +108,8 @@ int l_lovrAudioSetPosition(lua_State* L) {
|
|||
lovrAudioSetPosition(x, y, z);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrAudioStop(lua_State* L) {
|
||||
lovrAudioStop();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,5 +11,9 @@ int l_lovrAudioUpdate(lua_State* L);
|
|||
int l_lovrAudioGetOrientation(lua_State* L);
|
||||
int l_lovrAudioGetPosition(lua_State* L);
|
||||
int l_lovrAudioNewSource(lua_State* L);
|
||||
int l_lovrAudioPause(lua_State* L);
|
||||
int l_lovrAudioResume(lua_State* L);
|
||||
int l_lovrAudioRewind(lua_State* L);
|
||||
int l_lovrAudioSetOrientation(lua_State* L);
|
||||
int l_lovrAudioSetPosition(lua_State* L);
|
||||
int l_lovrAudioStop(lua_State* L);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "lovr/types/source.h"
|
||||
#include "lovr/audio.h"
|
||||
#include "audio/audio.h"
|
||||
|
||||
const luaL_Reg lovrSource[] = {
|
||||
{ "getBitDepth", l_lovrSourceGetBitDepth },
|
||||
|
@ -117,7 +118,9 @@ int l_lovrSourcePause(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrSourcePlay(lua_State* L) {
|
||||
lovrSourcePlay(luax_checktype(L, 1, Source));
|
||||
Source* source = luax_checktype(L, 1, Source);
|
||||
lovrSourcePlay(source);
|
||||
lovrAudioAdd(source);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue