aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/alBuffer.c99
1 files changed, 29 insertions, 70 deletions
diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c
index f56ca5c7..a803eea7 100644
--- a/OpenAL32/alBuffer.c
+++ b/OpenAL32/alBuffer.c
@@ -1974,101 +1974,60 @@ static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei f
ALuint64 newsize;
ALvoid *temp;
- WriteLock(&ALBuf->lock);
- if(ALBuf->ref != 0)
- {
- WriteUnlock(&ALBuf->lock);
- return AL_INVALID_OPERATION;
- }
-
if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE ||
(long)SrcChannels != (long)DstChannels)
- {
- WriteUnlock(&ALBuf->lock);
return AL_INVALID_ENUM;
- }
NewChannels = ChannelsFromFmt(DstChannels);
NewBytes = BytesFromFmt(DstType);
+ newsize = frames;
if(SrcType == UserFmtIMA4)
- {
- ALuint OrigChannels = ChannelsFromUserFmt(SrcChannels);
-
- newsize = frames;
newsize *= 65;
- newsize *= NewBytes;
- newsize *= NewChannels;
- if(newsize > INT_MAX)
- {
- WriteUnlock(&ALBuf->lock);
- return AL_OUT_OF_MEMORY;
- }
+ newsize *= NewBytes;
+ newsize *= NewChannels;
+ if(newsize > INT_MAX)
+ return AL_OUT_OF_MEMORY;
- temp = realloc(ALBuf->data, (size_t)newsize);
- if(!temp && newsize)
- {
- WriteUnlock(&ALBuf->lock);
- return AL_OUT_OF_MEMORY;
- }
- ALBuf->data = temp;
- ALBuf->SampleLen = frames*65;
-
- if(data != NULL)
- ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames);
-
- if(storesrc)
- {
- ALBuf->OriginalChannels = SrcChannels;
- ALBuf->OriginalType = SrcType;
- ALBuf->OriginalSize = frames * 36 * OrigChannels;
- }
- }
- else
+ WriteLock(&ALBuf->lock);
+ if(ALBuf->ref != 0)
{
- ALuint OrigBytes = BytesFromUserFmt(SrcType);
- ALuint OrigChannels = ChannelsFromUserFmt(SrcChannels);
-
- newsize = frames;
- newsize *= NewBytes;
- newsize *= NewChannels;
- if(newsize > INT_MAX)
- {
- WriteUnlock(&ALBuf->lock);
- return AL_OUT_OF_MEMORY;
- }
+ WriteUnlock(&ALBuf->lock);
+ return AL_INVALID_OPERATION;
+ }
- temp = realloc(ALBuf->data, (size_t)newsize);
- if(!temp && newsize)
- {
- WriteUnlock(&ALBuf->lock);
- return AL_OUT_OF_MEMORY;
- }
- ALBuf->data = temp;
- ALBuf->SampleLen = frames;
+ temp = realloc(ALBuf->data, (size_t)newsize);
+ if(!temp && newsize)
+ {
+ WriteUnlock(&ALBuf->lock);
+ return AL_OUT_OF_MEMORY;
+ }
+ ALBuf->data = temp;
- if(data != NULL)
- ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames);
+ if(data != NULL)
+ ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames);
- if(storesrc)
- {
- ALBuf->OriginalChannels = SrcChannels;
- ALBuf->OriginalType = SrcType;
- ALBuf->OriginalSize = frames * OrigBytes * OrigChannels;
- }
+ if(storesrc)
+ {
+ ALBuf->OriginalChannels = SrcChannels;
+ ALBuf->OriginalType = SrcType;
+ ALBuf->OriginalSize = frames * ((SrcType == UserFmtIMA4) ? 36 :
+ BytesFromUserFmt(SrcType)) *
+ ChannelsFromUserFmt(SrcChannels);
}
-
- if(!storesrc)
+ else
{
ALBuf->OriginalChannels = DstChannels;
ALBuf->OriginalType = DstType;
ALBuf->OriginalSize = frames * NewBytes * NewChannels;
}
+
ALBuf->Frequency = freq;
ALBuf->FmtChannels = DstChannels;
ALBuf->FmtType = DstType;
ALBuf->Format = NewFormat;
+ ALBuf->SampleLen = frames * ((SrcType == UserFmtIMA4) ? 65 : 1);
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = ALBuf->SampleLen;