diff options
author | Chris Robinson <[email protected]> | 2011-10-01 06:19:55 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2011-10-01 06:19:55 -0700 |
commit | 8b2e1fdd9a53d0145496b27f7ea0014124ce0d4a (patch) | |
tree | 3e574feaf4fec63825958c95782f9275525f5636 /OpenAL32/alBuffer.c | |
parent | c99b32a8ecbab7aa332d511cf61a412179c0f983 (diff) |
Add buffer properties to get the internal format, and the length in bytes, samples, and seconds
The provided buffer lengths correspond to the source offsets, in that the byte
length specifies the end of the byte offset (ie, when the buffer is used for a
static source, the offset will range between 0 (inclusive) and the byte length
(exclusive)). Although an application could use the AL_SIZE, AL_CHANNELS,
AL_BITS, and AL_FREQUENCY properties to find the length in samples and seconds,
the byte length cannot be reliably calculated this way.
Diffstat (limited to 'OpenAL32/alBuffer.c')
-rw-r--r-- | OpenAL32/alBuffer.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 1fa61f4c..768cc213 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -828,6 +828,7 @@ AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum eParam, ALfloat *pf { ALCcontext *pContext; ALCdevice *device; + ALbuffer *pBuffer; pContext = GetContextRef(); if(!pContext) return; @@ -835,12 +836,20 @@ AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum eParam, ALfloat *pf device = pContext->Device; if(!pflValue) alSetError(pContext, AL_INVALID_VALUE); - else if(LookupBuffer(device, buffer) == NULL) + else if((pBuffer=LookupBuffer(device, buffer)) == NULL) alSetError(pContext, AL_INVALID_NAME); else { switch(eParam) { + case AL_SEC_LENGTH: + ReadLock(&pBuffer->lock); + *pflValue = (pBuffer->size / + FrameSizeFromFmt(pBuffer->FmtChannels, pBuffer->FmtType)) / + (ALfloat)pBuffer->Frequency; + ReadUnlock(&pBuffer->lock); + break; + default: alSetError(pContext, AL_INVALID_ENUM); break; @@ -883,6 +892,13 @@ AL_API void AL_APIENTRY alGetBufferfv(ALuint buffer, ALenum eParam, ALfloat* pfl ALCcontext *pContext; ALCdevice *device; + switch(eParam) + { + case AL_SEC_LENGTH: + alGetBufferf(buffer, eParam, pflValues); + return; + } + pContext = GetContextRef(); if(!pContext) return; @@ -939,6 +955,21 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plVa *plValue = pBuffer->size; break; + case AL_INTERNAL_FORMAT: + *plValue = pBuffer->Format; + break; + + case AL_BYTE_LENGTH: + *plValue = pBuffer->OriginalSize; + break; + + case AL_SAMPLE_LENGTH: + ReadLock(&pBuffer->lock); + *plValue = pBuffer->size / + FrameSizeFromFmt(pBuffer->FmtChannels, pBuffer->FmtType); + ReadUnlock(&pBuffer->lock); + break; + default: alSetError(pContext, AL_INVALID_ENUM); break; @@ -988,6 +1019,9 @@ AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum eParam, ALint* plVal case AL_BITS: case AL_CHANNELS: case AL_SIZE: + case AL_INTERNAL_FORMAT: + case AL_BYTE_LENGTH: + case AL_SAMPLE_LENGTH: alGetBufferi(buffer, eParam, plValues); return; } @@ -2038,6 +2072,7 @@ static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei f ALBuf->Frequency = freq; ALBuf->FmtChannels = DstChannels; ALBuf->FmtType = DstType; + ALBuf->Format = NewFormat; ALBuf->LoopStart = 0; ALBuf->LoopEnd = (ALsizei)(newsize / NewChannels / NewBytes); |