aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-26 00:02:23 -0800
committerChris Robinson <[email protected]>2023-12-26 02:21:35 -0800
commit1fddc044ac765d00e64628e59edcbcd71f0046b1 (patch)
tree9e6734e0527bd418a4775c7d41c3b6a25ca4eb41 /al
parent095d1964feacaa4ec253db028fb1e8c04f718511 (diff)
Clean up some gotos and non-optimal casts
Diffstat (limited to 'al')
-rw-r--r--al/effects/chorus.cpp4
-rw-r--r--al/effects/fshifter.cpp4
-rw-r--r--al/effects/modulator.cpp2
-rw-r--r--al/effects/vmorpher.cpp6
-rw-r--r--al/source.cpp146
5 files changed, 83 insertions, 79 deletions
diff --git a/al/effects/chorus.cpp b/al/effects/chorus.cpp
index dba59d1d..913d1215 100644
--- a/al/effects/chorus.cpp
+++ b/al/effects/chorus.cpp
@@ -49,7 +49,7 @@ inline ALenum EnumFromWaveform(ChorusWaveform type)
EffectProps genDefaultChorusProps() noexcept
{
ChorusProps props{};
- props.Waveform = *WaveformFromEnum(AL_CHORUS_DEFAULT_WAVEFORM);
+ props.Waveform = WaveformFromEnum(AL_CHORUS_DEFAULT_WAVEFORM).value();
props.Phase = AL_CHORUS_DEFAULT_PHASE;
props.Rate = AL_CHORUS_DEFAULT_RATE;
props.Depth = AL_CHORUS_DEFAULT_DEPTH;
@@ -61,7 +61,7 @@ EffectProps genDefaultChorusProps() noexcept
EffectProps genDefaultFlangerProps() noexcept
{
FlangerProps props{};
- props.Waveform = *WaveformFromEnum(AL_FLANGER_DEFAULT_WAVEFORM);
+ props.Waveform = WaveformFromEnum(AL_FLANGER_DEFAULT_WAVEFORM).value();
props.Phase = AL_FLANGER_DEFAULT_PHASE;
props.Rate = AL_FLANGER_DEFAULT_RATE;
props.Depth = AL_FLANGER_DEFAULT_DEPTH;
diff --git a/al/effects/fshifter.cpp b/al/effects/fshifter.cpp
index 6f19e0dd..556244ac 100644
--- a/al/effects/fshifter.cpp
+++ b/al/effects/fshifter.cpp
@@ -45,8 +45,8 @@ EffectProps genDefaultProps() noexcept
{
FshifterProps props{};
props.Frequency = AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY;
- props.LeftDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION);
- props.RightDirection = *DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION);
+ props.LeftDirection = DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION).value();
+ props.RightDirection = DirectionFromEmum(AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION).value();
return props;
}
diff --git a/al/effects/modulator.cpp b/al/effects/modulator.cpp
index 566b333e..7e9424c0 100644
--- a/al/effects/modulator.cpp
+++ b/al/effects/modulator.cpp
@@ -47,7 +47,7 @@ EffectProps genDefaultProps() noexcept
ModulatorProps props{};
props.Frequency = AL_RING_MODULATOR_DEFAULT_FREQUENCY;
props.HighPassCutoff = AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF;
- props.Waveform = *WaveformFromEmum(AL_RING_MODULATOR_DEFAULT_WAVEFORM);
+ props.Waveform = WaveformFromEmum(AL_RING_MODULATOR_DEFAULT_WAVEFORM).value();
return props;
}
diff --git a/al/effects/vmorpher.cpp b/al/effects/vmorpher.cpp
index a986ddf7..35a64d32 100644
--- a/al/effects/vmorpher.cpp
+++ b/al/effects/vmorpher.cpp
@@ -126,11 +126,11 @@ EffectProps genDefaultProps() noexcept
{
VmorpherProps props{};
props.Rate = AL_VOCAL_MORPHER_DEFAULT_RATE;
- props.PhonemeA = *PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEA);
- props.PhonemeB = *PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEB);
+ props.PhonemeA = PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEA).value();
+ props.PhonemeB = PhenomeFromEnum(AL_VOCAL_MORPHER_DEFAULT_PHONEMEB).value();
props.PhonemeACoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING;
props.PhonemeBCoarseTuning = AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING;
- props.Waveform = *WaveformFromEmum(AL_VOCAL_MORPHER_DEFAULT_WAVEFORM);
+ props.Waveform = WaveformFromEmum(AL_VOCAL_MORPHER_DEFAULT_WAVEFORM).value();
return props;
}
diff --git a/al/source.cpp b/al/source.cpp
index a440a04b..bf96a769 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -3407,90 +3407,94 @@ FORCE_ALIGN void AL_APIENTRY alSourceQueueBuffersDirect(ALCcontext *context, ALu
std::unique_lock<std::mutex> buflock{device->BufferLock};
const size_t NewListStart{source->mQueue.size()};
- ALbufferQueueItem *BufferList{nullptr};
- for(ALsizei i{0};i < nb;i++)
- {
- bool fmt_mismatch{false};
- ALbuffer *buffer{buffers[i] ? LookupBuffer(device, buffers[i]) : nullptr};
- if(buffers[i] && !buffer)
- {
- context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]);
- goto buffer_error;
- }
- if(buffer)
+ try {
+ ALbufferQueueItem *BufferList{nullptr};
+ for(ALsizei i{0};i < nb;i++)
{
- if(buffer->mSampleRate < 1)
+ bool fmt_mismatch{false};
+ ALbuffer *buffer{buffers[i] ? LookupBuffer(device, buffers[i]) : nullptr};
+ if(buffers[i] && !buffer)
{
- context->setError(AL_INVALID_OPERATION, "Queueing buffer %u with no format",
- buffer->id);
- goto buffer_error;
+ context->setError(AL_INVALID_NAME, "Queueing invalid buffer ID %u", buffers[i]);
+ throw std::exception{};
}
- if(buffer->mCallback)
+ if(buffer)
{
- context->setError(AL_INVALID_OPERATION, "Queueing callback buffer %u", buffer->id);
- goto buffer_error;
+ if(buffer->mSampleRate < 1)
+ {
+ context->setError(AL_INVALID_OPERATION, "Queueing buffer %u with no format",
+ buffer->id);
+ throw std::exception{};
+ }
+ if(buffer->mCallback)
+ {
+ context->setError(AL_INVALID_OPERATION, "Queueing callback buffer %u",
+ buffer->id);
+ throw std::exception{};
+ }
+ if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
+ {
+ context->setError(AL_INVALID_OPERATION,
+ "Queueing non-persistently mapped buffer %u", buffer->id);
+ throw std::exception{};
+ }
}
- if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
+
+ source->mQueue.emplace_back();
+ if(!BufferList)
+ BufferList = &source->mQueue.back();
+ else
{
- context->setError(AL_INVALID_OPERATION,
- "Queueing non-persistently mapped buffer %u", buffer->id);
- goto buffer_error;
+ auto &item = source->mQueue.back();
+ BufferList->mNext.store(&item, std::memory_order_relaxed);
+ BufferList = &item;
}
- }
-
- source->mQueue.emplace_back();
- if(!BufferList)
- BufferList = &source->mQueue.back();
- else
- {
- auto &item = source->mQueue.back();
- BufferList->mNext.store(&item, std::memory_order_relaxed);
- BufferList = &item;
- }
- if(!buffer) continue;
- BufferList->mBlockAlign = buffer->mBlockAlign;
- BufferList->mSampleLen = buffer->mSampleLen;
- BufferList->mLoopEnd = buffer->mSampleLen;
- BufferList->mSamples = buffer->mData.data();
- BufferList->mBuffer = buffer;
- IncrementRef(buffer->ref);
-
- if(BufferFmt == nullptr)
- BufferFmt = buffer;
- else
- {
- fmt_mismatch |= BufferFmt->mSampleRate != buffer->mSampleRate;
- fmt_mismatch |= BufferFmt->mChannels != buffer->mChannels;
- fmt_mismatch |= BufferFmt->mType != buffer->mType;
- if(BufferFmt->isBFormat())
+ if(!buffer) continue;
+ BufferList->mBlockAlign = buffer->mBlockAlign;
+ BufferList->mSampleLen = buffer->mSampleLen;
+ BufferList->mLoopEnd = buffer->mSampleLen;
+ BufferList->mSamples = buffer->mData.data();
+ BufferList->mBuffer = buffer;
+ IncrementRef(buffer->ref);
+
+ if(BufferFmt == nullptr)
+ BufferFmt = buffer;
+ else
{
- fmt_mismatch |= BufferFmt->mAmbiLayout != buffer->mAmbiLayout;
- fmt_mismatch |= BufferFmt->mAmbiScaling != buffer->mAmbiScaling;
+ fmt_mismatch |= BufferFmt->mSampleRate != buffer->mSampleRate;
+ fmt_mismatch |= BufferFmt->mChannels != buffer->mChannels;
+ fmt_mismatch |= BufferFmt->mType != buffer->mType;
+ if(BufferFmt->isBFormat())
+ {
+ fmt_mismatch |= BufferFmt->mAmbiLayout != buffer->mAmbiLayout;
+ fmt_mismatch |= BufferFmt->mAmbiScaling != buffer->mAmbiScaling;
+ }
+ fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mAmbiOrder;
}
- fmt_mismatch |= BufferFmt->mAmbiOrder != buffer->mAmbiOrder;
- }
- if(fmt_mismatch) UNLIKELY
- {
- context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format\n"
- " Expected: %uhz, %s, %s ; Got: %uhz, %s, %s\n", BufferFmt->mSampleRate,
- NameFromFormat(BufferFmt->mType), NameFromFormat(BufferFmt->mChannels),
- buffer->mSampleRate, NameFromFormat(buffer->mType),
- NameFromFormat(buffer->mChannels));
-
- buffer_error:
- /* A buffer failed (invalid ID or format), so unlock and release
- * each buffer we had.
- */
- auto iter = source->mQueue.begin() + ptrdiff_t(NewListStart);
- for(;iter != source->mQueue.end();++iter)
+ if(fmt_mismatch) UNLIKELY
{
- if(ALbuffer *buf{iter->mBuffer})
- DecrementRef(buf->ref);
+ context->setError(AL_INVALID_OPERATION, "Queueing buffer with mismatched format\n"
+ " Expected: %uhz, %s, %s ; Got: %uhz, %s, %s\n", BufferFmt->mSampleRate,
+ NameFromFormat(BufferFmt->mType), NameFromFormat(BufferFmt->mChannels),
+ buffer->mSampleRate, NameFromFormat(buffer->mType),
+ NameFromFormat(buffer->mChannels));
+ throw std::exception{};
}
- source->mQueue.resize(NewListStart);
- return;
}
}
+ catch(...) {
+ /* A buffer failed (invalid ID or format), or there was some other
+ * unexpected error, so unlock and release each buffer we had.
+ */
+ auto iter = source->mQueue.begin() + ptrdiff_t(NewListStart);
+ for(;iter != source->mQueue.end();++iter)
+ {
+ if(ALbuffer *buf{iter->mBuffer})
+ DecrementRef(buf->ref);
+ }
+ source->mQueue.resize(NewListStart);
+ return;
+ }
/* All buffers good. */
buflock.unlock();