diff options
author | Chris Robinson <[email protected]> | 2010-11-28 12:53:35 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-11-28 12:53:35 -0800 |
commit | c41e893361f4c912b8c6c4c703bf7590c957318d (patch) | |
tree | ddb037cd77a117c5c7d0ce2c3b31fbb8d992569d /OpenAL32 | |
parent | 2fd8d6916bae6b681f065e5dfe1f962641f41533 (diff) |
Don't store the internal format in the buffer
The type and channel config are good enough
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alBuffer.h | 77 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 15 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 12 |
3 files changed, 83 insertions, 21 deletions
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h index 7d5b4fc2..c3835f97 100644 --- a/OpenAL32/Include/alBuffer.h +++ b/OpenAL32/Include/alBuffer.h @@ -30,6 +30,41 @@ enum SrcFmtChannels { void DecomposeInputFormat(ALenum format, enum SrcFmtType *type, enum SrcFmtChannels *order); +static __inline ALuint BytesFromSrcFmt(enum SrcFmtType type) +{ + switch(type) + { + case SrcFmtByte: return sizeof(ALbyte); + case SrcFmtUByte: return sizeof(ALubyte); + case SrcFmtShort: return sizeof(ALshort); + case SrcFmtUShort: return sizeof(ALushort); + case SrcFmtFloat: return sizeof(ALfloat); + case SrcFmtDouble: return sizeof(ALdouble); + case SrcFmtMulaw: return sizeof(ALubyte); + } + return 0; +} +static __inline ALuint ChannelsFromSrcFmt(enum SrcFmtChannels chans) +{ + switch(chans) + { + case SrcFmtMono: return 1; + case SrcFmtStereo: return 2; + case SrcFmtRear: return 2; + case SrcFmtQuad: return 4; + case SrcFmtX51: return 6; + case SrcFmtX61: return 7; + case SrcFmtX71: return 8; + } + return 0; +} +static __inline ALuint FrameSizeFromSrcFmt(enum SrcFmtType type, + enum SrcFmtChannels chans) +{ + return BytesFromSrcFmt(type) * ChannelsFromSrcFmt(chans); +} + + /* Storable formats */ enum FmtType { FmtUByte, @@ -40,8 +75,8 @@ enum FmtType { enum FmtChannels { FmtMono, FmtStereo, - FmtQuad, FmtRear, + FmtQuad, Fmt51ChanWFX, Fmt61ChanWFX, Fmt71ChanWFX, @@ -49,25 +84,53 @@ enum FmtChannels { void DecomposeFormat(ALenum format, enum FmtType *type, enum FmtChannels *order); +static __inline ALuint BytesFromFmt(enum FmtType type) +{ + switch(type) + { + case FmtUByte: return sizeof(ALubyte); + case FmtShort: return sizeof(ALshort); + case FmtFloat: return sizeof(ALfloat); + case FmtDouble: return sizeof(ALdouble); + } + return 0; +} +static __inline ALuint ChannelsFromFmt(enum FmtChannels chans) +{ + switch(chans) + { + case FmtMono: return 1; + case FmtStereo: return 2; + case FmtRear: return 2; + case FmtQuad: return 4; + case Fmt51ChanWFX: return 6; + case Fmt61ChanWFX: return 7; + case Fmt71ChanWFX: return 8; + } + return 0; +} +static __inline ALuint FrameSizeFromFmt(enum FmtType type, enum FmtChannels chans) +{ + return BytesFromFmt(type) * ChannelsFromFmt(chans); +} + typedef struct ALbuffer { ALvoid *data; ALsizei size; - ALenum format; - ALenum eOriginalFormat; - ALsizei frequency; + ALsizei frequency; + enum FmtType FmtType; + enum FmtChannels FmtChannels; + ALenum eOriginalFormat; ALsizei OriginalSize; ALsizei OriginalAlign; ALsizei LoopStart; ALsizei LoopEnd; - enum FmtType FmtType; - enum FmtChannels FmtChannels; - ALuint refcount; // Number of sources using this buffer (deletion can only occur when this is 0) // Index to itself diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 7f08fd59..db705977 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -373,7 +373,6 @@ AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid ALBuf->data = temp; ConvertDataIMA4(ALBuf->data, data, Channels, newsize/(65*Channels*NewBytes)); - ALBuf->format = NewFormat; ALBuf->eOriginalFormat = format; ALBuf->size = newsize; ALBuf->frequency = freq; @@ -474,7 +473,7 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const case AL_FORMAT_71CHN32: case AL_FORMAT_71CHN_MULAW: { ALuint OldBytes = aluBytesFromFormat(format); - ALuint Bytes = aluBytesFromFormat(ALBuf->format); + ALuint Bytes = BytesFromFmt(ALBuf->FmtType); enum SrcFmtChannels SrcChannels; enum SrcFmtType SrcType; @@ -489,8 +488,8 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer,ALenum format,const case AL_FORMAT_MONO_IMA4: case AL_FORMAT_STEREO_IMA4: { - ALuint Channels = aluChannelsFromFormat(ALBuf->format); - ALuint Bytes = aluBytesFromFormat(ALBuf->format); + ALuint Channels = ChannelsFromFmt(ALBuf->FmtChannels); + ALuint Bytes = BytesFromFmt(ALBuf->FmtType); /* offset -> byte offset, length -> block count */ offset /= 36; @@ -680,7 +679,8 @@ AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum eParam, const ALint* pl alSetError(pContext, AL_INVALID_VALUE); else { - ALint maxlen = ALBuf->size / aluFrameSizeFromFormat(ALBuf->format); + ALint maxlen = ALBuf->size / + FrameSizeFromFmt(ALBuf->FmtType, ALBuf->FmtChannels); if(plValues[0] > maxlen || plValues[1] > maxlen) alSetError(pContext, AL_INVALID_VALUE); else @@ -805,11 +805,11 @@ AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plVa break; case AL_BITS: - *plValue = aluBytesFromFormat(pBuffer->format) * 8; + *plValue = BytesFromFmt(pBuffer->FmtType) * 8; break; case AL_CHANNELS: - *plValue = aluChannelsFromFormat(pBuffer->format); + *plValue = ChannelsFromFmt(pBuffer->FmtChannels); break; case AL_SIZE: @@ -1219,7 +1219,6 @@ static ALenum LoadData(ALbuffer *ALBuf, const ALvoid *data, ALsizei size, ALuint ConvertData(ALBuf->data, DstType, data, SrcType, newsize/NewBytes); } - ALBuf->format = NewFormat; ALBuf->eOriginalFormat = OrigFormat; ALBuf->size = newsize; ALBuf->frequency = freq; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 70d197ff..34d33a38 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -1819,8 +1819,8 @@ static ALvoid GetSourceOffset(ALsource *Source, ALenum name, ALdouble *offset, A // Get Current Buffer Size and frequency (in milliseconds) BufferFreq = (ALfloat)Buffer->frequency; OriginalFormat = Buffer->eOriginalFormat; - Channels = aluChannelsFromFormat(Buffer->format); - Bytes = aluBytesFromFormat(Buffer->format); + Channels = ChannelsFromFmt(Buffer->FmtChannels); + Bytes = BytesFromFmt(Buffer->FmtType); // Get Current BytesPlayed (NOTE : This is the byte offset into the *current* buffer) readPos = Source->position * Channels * Bytes; @@ -1943,7 +1943,7 @@ static ALboolean ApplyOffset(ALsource *Source) // SW Mixer Positions are in Samples Source->position = (lByteOffset - lTotalBufferSize) / - aluFrameSizeFromFormat(Buffer->format); + FrameSizeFromFmt(Buffer->FmtType, Buffer->FmtChannels); return AL_TRUE; } @@ -1995,17 +1995,17 @@ static ALint GetByteOffset(ALsource *Source) case AL_BYTE_OFFSET: // Take into consideration the original format ByteOffset = FramesFromBytes(Source->lOffset, Buffer->eOriginalFormat); - ByteOffset *= aluFrameSizeFromFormat(Buffer->format); + ByteOffset *= FrameSizeFromFmt(Buffer->FmtType, Buffer->FmtChannels); break; case AL_SAMPLE_OFFSET: - ByteOffset = Source->lOffset * aluBytesFromFormat(Buffer->format); + ByteOffset = Source->lOffset * BytesFromFmt(Buffer->FmtType); break; case AL_SEC_OFFSET: // Note - lOffset is internally stored as Milliseconds ByteOffset = (ALint)(Source->lOffset / 1000.0 * Buffer->frequency); - ByteOffset *= aluBytesFromFormat(Buffer->format); + ByteOffset *= BytesFromFmt(Buffer->FmtType); break; } // Clear Offset |