Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/lib/libopenal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,9 +1453,9 @@ var LibraryOpenAL = {
var srcLen = AL.sourceDuration(src);
if (srcLen > 0.0) {
var frequency;
for (var bufId in src.bufQueue) {
if (bufId) {
frequency = src.bufQueue[bufId].frequency;
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
frequency = buf.frequency;
break;
}
}
Expand All @@ -1475,9 +1475,8 @@ var LibraryOpenAL = {
var srcLen = AL.sourceDuration(src);
if (srcLen > 0.0) {
var bytesPerSec;
for (var bufId in src.bufQueue) {
if (bufId) {
var buf = src.bufQueue[bufId];
for (var buf of src.bufQueue) {
if (buf.id !== 0) {
bytesPerSec = buf.frequency * buf.bytesPerSample * buf.channels;
break;
}
Expand Down
27 changes: 26 additions & 1 deletion test/openal/test_openal_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
ALCdevice* device = NULL;
ALCcontext* context = NULL;

void test_offsets_with_zero_buffer(void) {
// Test AL_SAMPLE_OFFSET and AL_BYTE_OFFSET when buffer 0 is queued before a real buffer
ALuint buf = 0;
alGenBuffers(1, &buf);
char dummy_data[2000] = {0};
alBufferData(buf, AL_FORMAT_MONO16, dummy_data, sizeof(dummy_data), 44100);

ALuint src = 0;
alGenSources(1, &src);

ALuint bufs[2] = {0, buf};
alSourceQueueBuffers(src, 2, bufs);
assert(alGetError() == AL_NO_ERROR);

alSourcei(src, AL_SAMPLE_OFFSET, 100);
assert(alGetError() == AL_NO_ERROR);

alSourcei(src, AL_BYTE_OFFSET, 200);
assert(alGetError() == AL_NO_ERROR);

alDeleteSources(1, &src);
alDeleteBuffers(1, &buf);
}

int main(int argc, char* argv[]) {
ALCboolean ret;

Expand All @@ -39,11 +63,12 @@ int main(int argc, char* argv[]) {
// Check that the error is reset after reading it.
assert(alGetError() == AL_NO_ERROR);

test_offsets_with_zero_buffer();

ret = alcMakeContextCurrent(NULL);
assert(ret == ALC_TRUE);

alcDestroyContext(context);
alcCloseDevice(device);
return 0;
}

Loading