diff options
author | Chris Robinson <[email protected]> | 2012-01-25 19:32:10 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-01-25 19:32:10 -0800 |
commit | b4ba83ec34f1467b9e37c9e735f4a3a5ddc100e9 (patch) | |
tree | e1489e03afd09ba115249300f13969b687ff3d95 /OpenAL32 | |
parent | d807c4bf8778a1db47015c7b0ff32a8d02a84a8d (diff) |
Avoid a bit of code duplication
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/alBuffer.c | 99 |
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; |