diff options
author | Chris Robinson <[email protected]> | 2011-10-03 10:07:50 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-10-04 02:08:45 -0700 |
commit | 11caba9807550a01ec5b81f50a6c744b3506115d (patch) | |
tree | 46f060fbea6f49ac1e8c269ee55ce61f6aa8cc52 /OpenAL32/alBuffer.c | |
parent | 35b4b31d57205f0f358202d9e41b594b9465b22b (diff) |
Use sample frames when handling the buffer length
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r-- | OpenAL32/alBuffer.c | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 32cbbbcb..083a2fc1 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -550,14 +550,12 @@ AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer, else { ALuint FrameSize; - ALsizei FrameCount; WriteLock(&ALBuf->lock); FrameSize = FrameSizeFromFmt(ALBuf->FmtChannels, ALBuf->FmtType); - FrameCount = ALBuf->size / FrameSize; if(channels != (ALenum)ALBuf->FmtChannels) alSetError(Context, AL_INVALID_ENUM); - else if(offset > FrameCount || samples > FrameCount-offset) + else if(offset > ALBuf->SampleLen || samples > ALBuf->SampleLen-offset) alSetError(Context, AL_INVALID_VALUE); else if(type == UserFmtIMA4 && (samples%65) != 0) alSetError(Context, AL_INVALID_VALUE); @@ -598,14 +596,12 @@ AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer, else { ALuint FrameSize; - ALsizei FrameCount; ReadLock(&ALBuf->lock); FrameSize = FrameSizeFromFmt(ALBuf->FmtChannels, ALBuf->FmtType); - FrameCount = ALBuf->size / FrameSize; if(channels != (ALenum)ALBuf->FmtChannels) alSetError(Context, AL_INVALID_ENUM); - else if(offset > FrameCount || samples > FrameCount-offset) + else if(offset > ALBuf->SampleLen || samples > ALBuf->SampleLen-offset) alSetError(Context, AL_INVALID_VALUE); else if(type == UserFmtIMA4 && (samples%65) != 0) alSetError(Context, AL_INVALID_VALUE); @@ -804,20 +800,13 @@ AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum eParam, const ALint* pl WriteLock(&ALBuf->lock); if(ALBuf->ref != 0) alSetError(pContext, AL_INVALID_OPERATION); - else if(plValues[0] < 0 || plValues[1] < 0 || - plValues[0] >= plValues[1] || ALBuf->size == 0) + else if(plValues[0] >= plValues[1] || plValues[0] < 0 || + plValues[1] > ALBuf->SampleLen) alSetError(pContext, AL_INVALID_VALUE); else { - ALint maxlen = ALBuf->size / - FrameSizeFromFmt(ALBuf->FmtChannels, ALBuf->FmtType); - if(plValues[0] > maxlen || plValues[1] > maxlen) - alSetError(pContext, AL_INVALID_VALUE); - else - { - ALBuf->LoopStart = plValues[0]; - ALBuf->LoopEnd = plValues[1]; - } + ALBuf->LoopStart = plValues[0]; + ALBuf->LoopEnd = plValues[1]; } WriteUnlock(&ALBuf->lock); break; @@ -852,10 +841,8 @@ AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum eParam, ALfloat *pf { case AL_SEC_LENGTH: ReadLock(&pBuffer->lock); - if(pBuffer->size != 0) - *pflValue = (pBuffer->size / - FrameSizeFromFmt(pBuffer->FmtChannels, pBuffer->FmtType)) / - (ALfloat)pBuffer->Frequency; + if(pBuffer->SampleLen != 0) + *pflValue = pBuffer->SampleLen / (ALfloat)pBuffer->Frequency; else *pflValue = 0.0f; ReadUnlock(&pBuffer->lock); @@ -963,7 +950,10 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plVa break; case AL_SIZE: - *plValue = pBuffer->size; + ReadLock(&pBuffer->lock); + *plValue = pBuffer->SampleLen * + FrameSizeFromFmt(pBuffer->FmtChannels, pBuffer->FmtType); + ReadUnlock(&pBuffer->lock); break; case AL_INTERNAL_FORMAT: @@ -975,13 +965,7 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plVa break; case AL_SAMPLE_LENGTH: - ReadLock(&pBuffer->lock); - if(pBuffer->size != 0) - *plValue = pBuffer->size / - FrameSizeFromFmt(pBuffer->FmtChannels, pBuffer->FmtType); - else - *plValue = 0; - ReadUnlock(&pBuffer->lock); + *plValue = pBuffer->SampleLen; break; default: @@ -2028,7 +2012,7 @@ static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei f return AL_OUT_OF_MEMORY; } ALBuf->data = temp; - ALBuf->size = (ALsizei)newsize; + ALBuf->SampleLen = frames*65; if(data != NULL) ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames); @@ -2061,7 +2045,7 @@ static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei f return AL_OUT_OF_MEMORY; } ALBuf->data = temp; - ALBuf->size = (ALsizei)newsize; + ALBuf->SampleLen = frames; if(data != NULL) ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames); @@ -2086,7 +2070,7 @@ static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei f ALBuf->Format = NewFormat; ALBuf->LoopStart = 0; - ALBuf->LoopEnd = (ALsizei)(newsize / NewChannels / NewBytes); + ALBuf->LoopEnd = ALBuf->SampleLen; WriteUnlock(&ALBuf->lock); return AL_NO_ERROR; |