diff options
-rw-r--r-- | Alc/ALu.c | 8 | ||||
-rw-r--r-- | Alc/mixer.c | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alBuffer.h | 77 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 15 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 12 |
5 files changed, 88 insertions, 26 deletions
@@ -114,8 +114,8 @@ ALvoid CalcNonAttnSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALbuffer *ALBuffer; if((ALBuffer=BufferListItem->buffer) != NULL) { - ALint maxstep = STACK_DATA_SIZE / - aluFrameSizeFromFormat(ALBuffer->format); + ALint maxstep = STACK_DATA_SIZE / FrameSizeFromFmt(ALBuffer->FmtType, + ALBuffer->FmtChannels); maxstep -= ResamplerPadding[ALSource->Resampler] + ResamplerPrePadding[ALSource->Resampler] + 1; maxstep = min(maxstep, INT_MAX>>FRACTIONBITS); @@ -592,8 +592,8 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) ALbuffer *ALBuffer; if((ALBuffer=BufferListItem->buffer) != NULL) { - ALint maxstep = STACK_DATA_SIZE / - aluFrameSizeFromFormat(ALBuffer->format); + ALint maxstep = STACK_DATA_SIZE / FrameSizeFromFmt(ALBuffer->FmtType, + ALBuffer->FmtChannels); maxstep -= ResamplerPadding[ALSource->Resampler] + ResamplerPrePadding[ALSource->Resampler] + 1; maxstep = min(maxstep, INT_MAX>>FRACTIONBITS); diff --git a/Alc/mixer.c b/Alc/mixer.c index ecf3d062..76ae9d86 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -749,9 +749,9 @@ ALvoid MixSource(ALsource *Source, ALCdevice *Device, ALuint SamplesToDo) const ALbuffer *ALBuffer; if((ALBuffer=BufferListItem->buffer) != NULL) { - FrameSize = aluFrameSizeFromFormat(ALBuffer->format); FmtChannels = ALBuffer->FmtChannels; FmtType = ALBuffer->FmtType; + FrameSize = FrameSizeFromFmt(FmtType, FmtChannels); break; } BufferListItem = BufferListItem->next; 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 |