aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-10-01 06:19:55 -0700
committerChris Robinson <[email protected]>2011-10-01 06:19:55 -0700
commit8b2e1fdd9a53d0145496b27f7ea0014124ce0d4a (patch)
tree3e574feaf4fec63825958c95782f9275525f5636
parentc99b32a8ecbab7aa332d511cf61a412179c0f983 (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.
-rw-r--r--OpenAL32/Include/alBuffer.h1
-rw-r--r--OpenAL32/Include/alMain.h6
-rw-r--r--OpenAL32/alBuffer.c37
-rw-r--r--OpenAL32/alExtension.c4
4 files changed, 47 insertions, 1 deletions
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index 7c6bc5b9..d68a4e36 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -72,6 +72,7 @@ typedef struct ALbuffer
ALsizei size;
ALsizei Frequency;
+ ALenum Format;
enum FmtChannels FmtChannels;
enum FmtType FmtType;
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 16165aa6..1a771f4b 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -98,6 +98,12 @@ ALC_API void ALC_APIENTRY alcRenderSamplesSOFT(ALCdevice *device, ALCvoid *buffe
#define AL_7POINT1_16 0x1211
#define AL_7POINT1_32F 0x1212
+/* Buffer attributes */
+#define AL_INTERNAL_FORMAT 0x2008
+#define AL_BYTE_LENGTH 0x2009
+#define AL_SAMPLE_LENGTH 0x200A
+#define AL_SEC_LENGTH 0x200B
+
typedef void (AL_APIENTRY*LPALBUFFERSAMPLESSOFT)(ALuint,ALuint,ALenum,ALsizei,ALenum,ALenum,const ALvoid*);
typedef void (AL_APIENTRY*LPALBUFFERSUBSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,const ALvoid*);
typedef void (AL_APIENTRY*LPALGETBUFFERSAMPLESSOFT)(ALuint,ALsizei,ALsizei,ALenum,ALenum,ALvoid*);
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);
diff --git a/OpenAL32/alExtension.c b/OpenAL32/alExtension.c
index c7214c13..3309338e 100644
--- a/OpenAL32/alExtension.c
+++ b/OpenAL32/alExtension.c
@@ -190,6 +190,10 @@ static const ALenums enumeration[] = {
{ "AL_BITS", AL_BITS },
{ "AL_CHANNELS", AL_CHANNELS },
{ "AL_SIZE", AL_SIZE },
+ { "AL_INTERNAL_FORMAT", AL_INTERNAL_FORMAT },
+ { "AL_BYTE_LENGTH", AL_BYTE_LENGTH },
+ { "AL_SAMPLE_LENGTH", AL_SAMPLE_LENGTH },
+ { "AL_SEC_LENGTH", AL_SEC_LENGTH },
// Buffer States (not supported yet)
{ "AL_UNUSED", AL_UNUSED },