aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends
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 /alc/backends
parent095d1964feacaa4ec253db028fb1e8c04f718511 (diff)
Clean up some gotos and non-optimal casts
Diffstat (limited to 'alc/backends')
-rw-r--r--alc/backends/oss.cpp14
-rw-r--r--alc/backends/portaudio.cpp17
-rw-r--r--alc/backends/pulseaudio.cpp5
-rw-r--r--alc/backends/sndio.cpp131
4 files changed, 79 insertions, 88 deletions
diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp
index 50bed5ee..d541b534 100644
--- a/alc/backends/oss.cpp
+++ b/alc/backends/oss.cpp
@@ -367,11 +367,9 @@ bool OSSPlayback::reset()
uint numFragmentsLogSize{(periods << 16) | log2FragmentSize};
audio_buf_info info{};
- const char *err;
-#define CHECKERR(func) if((func) < 0) { \
- err = #func; \
- goto err; \
-}
+#define CHECKERR(func) if((func) < 0) \
+ throw al::backend_exception{al::backend_error::DeviceError, "%s failed: %s\n", #func, strerror(errno)};
+
/* Don't fail if SETFRAGMENT fails. We can handle just about anything
* that's reported back via GETOSPACE */
ioctl(mFd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize);
@@ -379,12 +377,6 @@ bool OSSPlayback::reset()
CHECKERR(ioctl(mFd, SNDCTL_DSP_CHANNELS, &numChannels));
CHECKERR(ioctl(mFd, SNDCTL_DSP_SPEED, &ossSpeed));
CHECKERR(ioctl(mFd, SNDCTL_DSP_GETOSPACE, &info));
- if(false)
- {
- err:
- ERR("%s failed: %s\n", err, strerror(errno));
- return false;
- }
#undef CHECKERR
if(mDevice->channelsFromFmt() != numChannels)
diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp
index 2ccb1c64..a8bd00fd 100644
--- a/alc/backends/portaudio.cpp
+++ b/alc/backends/portaudio.cpp
@@ -148,7 +148,6 @@ void PortPlayback::open(std::string_view name)
break;
}
-retry_open:
static constexpr auto writeCallback = [](const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
const PaStreamCallbackFlags statusFlags, void *userData) noexcept
@@ -157,17 +156,13 @@ retry_open:
framesPerBuffer, timeInfo, statusFlags);
};
PaStream *stream{};
- PaError err{Pa_OpenStream(&stream, nullptr, &params, mDevice->Frequency, mDevice->UpdateSize,
- paNoFlag, writeCallback, this)};
- if(err != paNoError)
+ while(PaError err{Pa_OpenStream(&stream, nullptr, &params, mDevice->Frequency,
+ mDevice->UpdateSize, paNoFlag, writeCallback, this)})
{
- if(params.sampleFormat == paFloat32)
- {
- params.sampleFormat = paInt16;
- goto retry_open;
- }
- throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: %s",
- Pa_GetErrorText(err)};
+ if(params.sampleFormat != paFloat32)
+ throw al::backend_exception{al::backend_error::NoDevice, "Failed to open stream: %s",
+ Pa_GetErrorText(err)};
+ params.sampleFormat = paInt16;
}
Pa_CloseStream(mStream);
diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp
index dcf01095..77d45466 100644
--- a/alc/backends/pulseaudio.cpp
+++ b/alc/backends/pulseaudio.cpp
@@ -968,8 +968,9 @@ bool PulsePlayback::reset()
const auto scale = static_cast<double>(mSpec.rate) / mDevice->Frequency;
const auto perlen = static_cast<uint>(clampd(scale*mDevice->UpdateSize + 0.5, 64.0,
8192.0));
- const auto buflen = static_cast<uint>(clampd(scale*mDevice->BufferSize + 0.5, perlen*2,
- std::numeric_limits<int>::max()/mFrameSize));
+ const auto bufmax = uint{std::numeric_limits<int>::max() / mFrameSize};
+ const auto buflen = static_cast<uint>(clampd(scale*mDevice->BufferSize + 0.5, perlen*2.0,
+ bufmax));
mAttr.maxlength = ~0u;
mAttr.tlength = buflen * mFrameSize;
diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp
index 0e667874..ce3de366 100644
--- a/alc/backends/sndio.cpp
+++ b/alc/backends/sndio.cpp
@@ -135,72 +135,75 @@ bool SndioPlayback::reset()
SioPar par;
auto tryfmt = mDevice->FmtType;
-retry_params:
- switch(tryfmt)
+ while(true)
{
- case DevFmtByte:
- par.bits = 8;
- par.sig = 1;
- break;
- case DevFmtUByte:
- par.bits = 8;
- par.sig = 0;
- break;
- case DevFmtShort:
- par.bits = 16;
- par.sig = 1;
- break;
- case DevFmtUShort:
- par.bits = 16;
- par.sig = 0;
- break;
- case DevFmtFloat:
- case DevFmtInt:
- par.bits = 32;
- par.sig = 1;
- break;
- case DevFmtUInt:
- par.bits = 32;
- par.sig = 0;
- break;
- }
- par.bps = SIO_BPS(par.bits);
- par.le = SIO_LE_NATIVE;
- par.msb = 1;
-
- par.rate = mDevice->Frequency;
- par.pchan = mDevice->channelsFromFmt();
-
- par.round = mDevice->UpdateSize;
- par.appbufsz = mDevice->BufferSize - mDevice->UpdateSize;
- if(!par.appbufsz) par.appbufsz = mDevice->UpdateSize;
+ switch(tryfmt)
+ {
+ case DevFmtByte:
+ par.bits = 8;
+ par.sig = 1;
+ break;
+ case DevFmtUByte:
+ par.bits = 8;
+ par.sig = 0;
+ break;
+ case DevFmtShort:
+ par.bits = 16;
+ par.sig = 1;
+ break;
+ case DevFmtUShort:
+ par.bits = 16;
+ par.sig = 0;
+ break;
+ case DevFmtFloat:
+ case DevFmtInt:
+ par.bits = 32;
+ par.sig = 1;
+ break;
+ case DevFmtUInt:
+ par.bits = 32;
+ par.sig = 0;
+ break;
+ }
+ par.bps = SIO_BPS(par.bits);
+ par.le = SIO_LE_NATIVE;
+ par.msb = 1;
+
+ par.rate = mDevice->Frequency;
+ par.pchan = mDevice->channelsFromFmt();
+
+ par.round = mDevice->UpdateSize;
+ par.appbufsz = mDevice->BufferSize - mDevice->UpdateSize;
+ if(!par.appbufsz) par.appbufsz = mDevice->UpdateSize;
+
+ try {
+ if(!sio_setpar(mSndHandle, &par))
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Failed to set device parameters"};
+
+ par.clear();
+ if(!sio_getpar(mSndHandle, &par))
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "Failed to get device parameters"};
+
+ if(par.bps > 1 && par.le != SIO_LE_NATIVE)
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "%s-endian samples not supported", par.le ? "Little" : "Big"};
+ if(par.bits < par.bps*8 && !par.msb)
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "MSB-padded samples not supported (%u of %u bits)", par.bits, par.bps*8};
+ if(par.pchan < 1)
+ throw al::backend_exception{al::backend_error::DeviceError,
+ "No playback channels on device"};
- try {
- if(!sio_setpar(mSndHandle, &par))
- throw al::backend_exception{al::backend_error::DeviceError,
- "Failed to set device parameters"};
-
- par.clear();
- if(!sio_getpar(mSndHandle, &par))
- throw al::backend_exception{al::backend_error::DeviceError,
- "Failed to get device parameters"};
-
- if(par.bps > 1 && par.le != SIO_LE_NATIVE)
- throw al::backend_exception{al::backend_error::DeviceError,
- "%s-endian samples not supported", par.le ? "Little" : "Big"};
- if(par.bits < par.bps*8 && !par.msb)
- throw al::backend_exception{al::backend_error::DeviceError,
- "MSB-padded samples not supported (%u of %u bits)", par.bits, par.bps*8};
- if(par.pchan < 1)
- throw al::backend_exception{al::backend_error::DeviceError,
- "No playback channels on device"};
- }
- catch(al::backend_exception &e) {
- if(tryfmt == DevFmtShort)
- throw;
- par.clear();
- tryfmt = DevFmtShort;
- goto retry_params;
+ break;
+ }
+ catch(al::backend_exception &e) {
+ if(tryfmt == DevFmtShort)
+ throw;
+ par.clear();
+ tryfmt = DevFmtShort;
+ }
}
if(par.bps == 1)