Make ALbuffer inherit from BufferStorage
This commit is contained in:
@@ -583,7 +583,7 @@ START_API_FUNC
|
||||
{
|
||||
buffer = LookupBuffer(device, static_cast<ALuint>(value));
|
||||
if(!buffer) SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid buffer ID");
|
||||
if(buffer->mBuffer.mCallback)
|
||||
if(buffer->mCallback)
|
||||
SETERR_RETURN(context, AL_INVALID_OPERATION,,
|
||||
"Callback buffer not valid for effects");
|
||||
|
||||
@@ -596,7 +596,7 @@ START_API_FUNC
|
||||
|
||||
FPUCtl mixer_mode{};
|
||||
auto *state = slot->Effect.State.get();
|
||||
state->setBuffer(device, buffer ? &buffer->mBuffer : nullptr);
|
||||
state->setBuffer(device, buffer);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -878,7 +878,7 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
|
||||
FPUCtl mixer_mode{};
|
||||
State->deviceUpdate(Device);
|
||||
if(Buffer)
|
||||
State->setBuffer(Device, &Buffer->mBuffer);
|
||||
State->setBuffer(Device, Buffer);
|
||||
}
|
||||
|
||||
if(!effect)
|
||||
|
||||
+53
-53
@@ -505,11 +505,11 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
|
||||
if((access&AL_PRESERVE_DATA_BIT_SOFT))
|
||||
{
|
||||
/* Can only preserve data with the same format and alignment. */
|
||||
if UNLIKELY(ALBuf->mBuffer.mChannels != DstChannels || ALBuf->OriginalType != SrcType)
|
||||
if UNLIKELY(ALBuf->mChannels != DstChannels || ALBuf->OriginalType != SrcType)
|
||||
SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched format");
|
||||
if UNLIKELY(ALBuf->OriginalAlign != align)
|
||||
SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched alignment");
|
||||
if(ALBuf->mBuffer.mAmbiOrder != ambiorder)
|
||||
if(ALBuf->mAmbiOrder != ambiorder)
|
||||
SETERR_RETURN(context, AL_INVALID_VALUE,, "Preserving data of mismatched order");
|
||||
}
|
||||
|
||||
@@ -547,55 +547,56 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
|
||||
* use AL_SIZE to try to get the buffer's play length.
|
||||
*/
|
||||
newsize = RoundUp(newsize, 16);
|
||||
if(newsize != ALBuf->mBuffer.mData.size())
|
||||
if(newsize != ALBuf->mData.size())
|
||||
{
|
||||
auto newdata = al::vector<al::byte,16>(newsize, al::byte{});
|
||||
if((access&AL_PRESERVE_DATA_BIT_SOFT))
|
||||
{
|
||||
const size_t tocopy{minz(newdata.size(), ALBuf->mBuffer.mData.size())};
|
||||
std::copy_n(ALBuf->mBuffer.mData.begin(), tocopy, newdata.begin());
|
||||
const size_t tocopy{minz(newdata.size(), ALBuf->mData.size())};
|
||||
std::copy_n(ALBuf->mData.begin(), tocopy, newdata.begin());
|
||||
}
|
||||
newdata.swap(ALBuf->mBuffer.mData);
|
||||
newdata.swap(ALBuf->mData);
|
||||
}
|
||||
|
||||
if(SrcType == UserFmtIMA4)
|
||||
{
|
||||
assert(DstType == FmtShort);
|
||||
if(SrcData != nullptr && !ALBuf->mBuffer.mData.empty())
|
||||
Convert_int16_ima4(reinterpret_cast<int16_t*>(ALBuf->mBuffer.mData.data()), SrcData,
|
||||
if(SrcData != nullptr && !ALBuf->mData.empty())
|
||||
Convert_int16_ima4(reinterpret_cast<int16_t*>(ALBuf->mData.data()), SrcData,
|
||||
NumChannels, frames, align);
|
||||
ALBuf->OriginalAlign = align;
|
||||
}
|
||||
else if(SrcType == UserFmtMSADPCM)
|
||||
{
|
||||
assert(DstType == FmtShort);
|
||||
if(SrcData != nullptr && !ALBuf->mBuffer.mData.empty())
|
||||
Convert_int16_msadpcm(reinterpret_cast<int16_t*>(ALBuf->mBuffer.mData.data()), SrcData,
|
||||
if(SrcData != nullptr && !ALBuf->mData.empty())
|
||||
Convert_int16_msadpcm(reinterpret_cast<int16_t*>(ALBuf->mData.data()), SrcData,
|
||||
NumChannels, frames, align);
|
||||
ALBuf->OriginalAlign = align;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(static_cast<long>(SrcType) == static_cast<long>(DstType));
|
||||
if(SrcData != nullptr && !ALBuf->mBuffer.mData.empty())
|
||||
std::copy_n(SrcData, frames*FrameSize, ALBuf->mBuffer.mData.begin());
|
||||
if(SrcData != nullptr && !ALBuf->mData.empty())
|
||||
std::copy_n(SrcData, frames*FrameSize, ALBuf->mData.begin());
|
||||
ALBuf->OriginalAlign = 1;
|
||||
}
|
||||
ALBuf->OriginalSize = size;
|
||||
ALBuf->OriginalType = SrcType;
|
||||
|
||||
ALBuf->mBuffer.mSampleRate = static_cast<ALuint>(freq);
|
||||
ALBuf->mBuffer.mChannels = DstChannels;
|
||||
ALBuf->mBuffer.mType = DstType;
|
||||
ALBuf->Access = access;
|
||||
ALBuf->mBuffer.mAmbiOrder = ambiorder;
|
||||
|
||||
ALBuf->mBuffer.mCallback = nullptr;
|
||||
ALBuf->mBuffer.mUserData = nullptr;
|
||||
ALBuf->mSampleRate = static_cast<ALuint>(freq);
|
||||
ALBuf->mChannels = DstChannels;
|
||||
ALBuf->mType = DstType;
|
||||
ALBuf->mAmbiOrder = ambiorder;
|
||||
|
||||
ALBuf->mBuffer.mSampleLen = frames;
|
||||
ALBuf->mBuffer.mLoopStart = 0;
|
||||
ALBuf->mBuffer.mLoopEnd = ALBuf->mBuffer.mSampleLen;
|
||||
ALBuf->mCallback = nullptr;
|
||||
ALBuf->mUserData = nullptr;
|
||||
|
||||
ALBuf->mSampleLen = frames;
|
||||
ALBuf->mLoopStart = 0;
|
||||
ALBuf->mLoopEnd = ALBuf->mSampleLen;
|
||||
}
|
||||
|
||||
/** Prepares the buffer to use the specified callback, using the specified format. */
|
||||
@@ -644,24 +645,24 @@ void PrepareCallback(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq,
|
||||
ALBuf->UnpackAmbiOrder : 0};
|
||||
|
||||
al::vector<al::byte,16>(FrameSizeFromFmt(DstChannels, DstType, ambiorder) *
|
||||
size_t{BUFFERSIZE + (MAX_RESAMPLER_PADDING>>1)}).swap(ALBuf->mBuffer.mData);
|
||||
size_t{BUFFERSIZE + (MAX_RESAMPLER_PADDING>>1)}).swap(ALBuf->mData);
|
||||
|
||||
ALBuf->mBuffer.mCallback = callback;
|
||||
ALBuf->mBuffer.mUserData = userptr;
|
||||
ALBuf->mCallback = callback;
|
||||
ALBuf->mUserData = userptr;
|
||||
|
||||
ALBuf->OriginalType = SrcType;
|
||||
ALBuf->OriginalSize = 0;
|
||||
ALBuf->OriginalAlign = 1;
|
||||
|
||||
ALBuf->mBuffer.mSampleRate = static_cast<ALuint>(freq);
|
||||
ALBuf->mBuffer.mChannels = DstChannels;
|
||||
ALBuf->mBuffer.mType = DstType;
|
||||
ALBuf->Access = 0;
|
||||
ALBuf->mBuffer.mAmbiOrder = ambiorder;
|
||||
|
||||
ALBuf->mBuffer.mSampleLen = 0;
|
||||
ALBuf->mBuffer.mLoopStart = 0;
|
||||
ALBuf->mBuffer.mLoopEnd = ALBuf->mBuffer.mSampleLen;
|
||||
ALBuf->mSampleRate = static_cast<ALuint>(freq);
|
||||
ALBuf->mChannels = DstChannels;
|
||||
ALBuf->mType = DstType;
|
||||
ALBuf->mAmbiOrder = ambiorder;
|
||||
|
||||
ALBuf->mSampleLen = 0;
|
||||
ALBuf->mLoopStart = 0;
|
||||
ALBuf->mLoopEnd = ALBuf->mSampleLen;
|
||||
}
|
||||
|
||||
|
||||
@@ -922,7 +923,7 @@ START_API_FUNC
|
||||
offset, length, buffer);
|
||||
else
|
||||
{
|
||||
void *retval{albuf->mBuffer.mData.data() + offset};
|
||||
void *retval{albuf->mData.data() + offset};
|
||||
albuf->MappedAccess = access;
|
||||
albuf->MappedOffset = offset;
|
||||
albuf->MappedSize = length;
|
||||
@@ -1016,15 +1017,14 @@ START_API_FUNC
|
||||
ALuint align{SanitizeAlignment(usrfmt->type, unpack_align)};
|
||||
if UNLIKELY(align < 1)
|
||||
context->setError(AL_INVALID_VALUE, "Invalid unpack alignment %u", unpack_align);
|
||||
else if UNLIKELY(long{usrfmt->channels} != long{albuf->mBuffer.mChannels}
|
||||
else if UNLIKELY(long{usrfmt->channels} != long{albuf->mChannels}
|
||||
|| usrfmt->type != albuf->OriginalType)
|
||||
context->setError(AL_INVALID_ENUM, "Unpacking data with mismatched format");
|
||||
else if UNLIKELY(align != albuf->OriginalAlign)
|
||||
context->setError(AL_INVALID_VALUE,
|
||||
"Unpacking data with alignment %u does not match original alignment %u", align,
|
||||
albuf->OriginalAlign);
|
||||
else if UNLIKELY(albuf->mBuffer.isBFormat()
|
||||
&& albuf->UnpackAmbiOrder != albuf->mBuffer.mAmbiOrder)
|
||||
else if UNLIKELY(albuf->isBFormat() && albuf->UnpackAmbiOrder != albuf->mAmbiOrder)
|
||||
context->setError(AL_INVALID_VALUE, "Unpacking data with mismatched ambisonic order");
|
||||
else if UNLIKELY(albuf->MappedAccess != 0)
|
||||
context->setError(AL_INVALID_OPERATION, "Unpacking data into mapped buffer %u", buffer);
|
||||
@@ -1056,16 +1056,16 @@ START_API_FUNC
|
||||
size_t byteoff{static_cast<ALuint>(offset)/byte_align * align * frame_size};
|
||||
size_t samplen{static_cast<ALuint>(length)/byte_align * align};
|
||||
|
||||
void *dst = albuf->mBuffer.mData.data() + byteoff;
|
||||
if(usrfmt->type == UserFmtIMA4 && albuf->mBuffer.mType == FmtShort)
|
||||
void *dst = albuf->mData.data() + byteoff;
|
||||
if(usrfmt->type == UserFmtIMA4 && albuf->mType == FmtShort)
|
||||
Convert_int16_ima4(static_cast<int16_t*>(dst), static_cast<const al::byte*>(data),
|
||||
num_chans, samplen, align);
|
||||
else if(usrfmt->type == UserFmtMSADPCM && albuf->mBuffer.mType == FmtShort)
|
||||
else if(usrfmt->type == UserFmtMSADPCM && albuf->mType == FmtShort)
|
||||
Convert_int16_msadpcm(static_cast<int16_t*>(dst),
|
||||
static_cast<const al::byte*>(data), num_chans, samplen, align);
|
||||
else
|
||||
{
|
||||
assert(long{usrfmt->type} == long{albuf->mBuffer.mType});
|
||||
assert(long{usrfmt->type} == long{albuf->mType});
|
||||
memcpy(dst, data, size_t{samplen} * frame_size);
|
||||
}
|
||||
}
|
||||
@@ -1216,7 +1216,7 @@ START_API_FUNC
|
||||
else if UNLIKELY(value != AL_FUMA_SOFT && value != AL_ACN_SOFT)
|
||||
context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic layout %04x", value);
|
||||
else
|
||||
albuf->mBuffer.mAmbiLayout = AmbiLayoutFromEnum(value).value();
|
||||
albuf->mAmbiLayout = AmbiLayoutFromEnum(value).value();
|
||||
break;
|
||||
|
||||
case AL_AMBISONIC_SCALING_SOFT:
|
||||
@@ -1226,7 +1226,7 @@ START_API_FUNC
|
||||
else if UNLIKELY(value != AL_FUMA_SOFT && value != AL_SN3D_SOFT && value != AL_N3D_SOFT)
|
||||
context->setError(AL_INVALID_VALUE, "Invalid unpack ambisonic scaling %04x", value);
|
||||
else
|
||||
albuf->mBuffer.mAmbiScaling = AmbiScalingFromEnum(value).value();
|
||||
albuf->mAmbiScaling = AmbiScalingFromEnum(value).value();
|
||||
break;
|
||||
|
||||
case AL_UNPACK_AMBISONIC_ORDER_SOFT:
|
||||
@@ -1297,13 +1297,13 @@ START_API_FUNC
|
||||
context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points",
|
||||
buffer);
|
||||
else if UNLIKELY(values[0] < 0 || values[0] >= values[1]
|
||||
|| static_cast<ALuint>(values[1]) > albuf->mBuffer.mSampleLen)
|
||||
|| static_cast<ALuint>(values[1]) > albuf->mSampleLen)
|
||||
context->setError(AL_INVALID_VALUE, "Invalid loop point range %d -> %d on buffer %u",
|
||||
values[0], values[1], buffer);
|
||||
else
|
||||
{
|
||||
albuf->mBuffer.mLoopStart = static_cast<ALuint>(values[0]);
|
||||
albuf->mBuffer.mLoopEnd = static_cast<ALuint>(values[1]);
|
||||
albuf->mLoopStart = static_cast<ALuint>(values[0]);
|
||||
albuf->mLoopEnd = static_cast<ALuint>(values[1]);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1402,7 +1402,7 @@ START_API_FUNC
|
||||
else switch(param)
|
||||
{
|
||||
case AL_FREQUENCY:
|
||||
*value = static_cast<ALint>(albuf->mBuffer.mSampleRate);
|
||||
*value = static_cast<ALint>(albuf->mSampleRate);
|
||||
break;
|
||||
|
||||
case AL_BITS:
|
||||
@@ -1414,7 +1414,7 @@ START_API_FUNC
|
||||
break;
|
||||
|
||||
case AL_SIZE:
|
||||
*value = static_cast<ALint>(albuf->mBuffer.mSampleLen * albuf->frameSizeFromFmt());
|
||||
*value = static_cast<ALint>(albuf->mSampleLen * albuf->frameSizeFromFmt());
|
||||
break;
|
||||
|
||||
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
|
||||
@@ -1426,11 +1426,11 @@ START_API_FUNC
|
||||
break;
|
||||
|
||||
case AL_AMBISONIC_LAYOUT_SOFT:
|
||||
*value = EnumFromAmbiLayout(albuf->mBuffer.mAmbiLayout);
|
||||
*value = EnumFromAmbiLayout(albuf->mAmbiLayout);
|
||||
break;
|
||||
|
||||
case AL_AMBISONIC_SCALING_SOFT:
|
||||
*value = EnumFromAmbiScaling(albuf->mBuffer.mAmbiScaling);
|
||||
*value = EnumFromAmbiScaling(albuf->mAmbiScaling);
|
||||
break;
|
||||
|
||||
case AL_UNPACK_AMBISONIC_ORDER_SOFT:
|
||||
@@ -1497,8 +1497,8 @@ START_API_FUNC
|
||||
else switch(param)
|
||||
{
|
||||
case AL_LOOP_POINTS_SOFT:
|
||||
values[0] = static_cast<ALint>(albuf->mBuffer.mLoopStart);
|
||||
values[1] = static_cast<ALint>(albuf->mBuffer.mLoopEnd);
|
||||
values[0] = static_cast<ALint>(albuf->mLoopStart);
|
||||
values[1] = static_cast<ALint>(albuf->mLoopEnd);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1555,10 +1555,10 @@ START_API_FUNC
|
||||
else switch(param)
|
||||
{
|
||||
case AL_BUFFER_CALLBACK_FUNCTION_SOFT:
|
||||
*value = reinterpret_cast<void*>(albuf->mBuffer.mCallback);
|
||||
*value = reinterpret_cast<void*>(albuf->mCallback);
|
||||
break;
|
||||
case AL_BUFFER_CALLBACK_USER_PARAM_SOFT:
|
||||
*value = albuf->mBuffer.mUserData;
|
||||
*value = albuf->mUserData;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+1
-7
@@ -38,9 +38,7 @@ enum UserFmtChannels : unsigned char {
|
||||
};
|
||||
|
||||
|
||||
struct ALbuffer {
|
||||
BufferStorage mBuffer;
|
||||
|
||||
struct ALbuffer : public BufferStorage {
|
||||
ALbitfieldSOFT Access{0u};
|
||||
|
||||
UserFmtType OriginalType{};
|
||||
@@ -61,10 +59,6 @@ struct ALbuffer {
|
||||
/* Self ID */
|
||||
ALuint id{0};
|
||||
|
||||
inline ALuint bytesFromFmt() const noexcept { return mBuffer.bytesFromFmt(); }
|
||||
inline ALuint channelsFromFmt() const noexcept { return mBuffer.channelsFromFmt(); }
|
||||
inline ALuint frameSizeFromFmt() const noexcept { return mBuffer.frameSizeFromFmt(); }
|
||||
|
||||
DISABLE_ALLOC()
|
||||
};
|
||||
|
||||
|
||||
+55
-72
@@ -173,17 +173,6 @@ void UpdateSourceProps(const ALsource *source, Voice *voice, ALCcontext *context
|
||||
}
|
||||
}
|
||||
|
||||
inline ALbuffer *BufferFromStorage(BufferStorage *storage)
|
||||
{
|
||||
constexpr auto offset = offsetof(ALbuffer, mBuffer);
|
||||
return reinterpret_cast<ALbuffer*>(reinterpret_cast<char*>(storage) - offset);
|
||||
}
|
||||
inline const ALbuffer *BufferFromStorage(const BufferStorage *storage)
|
||||
{
|
||||
constexpr auto offset = offsetof(ALbuffer, mBuffer);
|
||||
return reinterpret_cast<const ALbuffer*>(reinterpret_cast<const char*>(storage) - offset);
|
||||
}
|
||||
|
||||
/* GetSourceSampleOffset
|
||||
*
|
||||
* Gets the current read offset for the given Source, in 32.32 fixed-point
|
||||
@@ -305,10 +294,11 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context)
|
||||
return 0.0;
|
||||
|
||||
const BufferlistItem *BufferList{Source->queue};
|
||||
const BufferStorage *BufferFmt{nullptr};
|
||||
const ALbuffer *BufferFmt{nullptr};
|
||||
while(BufferList)
|
||||
{
|
||||
if(!BufferFmt) BufferFmt = BufferList->mBuffer;
|
||||
if(!BufferFmt)
|
||||
BufferFmt = static_cast<const ALbuffer*>(BufferList->mBuffer);
|
||||
if(BufferList == Current) break;
|
||||
|
||||
readPos += BufferList->mSampleLen;
|
||||
@@ -317,7 +307,7 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context)
|
||||
}
|
||||
while(BufferList && !BufferFmt)
|
||||
{
|
||||
BufferFmt = BufferList->mBuffer;
|
||||
BufferFmt = static_cast<const ALbuffer*>(BufferList->mBuffer);
|
||||
BufferList = BufferList->mNext.load(std::memory_order_relaxed);
|
||||
}
|
||||
assert(BufferFmt != nullptr);
|
||||
@@ -334,28 +324,27 @@ double GetSourceOffset(ALsource *Source, ALenum name, ALCcontext *context)
|
||||
break;
|
||||
|
||||
case AL_BYTE_OFFSET:
|
||||
const ALbuffer *origbuf{BufferFromStorage(BufferFmt)};
|
||||
if(origbuf->OriginalType == UserFmtIMA4)
|
||||
if(BufferFmt->OriginalType == UserFmtIMA4)
|
||||
{
|
||||
ALuint FrameBlockSize{origbuf->OriginalAlign};
|
||||
ALuint align{(origbuf->OriginalAlign-1)/2 + 4};
|
||||
ALuint BlockSize{align * origbuf->channelsFromFmt()};
|
||||
ALuint FrameBlockSize{BufferFmt->OriginalAlign};
|
||||
ALuint align{(BufferFmt->OriginalAlign-1)/2 + 4};
|
||||
ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
|
||||
|
||||
/* Round down to nearest ADPCM block */
|
||||
offset = static_cast<double>(readPos / FrameBlockSize * BlockSize);
|
||||
}
|
||||
else if(origbuf->OriginalType == UserFmtMSADPCM)
|
||||
else if(BufferFmt->OriginalType == UserFmtMSADPCM)
|
||||
{
|
||||
ALuint FrameBlockSize{origbuf->OriginalAlign};
|
||||
ALuint FrameBlockSize{BufferFmt->OriginalAlign};
|
||||
ALuint align{(FrameBlockSize-2)/2 + 7};
|
||||
ALuint BlockSize{align * origbuf->channelsFromFmt()};
|
||||
ALuint BlockSize{align * BufferFmt->channelsFromFmt()};
|
||||
|
||||
/* Round down to nearest ADPCM block */
|
||||
offset = static_cast<double>(readPos / FrameBlockSize * BlockSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ALuint FrameSize{origbuf->frameSizeFromFmt()};
|
||||
const ALuint FrameSize{BufferFmt->frameSizeFromFmt()};
|
||||
offset = static_cast<double>(readPos * FrameSize);
|
||||
}
|
||||
break;
|
||||
@@ -379,17 +368,16 @@ struct VoicePos {
|
||||
al::optional<VoicePos> GetSampleOffset(BufferlistItem *BufferList, ALenum OffsetType,
|
||||
double Offset)
|
||||
{
|
||||
al::optional<VoicePos> ret;
|
||||
|
||||
/* Find the first valid Buffer in the Queue */
|
||||
const BufferStorage *BufferFmt{nullptr};
|
||||
const ALbuffer *BufferFmt{nullptr};
|
||||
while(BufferList)
|
||||
{
|
||||
if((BufferFmt=BufferList->mBuffer) != nullptr) break;
|
||||
BufferFmt = static_cast<const ALbuffer*>(BufferList->mBuffer);
|
||||
if(BufferFmt != nullptr) break;
|
||||
BufferList = BufferList->mNext.load(std::memory_order_relaxed);
|
||||
}
|
||||
if(!BufferList)
|
||||
return ret;
|
||||
return al::nullopt;
|
||||
|
||||
/* Get sample frame offset */
|
||||
ALuint offset{0u}, frac{0u};
|
||||
@@ -410,19 +398,18 @@ al::optional<VoicePos> GetSampleOffset(BufferlistItem *BufferList, ALenum Offset
|
||||
|
||||
case AL_BYTE_OFFSET:
|
||||
/* Determine the ByteOffset (and ensure it is block aligned) */
|
||||
const ALbuffer *origbuf{BufferFromStorage(BufferFmt)};
|
||||
offset = static_cast<ALuint>(Offset);
|
||||
if(origbuf->OriginalType == UserFmtIMA4)
|
||||
if(BufferFmt->OriginalType == UserFmtIMA4)
|
||||
{
|
||||
const ALuint align{(origbuf->OriginalAlign-1)/2 + 4};
|
||||
offset /= align * origbuf->channelsFromFmt();
|
||||
offset *= origbuf->OriginalAlign;
|
||||
const ALuint align{(BufferFmt->OriginalAlign-1)/2 + 4};
|
||||
offset /= align * BufferFmt->channelsFromFmt();
|
||||
offset *= BufferFmt->OriginalAlign;
|
||||
}
|
||||
else if(origbuf->OriginalType == UserFmtMSADPCM)
|
||||
else if(BufferFmt->OriginalType == UserFmtMSADPCM)
|
||||
{
|
||||
const ALuint align{(origbuf->OriginalAlign-2)/2 + 7};
|
||||
offset /= align * origbuf->channelsFromFmt();
|
||||
offset *= origbuf->OriginalAlign;
|
||||
const ALuint align{(BufferFmt->OriginalAlign-2)/2 + 7};
|
||||
offset /= align * BufferFmt->channelsFromFmt();
|
||||
offset *= BufferFmt->OriginalAlign;
|
||||
}
|
||||
else
|
||||
offset /= BufferFmt->frameSizeFromFmt();
|
||||
@@ -437,8 +424,7 @@ al::optional<VoicePos> GetSampleOffset(BufferlistItem *BufferList, ALenum Offset
|
||||
if(BufferList->mSampleLen > offset-totalBufferLen)
|
||||
{
|
||||
/* Offset is in this buffer */
|
||||
ret = {offset-totalBufferLen, frac, BufferList};
|
||||
return ret;
|
||||
return al::make_optional(VoicePos{offset-totalBufferLen, frac, BufferList});
|
||||
}
|
||||
totalBufferLen += BufferList->mSampleLen;
|
||||
|
||||
@@ -446,7 +432,7 @@ al::optional<VoicePos> GetSampleOffset(BufferlistItem *BufferList, ALenum Offset
|
||||
}
|
||||
|
||||
/* Offset is out of range of the queue */
|
||||
return ret;
|
||||
return al::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -1375,14 +1361,14 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
|
||||
if(buffer->MappedAccess && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
|
||||
SETERR_RETURN(Context, AL_INVALID_OPERATION, false,
|
||||
"Setting non-persistently mapped buffer %u", buffer->id);
|
||||
if(buffer->mBuffer.mCallback && ReadRef(buffer->ref) != 0)
|
||||
if(buffer->mCallback && ReadRef(buffer->ref) != 0)
|
||||
SETERR_RETURN(Context, AL_INVALID_OPERATION, false,
|
||||
"Setting already-set callback buffer %u", buffer->id);
|
||||
|
||||
/* Add the selected buffer to a one-item queue */
|
||||
auto newlist = new BufferlistItem{};
|
||||
newlist->mSampleLen = buffer->mBuffer.mSampleLen;
|
||||
newlist->mBuffer = &buffer->mBuffer;
|
||||
newlist->mSampleLen = buffer->mSampleLen;
|
||||
newlist->mBuffer = buffer;
|
||||
IncrementRef(buffer->ref);
|
||||
|
||||
/* Source is now Static */
|
||||
@@ -1399,11 +1385,11 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
|
||||
/* Delete all elements in the previous queue */
|
||||
while(oldlist != nullptr)
|
||||
{
|
||||
std::unique_ptr<BufferlistItem> temp{oldlist};
|
||||
oldlist = temp->mNext.load(std::memory_order_relaxed);
|
||||
std::unique_ptr<BufferlistItem> head{oldlist};
|
||||
oldlist = head->mNext.load(std::memory_order_relaxed);
|
||||
|
||||
if(BufferStorage *buffer{temp->mBuffer})
|
||||
DecrementRef(BufferFromStorage(buffer)->ref);
|
||||
if(auto *buffer{static_cast<ALbuffer*>(head->mBuffer)})
|
||||
DecrementRef(buffer->ref);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1952,11 +1938,9 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
|
||||
case AL_BUFFER:
|
||||
CHECKSIZE(values, 1);
|
||||
{
|
||||
BufferlistItem *BufferList{nullptr};
|
||||
if(Source->SourceType == AL_STATIC) BufferList = Source->queue;
|
||||
BufferStorage *buffer{nullptr};
|
||||
if(BufferList) buffer = BufferList->mBuffer;
|
||||
values[0] = buffer ? static_cast<int>(BufferFromStorage(buffer)->id) : 0;
|
||||
BufferlistItem *BufferList{(Source->SourceType==AL_STATIC) ? Source->queue : nullptr};
|
||||
ALbuffer *buffer{BufferList ? static_cast<ALbuffer*>(BufferList->mBuffer) : nullptr};
|
||||
values[0] = buffer ? static_cast<int>(buffer->id) : 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -3245,11 +3229,11 @@ START_API_FUNC
|
||||
|
||||
/* Check for a valid Buffer, for its frequency and format */
|
||||
ALCdevice *device{context->mDevice.get()};
|
||||
BufferStorage *BufferFmt{nullptr};
|
||||
ALbuffer *BufferFmt{nullptr};
|
||||
BufferlistItem *BufferList{source->queue};
|
||||
while(BufferList && !BufferFmt)
|
||||
{
|
||||
BufferFmt = BufferList->mBuffer;
|
||||
BufferFmt = static_cast<ALbuffer*>(BufferList->mBuffer);
|
||||
BufferList = BufferList->mNext.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
@@ -3265,7 +3249,7 @@ START_API_FUNC
|
||||
context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]);
|
||||
goto buffer_error;
|
||||
}
|
||||
if(buffer && buffer->mBuffer.mCallback)
|
||||
if(buffer && buffer->mCallback)
|
||||
{
|
||||
context->setError(AL_INVALID_OPERATION, "Queueing callback buffer %u", buffers[i]);
|
||||
goto buffer_error;
|
||||
@@ -3283,8 +3267,8 @@ START_API_FUNC
|
||||
BufferList = item;
|
||||
}
|
||||
BufferList->mNext.store(nullptr, std::memory_order_relaxed);
|
||||
BufferList->mSampleLen = buffer ? buffer->mBuffer.mSampleLen : 0;
|
||||
BufferList->mBuffer = buffer ? &buffer->mBuffer : nullptr;
|
||||
BufferList->mSampleLen = buffer ? buffer->mSampleLen : 0;
|
||||
BufferList->mBuffer = buffer;
|
||||
if(!buffer) continue;
|
||||
|
||||
IncrementRef(buffer->ref);
|
||||
@@ -3297,18 +3281,18 @@ START_API_FUNC
|
||||
}
|
||||
|
||||
if(BufferFmt == nullptr)
|
||||
BufferFmt = buffer ? &buffer->mBuffer : nullptr;
|
||||
BufferFmt = buffer;
|
||||
else
|
||||
{
|
||||
fmt_mismatch |= BufferFmt->mSampleRate != buffer->mBuffer.mSampleRate;
|
||||
fmt_mismatch |= BufferFmt->mChannels != buffer->mBuffer.mChannels;
|
||||
fmt_mismatch |= BufferFmt->mSampleRate != buffer->mSampleRate;
|
||||
fmt_mismatch |= BufferFmt->mChannels != buffer->mChannels;
|
||||
if(BufferFmt->isBFormat())
|
||||
{
|
||||
fmt_mismatch |= BufferFmt->mAmbiLayout != buffer->mBuffer.mAmbiLayout;
|
||||
fmt_mismatch |= BufferFmt->mAmbiScaling != buffer->mBuffer.mAmbiScaling;
|
||||
fmt_mismatch |= BufferFmt->mAmbiLayout != buffer->mAmbiLayout;
|
||||
fmt_mismatch |= BufferFmt->mAmbiScaling != buffer->mAmbiScaling;
|
||||
}
|
||||
fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mBuffer.mAmbiOrder;
|
||||
fmt_mismatch |= BufferFromStorage(BufferFmt)->OriginalType != buffer->OriginalType;
|
||||
fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mAmbiOrder;
|
||||
fmt_mismatch |= BufferFmt->OriginalType != buffer->OriginalType;
|
||||
}
|
||||
if(fmt_mismatch)
|
||||
{
|
||||
@@ -3321,8 +3305,8 @@ START_API_FUNC
|
||||
{
|
||||
std::unique_ptr<BufferlistItem> head{BufferListStart};
|
||||
BufferListStart = head->mNext.load(std::memory_order_relaxed);
|
||||
if(BufferStorage *buf{head->mBuffer})
|
||||
DecrementRef(BufferFromStorage(buf)->ref);
|
||||
if(auto *buf{static_cast<ALbuffer*>(head->mBuffer)})
|
||||
DecrementRef(buf->ref);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -3398,11 +3382,10 @@ START_API_FUNC
|
||||
std::unique_ptr<BufferlistItem> head{source->queue};
|
||||
source->queue = head->mNext.load(std::memory_order_relaxed);
|
||||
|
||||
if(BufferStorage *buffer{head->mBuffer})
|
||||
if(auto *buffer{static_cast<ALbuffer*>(head->mBuffer)})
|
||||
{
|
||||
ALbuffer *origbuf{BufferFromStorage(buffer)};
|
||||
*(buffers++) = origbuf->id;
|
||||
DecrementRef(origbuf->ref);
|
||||
*(buffers++) = buffer->id;
|
||||
DecrementRef(buffer->ref);
|
||||
}
|
||||
else
|
||||
*(buffers++) = 0;
|
||||
@@ -3438,8 +3421,8 @@ ALsource::~ALsource()
|
||||
{
|
||||
std::unique_ptr<BufferlistItem> head{BufferList};
|
||||
BufferList = head->mNext.load(std::memory_order_relaxed);
|
||||
if(BufferStorage *buffer{head->mBuffer})
|
||||
DecrementRef(BufferFromStorage(buffer)->ref);
|
||||
if(auto *buffer{static_cast<ALbuffer*>(head->mBuffer)})
|
||||
DecrementRef(buffer->ref);
|
||||
}
|
||||
queue = nullptr;
|
||||
|
||||
|
||||
+2
-2
@@ -2160,7 +2160,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
|
||||
state->mOutTarget = device->Dry.Buffer;
|
||||
state->deviceUpdate(device);
|
||||
if(ALbuffer *buffer{slot->Buffer})
|
||||
state->setBuffer(device, &buffer->mBuffer);
|
||||
state->setBuffer(device, buffer);
|
||||
slot->updateProps(context);
|
||||
}
|
||||
|
||||
@@ -2181,7 +2181,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
|
||||
state->mOutTarget = device->Dry.Buffer;
|
||||
state->deviceUpdate(device);
|
||||
if(ALbuffer *buffer{slot->Buffer})
|
||||
state->setBuffer(device, &buffer->mBuffer);
|
||||
state->setBuffer(device, buffer);
|
||||
slot->updateProps(context);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user