diff options
author | Anthony Pesch <inolen@gmail.com> | 2013-06-17 18:48:20 -0700 |
---|---|---|
committer | Anthony Pesch <inolen@gmail.com> | 2013-07-30 17:45:32 -0700 |
commit | 4088826095f06ae47a00544434d3db6a9fdf323e (patch) | |
tree | 8cb60e3e12938e43c8fd39436d4f43d8bbe9b770 /tests/openal_buffers.c | |
parent | 9e0d03bde9e08842366e0fd17f1167cf2b4ecca2 (diff) |
- fixed AudioBufferSourceNode start call, pass it an asbsolute time, not relative
- call updateSource when calling alGetSourcei
Diffstat (limited to 'tests/openal_buffers.c')
-rw-r--r-- | tests/openal_buffers.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/tests/openal_buffers.c b/tests/openal_buffers.c index f89a5791..6f51a685 100644 --- a/tests/openal_buffers.c +++ b/tests/openal_buffers.c @@ -11,7 +11,7 @@ #endif #define NUM_BUFFERS 4 -#define BUFFER_SIZE 1024*8 +#define BUFFER_SIZE 1470*10 ALCdevice* device = NULL; ALCcontext* context = NULL; @@ -26,22 +26,43 @@ unsigned int bits = 0; ALenum format = 0; ALuint source = 0; -void cycle(void *arg) { +void iter(void *arg) { ALuint buffer = 0; - ALint numBuffers = 0; + ALint buffersProcessed = 0; + ALint buffersWereQueued = 0; + ALint buffersQueued = 0; + ALint state; - alGetSourcei(source, AL_BUFFERS_PROCESSED, &numBuffers); + alGetSourcei(source, AL_BUFFERS_PROCESSED, &buffersProcessed); - while (offset < size && numBuffers--) { + while (offset < size && buffersProcessed--) { + // unqueue the old buffer and validate the queue length + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersWereQueued); alSourceUnqueueBuffers(source, 1, &buffer); + + assert(alGetError() == AL_NO_ERROR); int len = size - offset; if (len > BUFFER_SIZE) { len = BUFFER_SIZE; } + + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersQueued); + assert(buffersQueued == buffersWereQueued - 1); + + // queue the new buffer and validate the queue length + buffersWereQueued = buffersQueued; alBufferData(buffer, format, &data[offset], len, frequency); + alSourceQueueBuffers(source, 1, &buffer); assert(alGetError() == AL_NO_ERROR); + alGetSourcei(source, AL_BUFFERS_QUEUED, &buffersQueued); + assert(buffersQueued == buffersWereQueued + 1); + + // make sure it's still playing + alGetSourcei(source, AL_SOURCE_STATE, &state); + assert(state == AL_PLAYING); + offset += len; } @@ -50,18 +71,8 @@ void cycle(void *arg) { #ifdef EMSCRIPTEN int result = 0; REPORT_RESULT(); -#else - exit(0); -#endif - } - // Give the JS thread a few ms to breathe. - else { -#ifdef EMSCRIPTEN - emscripten_async_call(cycle, NULL, 10); -#else - usleep(10); - cycle(); #endif + exit(0); } } @@ -165,9 +176,12 @@ int main(int argc, char* argv[]) { // // Cycle and refill the buffers until we're done. // -#ifdef EMSCRIPTEN - emscripten_async_call(cycle, NULL, 10); -#else - cycle(); +#if EMSCRIPTEN + emscripten_set_main_loop(iter, 0, 0); +#else + while (1) { + iter(NULL); + usleep(16); + } #endif } |