From d7f1262e20cf11969c17efb62d12004cba417d49 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Fri, 2 May 2014 11:31:12 -0300 Subject: [PATCH] Query the Decoder instead of the current OpenAL buffer when getting the sample rate for calculations in streaming audio Sources. Some OpenAL implementations return 0 for alGetSourcei(source, AL_BUFFER) if the source isn't static, which eventually results in returning 0 when querying the buffer's sample rate. --- src/modules/audio/openal/Source.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/modules/audio/openal/Source.cpp b/src/modules/audio/openal/Source.cpp index e9ef1a434..520edb7bb 100644 --- a/src/modules/audio/openal/Source.cpp +++ b/src/modules/audio/openal/Source.cpp @@ -255,10 +255,7 @@ bool Source::update() alGetSourcef(source, AL_SAMPLE_OFFSET, &curOffsetSamples); - ALint b; - alGetSourcei(source, AL_BUFFER, &b); - int freq; - alGetBufferi(b, AL_FREQUENCY, &freq); + int freq = decoder->getSampleRate(); curOffsetSecs = curOffsetSamples / freq; // Get a free buffer. @@ -334,11 +331,7 @@ void Source::seekAtomic(float offset, void *unit) if (type == TYPE_STREAM) { offsetSamples = offset; - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offset /= freq; + offset /= decoder->getSampleRate(); offsetSeconds = offset; decoder->seek(offset); } @@ -353,11 +346,7 @@ void Source::seekAtomic(float offset, void *unit) { offsetSeconds = offset; decoder->seek(offset); - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offsetSamples = offset*freq; + offsetSamples = offset * decoder->getSampleRate(); } else { @@ -399,11 +388,7 @@ float Source::tellAtomic(void *unit) const default: { alGetSourcef(source, AL_SAMPLE_OFFSET, &offset); - ALint buffer; - alGetSourcei(source, AL_BUFFER, &buffer); - int freq; - alGetBufferi(buffer, AL_FREQUENCY, &freq); - offset /= freq; + offset /= decoder->getSampleRate(); if (type == TYPE_STREAM) offset += offsetSeconds; } break;