aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-11-24 10:07:48 -0800
committerChris Robinson <[email protected]>2018-11-24 10:07:48 -0800
commitb508a760c88e8af6e852561dd7cf50edd7c601b9 (patch)
treec384b90488c0eb03baf0f0918f88a5205aa84bf5 /OpenAL32
parent505e535655cb12af9a0d4dc8b2cae9a0db03e34e (diff)
Use a normal vector to store buffer data
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alBuffer.h43
-rw-r--r--OpenAL32/alBuffer.cpp30
2 files changed, 33 insertions, 40 deletions
diff --git a/OpenAL32/Include/alBuffer.h b/OpenAL32/Include/alBuffer.h
index a99c06fc..54c17670 100644
--- a/OpenAL32/Include/alBuffer.h
+++ b/OpenAL32/Include/alBuffer.h
@@ -7,6 +7,7 @@
#include "inprogext.h"
#include "atomic.h"
+#include "vector.h"
/* User formats */
@@ -88,37 +89,37 @@ inline ALsizei FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
}
-typedef struct ALbuffer {
- ALvoid *data;
+struct ALbuffer {
+ al::vector<ALbyte,16> mData;
- ALsizei Frequency;
- ALbitfieldSOFT Access;
- ALsizei SampleLen;
+ ALsizei Frequency{0};
+ ALbitfieldSOFT Access{0u};
+ ALsizei SampleLen{0};
- enum FmtChannels FmtChannels;
- enum FmtType FmtType;
- ALsizei BytesAlloc;
+ enum FmtChannels FmtChannels{};
+ enum FmtType FmtType{};
+ ALsizei BytesAlloc{0};
- enum UserFmtType OriginalType;
- ALsizei OriginalSize;
- ALsizei OriginalAlign;
+ enum UserFmtType OriginalType{};
+ ALsizei OriginalSize{0};
+ ALsizei OriginalAlign{0};
- ALsizei LoopStart;
- ALsizei LoopEnd;
+ ALsizei LoopStart{0};
+ ALsizei LoopEnd{0};
- ATOMIC(ALsizei) UnpackAlign;
- ATOMIC(ALsizei) PackAlign;
+ std::atomic<ALsizei> UnpackAlign{0};
+ std::atomic<ALsizei> PackAlign{0};
- ALbitfieldSOFT MappedAccess;
- ALsizei MappedOffset;
- ALsizei MappedSize;
+ ALbitfieldSOFT MappedAccess{0u};
+ ALsizei MappedOffset{0};
+ ALsizei MappedSize{0};
/* Number of times buffer was attached to a source (deletion can only occur when 0) */
- RefCount ref;
+ RefCount ref{0u};
/* Self ID */
- ALuint id;
-} ALbuffer;
+ ALuint id{0};
+};
ALvoid ReleaseALBuffers(ALCdevice *device);
diff --git a/OpenAL32/alBuffer.cpp b/OpenAL32/alBuffer.cpp
index 196dcd22..0580b33a 100644
--- a/OpenAL32/alBuffer.cpp
+++ b/OpenAL32/alBuffer.cpp
@@ -110,8 +110,6 @@ void FreeBuffer(ALCdevice *device, ALbuffer *buffer)
ALsizei lidx = id >> 6;
ALsizei slidx = id & 0x3f;
- al_free(buffer->data);
- buffer->data = nullptr;
buffer->~ALbuffer();
device->BufferList[lidx].FreeMask |= U64(1) << slidx;
@@ -290,41 +288,37 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, U
newsize = (newsize+15) & ~0xf;
if(newsize != ALBuf->BytesAlloc)
{
- void *temp{al_malloc(16, (size_t)newsize)};
- if(UNLIKELY(!temp && newsize))
- SETERR_RETURN(context, AL_OUT_OF_MEMORY,, "Failed to allocate %d bytes of storage",
- newsize);
+ al::vector<ALbyte,16> newdata(newsize);
if((access&AL_PRESERVE_DATA_BIT_SOFT))
{
ALsizei tocopy{std::min(newsize, ALBuf->BytesAlloc)};
- if(tocopy > 0) memcpy(temp, ALBuf->data, tocopy);
+ std::copy_n(ALBuf->mData.begin(), tocopy, newdata.begin());
}
- al_free(ALBuf->data);
- ALBuf->data = temp;
+ ALBuf->mData = std::move(newdata);
ALBuf->BytesAlloc = newsize;
}
if(SrcType == UserFmtIMA4)
{
assert(DstType == FmtShort);
- if(data != nullptr && ALBuf->data != nullptr)
- Convert_ALshort_ALima4(static_cast<ALshort*>(ALBuf->data),
+ if(data != nullptr && !ALBuf->mData.empty())
+ Convert_ALshort_ALima4(reinterpret_cast<ALshort*>(ALBuf->mData.data()),
static_cast<const ALubyte*>(data), NumChannels, frames, align);
ALBuf->OriginalAlign = align;
}
else if(SrcType == UserFmtMSADPCM)
{
assert(DstType == FmtShort);
- if(data != nullptr && ALBuf->data != nullptr)
- Convert_ALshort_ALmsadpcm(static_cast<ALshort*>(ALBuf->data),
+ if(data != nullptr && !ALBuf->mData.empty())
+ Convert_ALshort_ALmsadpcm(reinterpret_cast<ALshort*>(ALBuf->mData.data()),
static_cast<const ALubyte*>(data), NumChannels, frames, align);
ALBuf->OriginalAlign = align;
}
else
{
assert((long)SrcType == (long)DstType);
- if(data != nullptr && ALBuf->data != nullptr)
- memcpy(ALBuf->data, data, frames*FrameSize);
+ if(data != nullptr && !ALBuf->mData.empty())
+ std::copy_n(static_cast<const ALbyte*>(data), frames*FrameSize, ALBuf->mData.begin());
ALBuf->OriginalAlign = 1;
}
ALBuf->OriginalSize = size;
@@ -601,7 +595,7 @@ AL_API void* AL_APIENTRY alMapBufferSOFT(ALuint buffer, ALsizei offset, ALsizei
offset, length, buffer);
else
{
- void *retval = (ALbyte*)albuf->data + offset;
+ void *retval = albuf->mData.data() + offset;
albuf->MappedAccess = access;
albuf->MappedOffset = offset;
albuf->MappedSize = length;
@@ -730,7 +724,7 @@ AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, cons
offset = offset/byte_align * align * frame_size;
length = length/byte_align * align;
- void *dst = static_cast<ALbyte*>(albuf->data) + offset;
+ void *dst = albuf->mData.data() + offset;
if(srctype == UserFmtIMA4 && albuf->FmtType == FmtShort)
Convert_ALshort_ALima4(static_cast<ALshort*>(dst),
static_cast<const ALubyte*>(data), num_chans, length, align);
@@ -1196,8 +1190,6 @@ ALvoid ReleaseALBuffers(ALCdevice *device)
ALsizei idx = CTZ64(usemask);
ALbuffer *buffer = sublist.Buffers + idx;
- al_free(buffer->data);
- buffer->data = nullptr;
buffer->~ALbuffer();
++leftover;