From cb3e96e75640730b9391f0d2d922eecd9ee2ce79 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Jul 2019 18:56:04 -0700 Subject: Rename Alc to alc --- alc/backends/solaris.cpp | 302 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 alc/backends/solaris.cpp (limited to 'alc/backends/solaris.cpp') diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp new file mode 100644 index 00000000..584f6e66 --- /dev/null +++ b/alc/backends/solaris.cpp @@ -0,0 +1,302 @@ +/** + * OpenAL cross platform audio library + * Copyright (C) 1999-2007 by authors. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Or go to http://www.gnu.org/copyleft/lgpl.html + */ + +#include "config.h" + +#include "backends/solaris.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "alcmain.h" +#include "alu.h" +#include "alconfig.h" +#include "threads.h" +#include "vector.h" +#include "compat.h" + +#include + + +namespace { + +constexpr ALCchar solaris_device[] = "Solaris Default"; + +std::string solaris_driver{"/dev/audio"}; + + +struct SolarisBackend final : public BackendBase { + SolarisBackend(ALCdevice *device) noexcept : BackendBase{device} { } + ~SolarisBackend() override; + + int mixerProc(); + + ALCenum open(const ALCchar *name) override; + ALCboolean reset() override; + ALCboolean start() override; + void stop() override; + + int mFd{-1}; + + al::vector mBuffer; + + std::atomic mKillNow{true}; + std::thread mThread; + + DEF_NEWDEL(SolarisBackend) +}; + +SolarisBackend::~SolarisBackend() +{ + if(mFd != -1) + close(mFd); + mFd = -1; +} + +int SolarisBackend::mixerProc() +{ + SetRTPriority(); + althrd_setname(MIXER_THREAD_NAME); + + const int frame_size{mDevice->frameSizeFromFmt()}; + + lock(); + while(!mKillNow.load(std::memory_order_acquire) && + mDevice->Connected.load(std::memory_order_acquire)) + { + pollfd pollitem{}; + pollitem.fd = mFd; + pollitem.events = POLLOUT; + + unlock(); + int pret{poll(&pollitem, 1, 1000)}; + lock(); + if(pret < 0) + { + if(errno == EINTR || errno == EAGAIN) + continue; + ERR("poll failed: %s\n", strerror(errno)); + aluHandleDisconnect(mDevice, "Failed to wait for playback buffer: %s", + strerror(errno)); + break; + } + else if(pret == 0) + { + WARN("poll timeout\n"); + continue; + } + + ALubyte *write_ptr{mBuffer.data()}; + size_t to_write{mBuffer.size()}; + aluMixData(mDevice, write_ptr, to_write/frame_size); + while(to_write > 0 && !mKillNow.load(std::memory_order_acquire)) + { + ssize_t wrote{write(mFd, write_ptr, to_write)}; + if(wrote < 0) + { + if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) + continue; + ERR("write failed: %s\n", strerror(errno)); + aluHandleDisconnect(mDevice, "Failed to write playback samples: %s", + strerror(errno)); + break; + } + + to_write -= wrote; + write_ptr += wrote; + } + } + unlock(); + + return 0; +} + + +ALCenum SolarisBackend::open(const ALCchar *name) +{ + if(!name) + name = solaris_device; + else if(strcmp(name, solaris_device) != 0) + return ALC_INVALID_VALUE; + + mFd = ::open(solaris_driver.c_str(), O_WRONLY); + if(mFd == -1) + { + ERR("Could not open %s: %s\n", solaris_driver.c_str(), strerror(errno)); + return ALC_INVALID_VALUE; + } + + mDevice->DeviceName = name; + return ALC_NO_ERROR; +} + +ALCboolean SolarisBackend::reset() +{ + audio_info_t info; + AUDIO_INITINFO(&info); + + info.play.sample_rate = mDevice->Frequency; + + if(mDevice->FmtChans != DevFmtMono) + mDevice->FmtChans = DevFmtStereo; + ALsizei numChannels{mDevice->channelsFromFmt()}; + info.play.channels = numChannels; + + switch(mDevice->FmtType) + { + case DevFmtByte: + info.play.precision = 8; + info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + case DevFmtUByte: + info.play.precision = 8; + info.play.encoding = AUDIO_ENCODING_LINEAR8; + break; + case DevFmtUShort: + case DevFmtInt: + case DevFmtUInt: + case DevFmtFloat: + mDevice->FmtType = DevFmtShort; + /* fall-through */ + case DevFmtShort: + info.play.precision = 16; + info.play.encoding = AUDIO_ENCODING_LINEAR; + break; + } + + ALsizei frameSize{numChannels * mDevice->bytesFromFmt()}; + info.play.buffer_size = mDevice->BufferSize * frameSize; + + if(ioctl(mFd, AUDIO_SETINFO, &info) < 0) + { + ERR("ioctl failed: %s\n", strerror(errno)); + return ALC_FALSE; + } + + if(mDevice->channelsFromFmt() != (ALsizei)info.play.channels) + { + ERR("Failed to set %s, got %u channels instead\n", DevFmtChannelsString(mDevice->FmtChans), + info.play.channels); + return ALC_FALSE; + } + + if(!((info.play.precision == 8 && info.play.encoding == AUDIO_ENCODING_LINEAR8 && mDevice->FmtType == DevFmtUByte) || + (info.play.precision == 8 && info.play.encoding == AUDIO_ENCODING_LINEAR && mDevice->FmtType == DevFmtByte) || + (info.play.precision == 16 && info.play.encoding == AUDIO_ENCODING_LINEAR && mDevice->FmtType == DevFmtShort) || + (info.play.precision == 32 && info.play.encoding == AUDIO_ENCODING_LINEAR && mDevice->FmtType == DevFmtInt))) + { + ERR("Could not set %s samples, got %d (0x%x)\n", DevFmtTypeString(mDevice->FmtType), + info.play.precision, info.play.encoding); + return ALC_FALSE; + } + + mDevice->Frequency = info.play.sample_rate; + mDevice->BufferSize = info.play.buffer_size / frameSize; + mDevice->UpdateSize = mDevice->BufferSize / 2; + + SetDefaultChannelOrder(mDevice); + + mBuffer.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt()); + std::fill(mBuffer.begin(), mBuffer.end(), 0); + + return ALC_TRUE; +} + +ALCboolean SolarisBackend::start() +{ + try { + mKillNow.store(false, std::memory_order_release); + mThread = std::thread{std::mem_fn(&SolarisBackend::mixerProc), this}; + return ALC_TRUE; + } + catch(std::exception& e) { + ERR("Could not create playback thread: %s\n", e.what()); + } + catch(...) { + } + return ALC_FALSE; +} + +void SolarisBackend::stop() +{ + if(mKillNow.exchange(true, std::memory_order_acq_rel) || !mThread.joinable()) + return; + mThread.join(); + + if(ioctl(mFd, AUDIO_DRAIN) < 0) + ERR("Error draining device: %s\n", strerror(errno)); +} + +} // namespace + +BackendFactory &SolarisBackendFactory::getFactory() +{ + static SolarisBackendFactory factory{}; + return factory; +} + +bool SolarisBackendFactory::init() +{ + if(auto devopt = ConfigValueStr(nullptr, "solaris", "device")) + solaris_driver = std::move(*devopt); + return true; +} + +bool SolarisBackendFactory::querySupport(BackendType type) +{ return type == BackendType::Playback; } + +void SolarisBackendFactory::probe(DevProbe type, std::string *outnames) +{ + switch(type) + { + case DevProbe::Playback: + { +#ifdef HAVE_STAT + struct stat buf; + if(stat(solaris_driver.c_str(), &buf) == 0) +#endif + outnames->append(solaris_device, sizeof(solaris_device)); + } + break; + + case DevProbe::Capture: + break; + } +} + +BackendPtr SolarisBackendFactory::createBackend(ALCdevice *device, BackendType type) +{ + if(type == BackendType::Playback) + return BackendPtr{new SolarisBackend{device}}; + return nullptr; +} -- cgit v1.2.3 From a250b6a98639571eedcaaf858d014d22eb008999 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 13 Sep 2019 14:29:25 -0700 Subject: Return unsigned values from the FromDevFmt functions --- alc/alc.cpp | 6 ++--- alc/alcmain.h | 6 ++--- alc/backends/dsound.cpp | 4 ++-- alc/backends/jack.cpp | 12 ++++------ alc/backends/oss.cpp | 59 ++++++++++++++++++++-------------------------- alc/backends/portaudio.cpp | 10 ++++---- alc/backends/sdl2.cpp | 2 +- alc/backends/sndio.cpp | 13 +++++----- alc/backends/solaris.cpp | 8 +++---- alc/backends/wasapi.cpp | 5 ++-- alc/backends/wave.cpp | 10 ++++---- alc/converter.cpp | 7 +++--- alc/devformat.h | 6 ++--- 13 files changed, 67 insertions(+), 81 deletions(-) (limited to 'alc/backends/solaris.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index 6d7228f5..9bb604a4 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1272,7 +1272,7 @@ const ALCchar *DevFmtChannelsString(DevFmtChannels chans) noexcept return "(unknown channels)"; } -ALsizei BytesFromDevFmt(DevFmtType type) noexcept +ALuint BytesFromDevFmt(DevFmtType type) noexcept { switch(type) { @@ -1286,7 +1286,7 @@ ALsizei BytesFromDevFmt(DevFmtType type) noexcept } return 0; } -ALsizei ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept +ALuint ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept { switch(chans) { @@ -1297,7 +1297,7 @@ ALsizei ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept case DevFmtX51Rear: return 6; case DevFmtX61: return 7; case DevFmtX71: return 8; - case DevFmtAmbi3D: return (ambiorder+1) * (ambiorder+1); + case DevFmtAmbi3D: return static_cast((ambiorder+1) * (ambiorder+1)); } return 0; } diff --git a/alc/alcmain.h b/alc/alcmain.h index 338897ab..f7842d96 100644 --- a/alc/alcmain.h +++ b/alc/alcmain.h @@ -340,9 +340,9 @@ struct ALCdevice : public al::intrusive_ref { ALCdevice& operator=(const ALCdevice&) = delete; ~ALCdevice(); - ALsizei bytesFromFmt() const noexcept { return BytesFromDevFmt(FmtType); } - ALsizei channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); } - ALsizei frameSizeFromFmt() const noexcept { return bytesFromFmt() * channelsFromFmt(); } + ALuint bytesFromFmt() const noexcept { return BytesFromDevFmt(FmtType); } + ALuint channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); } + ALuint frameSizeFromFmt() const noexcept { return bytesFromFmt() * channelsFromFmt(); } void ProcessHrtf(const size_t SamplesToDo); void ProcessAmbiDec(const size_t SamplesToDo); diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index ad182cf7..1c44c2ec 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -219,7 +219,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() return 1; } - ALsizei FrameSize{mDevice->frameSizeFromFmt()}; + ALuint FrameSize{mDevice->frameSizeFromFmt()}; DWORD FragSize{mDevice->UpdateSize * FrameSize}; bool Playing{false}; @@ -820,7 +820,7 @@ ALCuint DSoundCapture::availableSamples() if(!mDevice->Connected.load(std::memory_order_acquire)) return static_cast(mRing->readSpace()); - ALsizei FrameSize{mDevice->frameSizeFromFmt()}; + ALuint FrameSize{mDevice->frameSizeFromFmt()}; DWORD BufferBytes{mBufferBytes}; DWORD LastCursor{mCursor}; diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index e688b96b..e1ae91f0 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -235,7 +235,7 @@ int JackPlayback::process(jack_nframes_t numframes) } auto data = mRing->getReadVector(); - jack_nframes_t todo{minu(numframes, data.first.len)}; + jack_nframes_t todo{minu(numframes, static_cast(data.first.len))}; std::transform(out, out+numchans, out, [&data,numchans,todo](ALfloat *outbuf) -> ALfloat* { @@ -254,7 +254,7 @@ int JackPlayback::process(jack_nframes_t numframes) ); jack_nframes_t total{todo}; - todo = minu(numframes-total, data.second.len); + todo = minu(numframes-total, static_cast(data.second.len)); if(todo > 0) { std::transform(out, out+numchans, out, @@ -315,8 +315,8 @@ int JackPlayback::mixerProc() auto todo = static_cast(data.first.len + data.second.len); todo -= todo%mDevice->UpdateSize; - ALuint len1{minu(data.first.len, todo)}; - ALuint len2{minu(data.second.len, todo-len1)}; + ALuint len1{minu(static_cast(data.first.len), todo)}; + ALuint len2{minu(static_cast(data.second.len), todo-len1)}; aluMixData(mDevice, data.first.buf, len1); if(len2 > 0) @@ -382,8 +382,7 @@ ALCboolean JackPlayback::reset() /* Force 32-bit float output. */ mDevice->FmtType = DevFmtFloat; - ALsizei numchans{mDevice->channelsFromFmt()}; - auto ports_end = std::begin(mPort) + numchans; + auto ports_end = std::begin(mPort) + mDevice->channelsFromFmt(); auto bad_port = std::find_if_not(std::begin(mPort), ports_end, [this](jack_port_t *&port) -> bool { @@ -410,7 +409,6 @@ ALCboolean JackPlayback::reset() } mDevice->FmtChans = DevFmtStereo; } - numchans = std::distance(std::begin(mPort), bad_port); } mRing = nullptr; diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 8cfe9e96..48794a50 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -230,10 +230,10 @@ done: #endif -int log2i(ALCuint x) +ALCuint log2i(ALCuint x) { - int y = 0; - while (x > 1) + ALCuint y{0}; + while(x > 1) { x >>= 1; y++; @@ -276,7 +276,7 @@ int OSSPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - const int frame_size{mDevice->frameSizeFromFmt()}; + const ALuint frame_size{mDevice->frameSizeFromFmt()}; lock(); while(!mKillNow.load(std::memory_order_acquire) && @@ -319,7 +319,7 @@ int OSSPlayback::mixerProc() break; } - to_write -= wrote; + to_write -= static_cast(wrote); write_ptr += wrote; } } @@ -361,16 +361,7 @@ ALCenum OSSPlayback::open(const ALCchar *name) ALCboolean OSSPlayback::reset() { - int numFragmentsLogSize; - int log2FragmentSize; - unsigned int periods; - audio_buf_info info; - ALuint frameSize; - int numChannels; - int ossFormat; - int ossSpeed; - const char *err; - + int ossFormat{}; switch(mDevice->FmtType) { case DevFmtByte: @@ -390,14 +381,16 @@ ALCboolean OSSPlayback::reset() break; } - periods = mDevice->BufferSize / mDevice->UpdateSize; - numChannels = mDevice->channelsFromFmt(); - ossSpeed = mDevice->Frequency; - frameSize = numChannels * mDevice->bytesFromFmt(); + ALuint periods{mDevice->BufferSize / mDevice->UpdateSize}; + ALuint numChannels{mDevice->channelsFromFmt()}; + ALuint ossSpeed{mDevice->Frequency}; + ALuint frameSize{numChannels * mDevice->bytesFromFmt()}; /* According to the OSS spec, 16 bytes (log2(16)) is the minimum. */ - log2FragmentSize = maxi(log2i(mDevice->UpdateSize*frameSize), 4); - numFragmentsLogSize = (periods << 16) | log2FragmentSize; + ALuint log2FragmentSize{maxu(log2i(mDevice->UpdateSize*frameSize), 4)}; + ALuint numFragmentsLogSize{(periods << 16) | log2FragmentSize}; + audio_buf_info info{}; + const char *err; #define CHECKERR(func) if((func) < 0) { \ err = #func; \ goto err; \ @@ -434,8 +427,8 @@ ALCboolean OSSPlayback::reset() } mDevice->Frequency = ossSpeed; - mDevice->UpdateSize = info.fragsize / frameSize; - mDevice->BufferSize = info.fragments * mDevice->UpdateSize; + mDevice->UpdateSize = static_cast(info.fragsize) / frameSize; + mDevice->BufferSize = static_cast(info.fragments) * mDevice->UpdateSize; SetDefaultChannelOrder(mDevice); @@ -505,7 +498,7 @@ int OSScapture::recordProc() SetRTPriority(); althrd_setname(RECORD_THREAD_NAME); - const int frame_size{mDevice->frameSizeFromFmt()}; + const ALuint frame_size{mDevice->frameSizeFromFmt()}; while(!mKillNow.load(std::memory_order_acquire)) { pollfd pollitem{}; @@ -592,17 +585,15 @@ ALCenum OSScapture::open(const ALCchar *name) return ALC_INVALID_VALUE; } - int periods{4}; - int numChannels{mDevice->channelsFromFmt()}; - int frameSize{numChannels * mDevice->bytesFromFmt()}; - int ossSpeed{static_cast(mDevice->Frequency)}; - int log2FragmentSize{log2i(mDevice->BufferSize * frameSize / periods)}; - + ALuint periods{4}; + ALuint numChannels{mDevice->channelsFromFmt()}; + ALuint frameSize{numChannels * mDevice->bytesFromFmt()}; + ALuint ossSpeed{mDevice->Frequency}; /* according to the OSS spec, 16 bytes are the minimum */ - log2FragmentSize = std::max(log2FragmentSize, 4); - int numFragmentsLogSize{(periods << 16) | log2FragmentSize}; + ALuint log2FragmentSize{maxu(log2i(mDevice->BufferSize * frameSize / periods), 4)}; + ALuint numFragmentsLogSize{(periods << 16) | log2FragmentSize}; - audio_buf_info info; + audio_buf_info info{}; const char *err; #define CHECKERR(func) if((func) < 0) { \ err = #func; \ @@ -687,7 +678,7 @@ ALCenum OSScapture::captureSamples(ALCvoid *buffer, ALCuint samples) } ALCuint OSScapture::availableSamples() -{ return mRing->readSpace(); } +{ return static_cast(mRing->readSpace()); } } // namespace diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index fcfd4b01..4704a806 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -114,7 +114,7 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, const PaStreamCallbackFlags) { lock(); - aluMixData(mDevice, outputBuffer, framesPerBuffer); + aluMixData(mDevice, outputBuffer, static_cast(framesPerBuffer)); unlock(); return 0; } @@ -182,7 +182,7 @@ retry_open: ALCboolean PortPlayback::reset() { const PaStreamInfo *streamInfo{Pa_GetStreamInfo(mStream)}; - mDevice->Frequency = streamInfo->sampleRate; + mDevice->Frequency = static_cast(streamInfo->sampleRate); mDevice->UpdateSize = mUpdateSize; if(mParams.sampleFormat == paInt8) @@ -293,7 +293,7 @@ ALCenum PortCapture::open(const ALCchar *name) ALuint samples{mDevice->BufferSize}; samples = maxu(samples, 100 * mDevice->Frequency / 1000); - ALsizei frame_size{mDevice->frameSizeFromFmt()}; + ALuint frame_size{mDevice->frameSizeFromFmt()}; mRing = CreateRingBuffer(samples, frame_size, false); if(!mRing) return ALC_INVALID_VALUE; @@ -326,7 +326,7 @@ ALCenum PortCapture::open(const ALCchar *name) ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); return ALC_INVALID_VALUE; } - mParams.channelCount = mDevice->channelsFromFmt(); + mParams.channelCount = static_cast(mDevice->channelsFromFmt()); PaError err{Pa_OpenStream(&mStream, &mParams, nullptr, mDevice->Frequency, paFramesPerBufferUnspecified, paNoFlag, &PortCapture::readCallbackC, this)}; @@ -361,7 +361,7 @@ void PortCapture::stop() ALCuint PortCapture::availableSamples() -{ return mRing->readSpace(); } +{ return static_cast(mRing->readSpace()); } ALCenum PortCapture::captureSamples(ALCvoid *buffer, ALCuint samples) { diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index 28d020a1..6af0ac9d 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -153,7 +153,7 @@ ALCenum Sdl2Backend::open(const ALCchar *name) mDevice->UpdateSize = have.samples; mDevice->BufferSize = have.samples * 2; /* SDL always (tries to) use two periods. */ - mFrameSize = static_cast(mDevice->frameSizeFromFmt()); + mFrameSize = mDevice->frameSizeFromFmt(); mFrequency = mDevice->Frequency; mFmtChans = mDevice->FmtChans; mFmtType = mDevice->FmtType; diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index c7a86670..4a470e82 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -76,16 +76,16 @@ int SndioPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - const ALsizei frameSize{mDevice->frameSizeFromFmt()}; + const ALuint frameSize{mDevice->frameSizeFromFmt()}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { - auto WritePtr = static_cast(mBuffer.data()); + ALubyte *WritePtr{mBuffer.data()}; size_t len{mBuffer.size()}; lock(); - aluMixData(mDevice, WritePtr, len/frameSize); + aluMixData(mDevice, WritePtr, static_cast(len/frameSize)); unlock(); while(len > 0 && !mKillNow.load(std::memory_order_acquire)) { @@ -277,7 +277,7 @@ int SndioCapture::recordProc() SetRTPriority(); althrd_setname(RECORD_THREAD_NAME); - const ALsizei frameSize{mDevice->frameSizeFromFmt()}; + const ALuint frameSize{mDevice->frameSizeFromFmt()}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) @@ -396,8 +396,7 @@ ALCenum SndioCapture::open(const ALCchar *name) (mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) || (mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) || (mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) || - mDevice->channelsFromFmt() != static_cast(par.rchan) || - mDevice->Frequency != par.rate) + mDevice->channelsFromFmt() != par.rchan || mDevice->Frequency != par.rate) { ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n", DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), @@ -457,7 +456,7 @@ ALCenum SndioCapture::captureSamples(void *buffer, ALCuint samples) } ALCuint SndioCapture::availableSamples() -{ return mRing->readSpace(); } +{ return static_cast(mRing->readSpace()); } } // namespace diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 584f6e66..2e8fe458 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -88,7 +88,7 @@ int SolarisBackend::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - const int frame_size{mDevice->frameSizeFromFmt()}; + const ALuint frame_size{mDevice->frameSizeFromFmt()}; lock(); while(!mKillNow.load(std::memory_order_acquire) && @@ -169,7 +169,7 @@ ALCboolean SolarisBackend::reset() if(mDevice->FmtChans != DevFmtMono) mDevice->FmtChans = DevFmtStereo; - ALsizei numChannels{mDevice->channelsFromFmt()}; + ALuint numChannels{mDevice->channelsFromFmt()}; info.play.channels = numChannels; switch(mDevice->FmtType) @@ -194,7 +194,7 @@ ALCboolean SolarisBackend::reset() break; } - ALsizei frameSize{numChannels * mDevice->bytesFromFmt()}; + ALuint frameSize{numChannels * mDevice->bytesFromFmt()}; info.play.buffer_size = mDevice->BufferSize * frameSize; if(ioctl(mFd, AUDIO_SETINFO, &info) < 0) @@ -203,7 +203,7 @@ ALCboolean SolarisBackend::reset() return ALC_FALSE; } - if(mDevice->channelsFromFmt() != (ALsizei)info.play.channels) + if(mDevice->channelsFromFmt() != info.play.channels) { ERR("Failed to set %s, got %u channels instead\n", DevFmtChannelsString(mDevice->FmtChans), info.play.channels); diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 806db122..55c95146 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1565,9 +1565,8 @@ HRESULT WasapiCapture::resetProxy() if(mDevice->Frequency != OutputType.Format.nSamplesPerSec || mDevice->FmtType != srcType) { - mSampleConv = CreateSampleConverter(srcType, mDevice->FmtType, - static_cast(mDevice->channelsFromFmt()), OutputType.Format.nSamplesPerSec, - mDevice->Frequency, BSinc24Resampler); + mSampleConv = CreateSampleConverter(srcType, mDevice->FmtType, mDevice->channelsFromFmt(), + OutputType.Format.nSamplesPerSec, mDevice->Frequency, BSinc24Resampler); if(!mSampleConv) { ERR("Failed to create converter for %s format, dst: %s %uhz, src: %s %luhz\n", diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 20f0d3f2..f1171747 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -125,7 +125,7 @@ int WaveBackend::mixerProc() althrd_setname(MIXER_THREAD_NAME); - const auto frameSize = static_cast(mDevice->frameSizeFromFmt()); + const ALuint frameSize{mDevice->frameSizeFromFmt()}; int64_t done{0}; auto start = std::chrono::steady_clock::now(); @@ -151,7 +151,7 @@ int WaveBackend::mixerProc() if(!IS_LITTLE_ENDIAN) { - const ALsizei bytesize{mDevice->bytesFromFmt()}; + const ALuint bytesize{mDevice->bytesFromFmt()}; if(bytesize == 2) { @@ -281,8 +281,8 @@ ALCboolean WaveBackend::reset() chanmask = 0; break; } - bytes = static_cast(mDevice->bytesFromFmt()); - channels = static_cast(mDevice->channelsFromFmt()); + bytes = mDevice->bytesFromFmt(); + channels = mDevice->channelsFromFmt(); rewind(mFile); @@ -330,7 +330,7 @@ ALCboolean WaveBackend::reset() SetDefaultWFXChannelOrder(mDevice); - const ALuint bufsize{static_cast(mDevice->frameSizeFromFmt())*mDevice->UpdateSize}; + const ALuint bufsize{mDevice->frameSizeFromFmt() * mDevice->UpdateSize}; mBuffer.resize(bufsize); return ALC_TRUE; diff --git a/alc/converter.cpp b/alc/converter.cpp index 87a9d275..2913f533 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -152,8 +152,8 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, SampleConverterPtr converter{new (FamCount{numchans}) SampleConverter{numchans}}; converter->mSrcType = srcType; converter->mDstType = dstType; - converter->mSrcTypeSize = static_cast(BytesFromDevFmt(srcType)); - converter->mDstTypeSize = static_cast(BytesFromDevFmt(dstType)); + converter->mSrcTypeSize = BytesFromDevFmt(srcType); + converter->mDstTypeSize = BytesFromDevFmt(dstType); converter->mSrcPrepCount = 0; converter->mFracOffset = 0; @@ -360,6 +360,5 @@ void ChannelConverter::convert(const ALvoid *src, ALfloat *dst, ALuint frames) c } } else - LoadSamples(dst, src, 1u, mSrcType, - frames*static_cast(ChannelsFromDevFmt(mSrcChans, 0))); + LoadSamples(dst, src, 1u, mSrcType, frames * ChannelsFromDevFmt(mSrcChans, 0)); } diff --git a/alc/devformat.h b/alc/devformat.h index 95fe5fbd..674dd848 100644 --- a/alc/devformat.h +++ b/alc/devformat.h @@ -97,9 +97,9 @@ template<> struct DevFmtTypeTraits { using Type = ALfloat; }; -ALsizei BytesFromDevFmt(DevFmtType type) noexcept; -ALsizei ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept; -inline ALsizei FrameSizeFromDevFmt(DevFmtChannels chans, DevFmtType type, ALsizei ambiorder) noexcept +ALuint BytesFromDevFmt(DevFmtType type) noexcept; +ALuint ChannelsFromDevFmt(DevFmtChannels chans, ALsizei ambiorder) noexcept; +inline ALuint FrameSizeFromDevFmt(DevFmtChannels chans, DevFmtType type, ALsizei ambiorder) noexcept { return ChannelsFromDevFmt(chans, ambiorder) * BytesFromDevFmt(type); } enum class AmbiLayout { -- cgit v1.2.3 From c5a3c52822d0ab8e36c2d3d31936eae1da64049f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 15 Sep 2019 09:50:28 -0700 Subject: Return and pass more appropriate types for backends --- alc/alc.cpp | 9 +++++---- alc/backends/alsa.cpp | 38 +++++++++++++++++++------------------- alc/backends/base.cpp | 6 +++--- alc/backends/base.h | 7 ++++--- alc/backends/coreaudio.cpp | 38 +++++++++++++++++++------------------- alc/backends/dsound.cpp | 28 ++++++++++++++-------------- alc/backends/jack.cpp | 22 +++++++++++----------- alc/backends/loopback.cpp | 12 ++++++------ alc/backends/null.cpp | 14 +++++++------- alc/backends/opensl.cpp | 36 +++++++++++++++++------------------- alc/backends/oss.cpp | 32 ++++++++++++++++---------------- alc/backends/portaudio.cpp | 30 +++++++++++++++--------------- alc/backends/pulseaudio.cpp | 24 ++++++++++++------------ alc/backends/qsa.cpp | 18 +++++++++--------- alc/backends/sdl2.cpp | 12 ++++++------ alc/backends/sndio.cpp | 36 ++++++++++++++++++------------------ alc/backends/solaris.cpp | 20 ++++++++++---------- alc/backends/wasapi.cpp | 22 +++++++++++----------- alc/backends/wave.cpp | 16 ++++++++-------- alc/backends/winmm.cpp | 34 +++++++++++++++++----------------- 20 files changed, 227 insertions(+), 227 deletions(-) (limited to 'alc/backends/solaris.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index fa88cba8..4a4ed677 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -1920,7 +1920,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->UpdateSize, device->BufferSize); try { - if(device->Backend->reset() == ALC_FALSE) + if(device->Backend->reset() == false) return ALC_INVALID_DEVICE; } catch(std::exception &e) { @@ -2235,7 +2235,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(!device->Flags.get()) { - if(device->Backend->start() == ALC_FALSE) + if(device->Backend->start() == false) return ALC_INVALID_DEVICE; device->Flags.set(); } @@ -3911,7 +3911,8 @@ START_API_FUNC { std::lock_guard _{dev->StateLock}; BackendBase *backend{dev->Backend.get()}; if(samples >= 0 && backend->availableSamples() >= static_cast(samples)) - err = backend->captureSamples(buffer, static_cast(samples)); + err = backend->captureSamples(static_cast(buffer), + static_cast(samples)); } if(err != ALC_NO_ERROR) alcSetError(dev.get(), err); @@ -4085,7 +4086,7 @@ START_API_FUNC if(dev->mContexts.load()->empty()) return; - if(dev->Backend->start() == ALC_FALSE) + if(dev->Backend->start() == false) { aluHandleDisconnect(dev.get(), "Device start failure"); alcSetError(dev.get(), ALC_INVALID_DEVICE); diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index b797c768..da928171 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -395,8 +395,8 @@ struct AlsaPlayback final : public BackendBase { int mixerNoMMapProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; ClockLatency getClockLatency() override; @@ -630,7 +630,7 @@ ALCenum AlsaPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean AlsaPlayback::reset() +bool AlsaPlayback::reset() { snd_pcm_format_t format{SND_PCM_FORMAT_UNKNOWN}; switch(mDevice->FmtType) @@ -770,16 +770,16 @@ ALCboolean AlsaPlayback::reset() SetDefaultChannelOrder(mDevice); - return ALC_TRUE; + return true; error: ERR("%s failed: %s\n", funcerr, snd_strerror(err)); if(hp) snd_pcm_hw_params_free(hp); if(sp) snd_pcm_sw_params_free(sp); - return ALC_FALSE; + return false; } -ALCboolean AlsaPlayback::start() +bool AlsaPlayback::start() { snd_pcm_hw_params_t *hp{}; snd_pcm_access_t access; @@ -797,7 +797,7 @@ ALCboolean AlsaPlayback::start() error: ERR("%s failed: %s\n", funcerr, snd_strerror(err)); if(hp) snd_pcm_hw_params_free(hp); - return ALC_FALSE; + return false; } snd_pcm_hw_params_free(hp); hp = nullptr; @@ -815,7 +815,7 @@ ALCboolean AlsaPlayback::start() if(err < 0) { ERR("snd_pcm_prepare(data->mPcmHandle) failed: %s\n", snd_strerror(err)); - return ALC_FALSE; + return false; } thread_func = &AlsaPlayback::mixerProc; } @@ -823,7 +823,7 @@ ALCboolean AlsaPlayback::start() try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(thread_func), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); @@ -831,7 +831,7 @@ ALCboolean AlsaPlayback::start() catch(...) { } mBuffer.clear(); - return ALC_FALSE; + return false; } void AlsaPlayback::stop() @@ -869,9 +869,9 @@ struct AlsaCapture final : public BackendBase { ~AlsaCapture() override; ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(ALCvoid *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; ClockLatency getClockLatency() override; @@ -1015,7 +1015,7 @@ error2: } -ALCboolean AlsaCapture::start() +bool AlsaCapture::start() { int err{snd_pcm_prepare(mPcmHandle)}; if(err < 0) @@ -1029,11 +1029,11 @@ ALCboolean AlsaCapture::start() if(err < 0) { aluHandleDisconnect(mDevice, "Capture state failure: %s", snd_strerror(err)); - return ALC_FALSE; + return false; } mDoCapture = true; - return ALC_TRUE; + return true; } void AlsaCapture::stop() @@ -1058,7 +1058,7 @@ void AlsaCapture::stop() mDoCapture = false; } -ALCenum AlsaCapture::captureSamples(ALCvoid *buffer, ALCuint samples) +ALCenum AlsaCapture::captureSamples(al::byte *buffer, ALCuint samples) { if(mRing) { @@ -1078,7 +1078,7 @@ ALCenum AlsaCapture::captureSamples(ALCvoid *buffer, ALCuint samples) if(static_cast(amt) > samples) amt = samples; amt = snd_pcm_frames_to_bytes(mPcmHandle, amt); - std::copy_n(mBuffer.begin(), amt, static_cast(buffer)); + std::copy_n(mBuffer.begin(), amt, buffer); mBuffer.erase(mBuffer.begin(), mBuffer.begin()+amt); amt = snd_pcm_bytes_to_frames(mPcmHandle, amt); @@ -1111,11 +1111,11 @@ ALCenum AlsaCapture::captureSamples(ALCvoid *buffer, ALCuint samples) continue; } - buffer = static_cast(buffer) + amt; + buffer = buffer + amt; samples -= static_cast(amt); } if(samples > 0) - std::fill_n(static_cast(buffer), snd_pcm_frames_to_bytes(mPcmHandle, samples), + std::fill_n(buffer, snd_pcm_frames_to_bytes(mPcmHandle, samples), al::byte((mDevice->FmtType == DevFmtUByte) ? 0x80 : 0)); return ALC_NO_ERROR; diff --git a/alc/backends/base.cpp b/alc/backends/base.cpp index c4c6052b..a5f66606 100644 --- a/alc/backends/base.cpp +++ b/alc/backends/base.cpp @@ -28,10 +28,10 @@ BackendBase::BackendBase(ALCdevice *device) noexcept : mDevice{device} BackendBase::~BackendBase() = default; -ALCboolean BackendBase::reset() -{ return ALC_FALSE; } +bool BackendBase::reset() +{ return false; } -ALCenum BackendBase::captureSamples(void*, ALCuint) +ALCenum BackendBase::captureSamples(al::byte*, ALCuint) { return ALC_INVALID_DEVICE; } ALCuint BackendBase::availableSamples() diff --git a/alc/backends/base.h b/alc/backends/base.h index e88734dc..cc33ba50 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -9,6 +9,7 @@ #include "AL/alc.h" #include "alcmain.h" +#include "albyte.h" struct ClockLatency { @@ -33,11 +34,11 @@ ClockLatency GetClockLatency(ALCdevice *device); struct BackendBase { virtual ALCenum open(const ALCchar *name) = 0; - virtual ALCboolean reset(); - virtual ALCboolean start() = 0; + virtual bool reset(); + virtual bool start() = 0; virtual void stop() = 0; - virtual ALCenum captureSamples(void *buffer, ALCuint samples); + virtual ALCenum captureSamples(al::byte *buffer, ALCuint samples); virtual ALCuint availableSamples(); virtual ClockLatency getClockLatency(); diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 3ae9800c..72754718 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -54,8 +54,8 @@ struct CoreAudioPlayback final : public BackendBase { AudioBufferList *ioData); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; AudioUnit mAudioUnit; @@ -137,7 +137,7 @@ ALCenum CoreAudioPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean CoreAudioPlayback::reset() +bool CoreAudioPlayback::reset() { OSStatus err{AudioUnitUninitialize(mAudioUnit)}; if(err != noErr) @@ -151,7 +151,7 @@ ALCboolean CoreAudioPlayback::reset() if(err != noErr || size != sizeof(AudioStreamBasicDescription)) { ERR("AudioUnitGetProperty failed\n"); - return ALC_FALSE; + return false; } #if 0 @@ -170,7 +170,7 @@ ALCboolean CoreAudioPlayback::reset() if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_FALSE; + return false; } if(mDevice->Frequency != streamFormat.mSampleRate) @@ -254,7 +254,7 @@ ALCboolean CoreAudioPlayback::reset() if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_FALSE; + return false; } /* setup callback */ @@ -268,7 +268,7 @@ ALCboolean CoreAudioPlayback::reset() if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_FALSE; + return false; } /* init the default audio unit... */ @@ -276,21 +276,21 @@ ALCboolean CoreAudioPlayback::reset() if(err != noErr) { ERR("AudioUnitInitialize failed\n"); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } -ALCboolean CoreAudioPlayback::start() +bool CoreAudioPlayback::start() { OSStatus err{AudioOutputUnitStart(mAudioUnit)}; if(err != noErr) { ERR("AudioOutputUnitStart failed\n"); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void CoreAudioPlayback::stop() @@ -313,9 +313,9 @@ struct CoreAudioCapture final : public BackendBase { UInt32 inNumberFrames, AudioBufferList *ioData); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; AudioUnit mAudioUnit{0}; @@ -628,15 +628,15 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) } -ALCboolean CoreAudioCapture::start() +bool CoreAudioCapture::start() { OSStatus err{AudioOutputUnitStart(mAudioUnit)}; if(err != noErr) { ERR("AudioOutputUnitStart failed\n"); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void CoreAudioCapture::stop() @@ -646,7 +646,7 @@ void CoreAudioCapture::stop() ERR("AudioOutputUnitStop failed\n"); } -ALCenum CoreAudioCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum CoreAudioCapture::captureSamples(al::byte *buffer, ALCuint samples) { if(!mConverter) { @@ -663,7 +663,7 @@ ALCenum CoreAudioCapture::captureSamples(void *buffer, ALCuint samples) { const void *src1{rec_vec.second.buf}; auto src1len = static_cast(rec_vec.second.len); - got += mConverter->convert(&src1, &src1len, static_cast(buffer)+got, samples-got); + got += mConverter->convert(&src1, &src1len, buffer+got, samples-got); total_read += rec_vec.second.len - src1len; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index f9184968..c581fe8f 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -167,8 +167,8 @@ struct DSoundPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; IDirectSound *mDS{nullptr}; @@ -348,7 +348,7 @@ ALCenum DSoundPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean DSoundPlayback::reset() +bool DSoundPlayback::reset() { if(mNotifies) mNotifies->Release(); @@ -558,28 +558,28 @@ retry_open: if(mPrimaryBuffer) mPrimaryBuffer->Release(); mPrimaryBuffer = nullptr; - return ALC_FALSE; + return false; } ResetEvent(mNotifyEvent); SetDefaultWFXChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean DSoundPlayback::start() +bool DSoundPlayback::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&DSoundPlayback::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Failed to start mixing thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void DSoundPlayback::stop() @@ -597,9 +597,9 @@ struct DSoundCapture final : public BackendBase { ~DSoundCapture() override; ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; IDirectSoundCapture *mDSC{nullptr}; @@ -791,16 +791,16 @@ ALCenum DSoundCapture::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean DSoundCapture::start() +bool DSoundCapture::start() { HRESULT hr{mDSCbuffer->Start(DSCBSTART_LOOPING)}; if(FAILED(hr)) { ERR("start failed: 0x%08lx\n", hr); aluHandleDisconnect(mDevice, "Failure starting capture: 0x%lx", hr); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void DSoundCapture::stop() @@ -813,7 +813,7 @@ void DSoundCapture::stop() } } -ALCenum DSoundCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum DSoundCapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index e1ae91f0..660ea933 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -162,8 +162,8 @@ struct JackPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; ClockLatency getClockLatency() override; @@ -359,7 +359,7 @@ ALCenum JackPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean JackPlayback::reset() +bool JackPlayback::reset() { std::for_each(std::begin(mPort), std::end(mPort), [this](jack_port_t *port) -> void @@ -395,7 +395,7 @@ ALCboolean JackPlayback::reset() if(bad_port != ports_end) { ERR("Not enough JACK ports available for %s output\n", DevFmtChannelsString(mDevice->FmtChans)); - if(bad_port == std::begin(mPort)) return ALC_FALSE; + if(bad_port == std::begin(mPort)) return false; if(bad_port == std::begin(mPort)+1) mDevice->FmtChans = DevFmtMono; @@ -416,20 +416,20 @@ ALCboolean JackPlayback::reset() if(!mRing) { ERR("Failed to allocate ringbuffer\n"); - return ALC_FALSE; + return false; } SetDefaultChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean JackPlayback::start() +bool JackPlayback::start() { if(jack_activate(mClient)) { ERR("Failed to activate client\n"); - return ALC_FALSE; + return false; } const char **ports{jack_get_ports(mClient, nullptr, nullptr, @@ -438,7 +438,7 @@ ALCboolean JackPlayback::start() { ERR("No physical playback ports found\n"); jack_deactivate(mClient); - return ALC_FALSE; + return false; } std::mismatch(std::begin(mPort), std::end(mPort), ports, [this](const jack_port_t *port, const char *pname) -> bool @@ -460,7 +460,7 @@ ALCboolean JackPlayback::start() try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&JackPlayback::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); @@ -468,7 +468,7 @@ ALCboolean JackPlayback::start() catch(...) { } jack_deactivate(mClient); - return ALC_FALSE; + return false; } void JackPlayback::stop() diff --git a/alc/backends/loopback.cpp b/alc/backends/loopback.cpp index 4a1c641a..7edc2d40 100644 --- a/alc/backends/loopback.cpp +++ b/alc/backends/loopback.cpp @@ -32,8 +32,8 @@ struct LoopbackBackend final : public BackendBase { LoopbackBackend(ALCdevice *device) noexcept : BackendBase{device} { } ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; DEF_NEWDEL(LoopbackBackend) @@ -46,14 +46,14 @@ ALCenum LoopbackBackend::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean LoopbackBackend::reset() +bool LoopbackBackend::reset() { SetDefaultWFXChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean LoopbackBackend::start() -{ return ALC_TRUE; } +bool LoopbackBackend::start() +{ return true; } void LoopbackBackend::stop() { } diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index ae58cb8b..b6b115f1 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -52,8 +52,8 @@ struct NullBackend final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; std::atomic mKillNow{true}; @@ -120,25 +120,25 @@ ALCenum NullBackend::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean NullBackend::reset() +bool NullBackend::reset() { SetDefaultWFXChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean NullBackend::start() +bool NullBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&NullBackend::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Failed to start mixing thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void NullBackend::stop() diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 3a2f455e..0f1d8a21 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -152,8 +152,8 @@ struct OpenSLPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; ClockLatency getClockLatency() override; @@ -347,7 +347,7 @@ ALCenum OpenSLPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean OpenSLPlayback::reset() +bool OpenSLPlayback::reset() { SLDataLocator_AndroidSimpleBufferQueue loc_bufq; SLDataLocator_OutputMix loc_outmix; @@ -518,13 +518,13 @@ ALCboolean OpenSLPlayback::reset() VCALL0(mBufferQueueObj,Destroy)(); mBufferQueueObj = nullptr; - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } -ALCboolean OpenSLPlayback::start() +bool OpenSLPlayback::start() { mRing->reset(); @@ -533,23 +533,23 @@ ALCboolean OpenSLPlayback::start() &bufferQueue)}; PRINTERR(result, "bufferQueue->GetInterface"); if(SL_RESULT_SUCCESS != result) - return ALC_FALSE; + return false; result = VCALL(bufferQueue,RegisterCallback)(&OpenSLPlayback::processC, this); PRINTERR(result, "bufferQueue->RegisterCallback"); - if(SL_RESULT_SUCCESS != result) return ALC_FALSE; + if(SL_RESULT_SUCCESS != result) return false; try { mKillNow.store(false, std::memory_order_release); mThread = std::thread(std::mem_fn(&OpenSLPlayback::mixerProc), this); - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void OpenSLPlayback::stop() @@ -615,9 +615,9 @@ struct OpenSLCapture final : public BackendBase { void process(SLAndroidSimpleBufferQueueItf bq); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; /* engine interfaces */ @@ -815,7 +815,7 @@ ALCenum OpenSLCapture::open(const ALCchar* name) return ALC_NO_ERROR; } -ALCboolean OpenSLCapture::start() +bool OpenSLCapture::start() { SLRecordItf record; SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_RECORD, &record)}; @@ -830,10 +830,10 @@ ALCboolean OpenSLCapture::start() if(SL_RESULT_SUCCESS != result) { aluHandleDisconnect(mDevice, "Failed to start capture: 0x%08x", result); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void OpenSLCapture::stop() @@ -849,7 +849,7 @@ void OpenSLCapture::stop() } } -ALCenum OpenSLCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) { ALuint chunk_size{mDevice->UpdateSize * mFrameSize}; SLAndroidSimpleBufferQueueItf bufferQueue; @@ -866,9 +866,7 @@ ALCenum OpenSLCapture::captureSamples(void *buffer, ALCuint samples) for(i = 0;i < samples;) { ALCuint rem{minu(samples - i, mDevice->UpdateSize - mSplOffset)}; - memcpy(static_cast(buffer) + i*mFrameSize, - data.first.buf + mSplOffset*mFrameSize, - rem * mFrameSize); + memcpy(buffer + i*mFrameSize, data.first.buf + mSplOffset*mFrameSize, rem*mFrameSize); mSplOffset += rem; if(mSplOffset == mDevice->UpdateSize) diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index ffdf3c23..c825ce3e 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -249,8 +249,8 @@ struct OSSPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; int mFd{-1}; @@ -359,7 +359,7 @@ ALCenum OSSPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean OSSPlayback::reset() +bool OSSPlayback::reset() { int ossFormat{}; switch(mDevice->FmtType) @@ -406,7 +406,7 @@ ALCboolean OSSPlayback::reset() { err: ERR("%s failed: %s\n", err, strerror(errno)); - return ALC_FALSE; + return false; } #undef CHECKERR @@ -414,7 +414,7 @@ ALCboolean OSSPlayback::reset() { ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(mDevice->FmtChans), numChannels); - return ALC_FALSE; + return false; } if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte) || @@ -423,7 +423,7 @@ ALCboolean OSSPlayback::reset() { ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(mDevice->FmtType), ossFormat); - return ALC_FALSE; + return false; } mDevice->Frequency = ossSpeed; @@ -434,22 +434,22 @@ ALCboolean OSSPlayback::reset() mMixData.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt()); - return ALC_TRUE; + return true; } -ALCboolean OSSPlayback::start() +bool OSSPlayback::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&OSSPlayback::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void OSSPlayback::stop() @@ -470,9 +470,9 @@ struct OSScapture final : public BackendBase { int recordProc(); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(ALCvoid *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; int mFd{-1}; @@ -646,19 +646,19 @@ ALCenum OSScapture::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean OSScapture::start() +bool OSScapture::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&OSScapture::recordProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create record thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void OSScapture::stop() @@ -671,7 +671,7 @@ void OSScapture::stop() ERR("Error resetting device: %s\n", strerror(errno)); } -ALCenum OSScapture::captureSamples(ALCvoid *buffer, ALCuint samples) +ALCenum OSScapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 4704a806..0b77f622 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -81,8 +81,8 @@ struct PortPlayback final : public BackendBase { const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; PaStream *mStream{nullptr}; @@ -179,7 +179,7 @@ retry_open: } -ALCboolean PortPlayback::reset() +bool PortPlayback::reset() { const PaStreamInfo *streamInfo{Pa_GetStreamInfo(mStream)}; mDevice->Frequency = static_cast(streamInfo->sampleRate); @@ -198,7 +198,7 @@ ALCboolean PortPlayback::reset() else { ERR("Unexpected sample format: 0x%lx\n", mParams.sampleFormat); - return ALC_FALSE; + return false; } if(mParams.channelCount == 2) @@ -208,22 +208,22 @@ ALCboolean PortPlayback::reset() else { ERR("Unexpected channel count: %u\n", mParams.channelCount); - return ALC_FALSE; + return false; } SetDefaultChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean PortPlayback::start() +bool PortPlayback::start() { PaError err{Pa_StartStream(mStream)}; if(err != paNoError) { ERR("Pa_StartStream() returned an error: %s\n", Pa_GetErrorText(err)); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void PortPlayback::stop() @@ -245,9 +245,9 @@ struct PortCapture final : public BackendBase { const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(ALCvoid *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; PaStream *mStream{nullptr}; @@ -341,15 +341,15 @@ ALCenum PortCapture::open(const ALCchar *name) } -ALCboolean PortCapture::start() +bool PortCapture::start() { PaError err{Pa_StartStream(mStream)}; if(err != paNoError) { ERR("Error starting stream: %s\n", Pa_GetErrorText(err)); - return ALC_FALSE; + return false; } - return ALC_TRUE; + return true; } void PortCapture::stop() @@ -363,7 +363,7 @@ void PortCapture::stop() ALCuint PortCapture::availableSamples() { return static_cast(mRing->readSpace()); } -ALCenum PortCapture::captureSamples(ALCvoid *buffer, ALCuint samples) +ALCenum PortCapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 23d4e71a..e9997013 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -666,8 +666,8 @@ struct PulsePlayback final : public BackendBase { void streamMovedCallback(pa_stream *stream); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; ClockLatency getClockLatency() override; void lock() override; @@ -879,7 +879,7 @@ ALCenum PulsePlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean PulsePlayback::reset() +bool PulsePlayback::reset() { std::unique_lock plock{pulse_lock}; @@ -1032,10 +1032,10 @@ ALCboolean PulsePlayback::reset() len, mAttr.prebuf, mDevice->BufferSize); } - return ALC_TRUE; + return true; } -ALCboolean PulsePlayback::start() +bool PulsePlayback::start() { std::unique_lock plock{pulse_lock}; @@ -1043,7 +1043,7 @@ ALCboolean PulsePlayback::start() pa_operation *op{pa_stream_cork(mStream, 0, stream_success_callback, nullptr)}; wait_for_operation(op, plock); - return ALC_TRUE; + return true; } void PulsePlayback::stop() @@ -1110,9 +1110,9 @@ struct PulseCapture final : public BackendBase { void streamMovedCallback(pa_stream *stream); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(ALCvoid *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; ClockLatency getClockLatency() override; void lock() override; @@ -1303,12 +1303,12 @@ ALCenum PulseCapture::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean PulseCapture::start() +bool PulseCapture::start() { std::unique_lock plock{pulse_lock}; pa_operation *op{pa_stream_cork(mStream, 0, stream_success_callback, nullptr)}; wait_for_operation(op, plock); - return ALC_TRUE; + return true; } void PulseCapture::stop() @@ -1318,9 +1318,9 @@ void PulseCapture::stop() wait_for_operation(op, plock); } -ALCenum PulseCapture::captureSamples(ALCvoid *buffer, ALCuint samples) +ALCenum PulseCapture::captureSamples(al::byte *buffer, ALCuint samples) { - al::span dstbuf{static_cast(buffer), samples * pa_frame_size(&mSpec)}; + al::span dstbuf{buffer, samples * pa_frame_size(&mSpec)}; /* Capture is done in fragment-sized chunks, so we loop until we get all * that's available */ diff --git a/alc/backends/qsa.cpp b/alc/backends/qsa.cpp index 64ed53aa..5fee2989 100644 --- a/alc/backends/qsa.cpp +++ b/alc/backends/qsa.cpp @@ -175,8 +175,8 @@ struct PlaybackWrapper final : public BackendBase { ~PlaybackWrapper() override; ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; std::unique_ptr mExtraData; @@ -616,10 +616,10 @@ PlaybackWrapper::~PlaybackWrapper() ALCenum PlaybackWrapper::open(const ALCchar *name) { return qsa_open_playback(this, name); } -ALCboolean PlaybackWrapper::reset() +bool PlaybackWrapper::reset() { return qsa_reset_playback(this); } -ALCboolean PlaybackWrapper::start() +bool PlaybackWrapper::start() { return qsa_start_playback(this); } void PlaybackWrapper::stop() @@ -635,9 +635,9 @@ struct CaptureWrapper final : public BackendBase { ~CaptureWrapper() override; ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; std::unique_ptr mExtraData; @@ -894,13 +894,13 @@ CaptureWrapper::~CaptureWrapper() ALCenum CaptureWrapper::open(const ALCchar *name) { return qsa_open_capture(this, name); } -ALCboolean CaptureWrapper::start() -{ qsa_start_capture(this); return ALC_TRUE; } +bool CaptureWrapper::start() +{ qsa_start_capture(this); return true; } void CaptureWrapper::stop() { qsa_stop_capture(this); } -ALCenum CaptureWrapper::captureSamples(void *buffer, ALCuint samples) +ALCenum CaptureWrapper::captureSamples(al::byte *buffer, ALCuint samples) { return qsa_capture_samples(this, buffer, samples); } ALCuint CaptureWrapper::availableSamples() diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index 6af0ac9d..71616906 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -55,8 +55,8 @@ struct Sdl2Backend final : public BackendBase { void audioCallback(Uint8 *stream, int len); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; void lock() override; void unlock() override; @@ -163,7 +163,7 @@ ALCenum Sdl2Backend::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean Sdl2Backend::reset() +bool Sdl2Backend::reset() { mDevice->Frequency = mFrequency; mDevice->FmtChans = mFmtChans; @@ -171,13 +171,13 @@ ALCboolean Sdl2Backend::reset() mDevice->UpdateSize = mUpdateSize; mDevice->BufferSize = mUpdateSize * 2; SetDefaultWFXChannelOrder(mDevice); - return ALC_TRUE; + return true; } -ALCboolean Sdl2Backend::start() +bool Sdl2Backend::start() { SDL_PauseAudioDevice(mDeviceID, 0); - return ALC_TRUE; + return true; } void Sdl2Backend::stop() diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 4a470e82..d2654853 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -50,8 +50,8 @@ struct SndioPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; sio_hdl *mSndHandle{nullptr}; @@ -124,7 +124,7 @@ ALCenum SndioPlayback::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean SndioPlayback::reset() +bool SndioPlayback::reset() { sio_par par; sio_initpar(&par); @@ -169,13 +169,13 @@ ALCboolean SndioPlayback::reset() if(!sio_setpar(mSndHandle, &par) || !sio_getpar(mSndHandle, &par)) { ERR("Failed to set device parameters\n"); - return ALC_FALSE; + return false; } if(par.bits != par.bps*8) { ERR("Padded samples not supported (%u of %u bits)\n", par.bits, par.bps*8); - return ALC_FALSE; + return true; } mDevice->Frequency = par.rate; @@ -196,7 +196,7 @@ ALCboolean SndioPlayback::reset() else { ERR("Unhandled sample format: %s %u-bit\n", (par.sig?"signed":"unsigned"), par.bits); - return ALC_FALSE; + return false; } SetDefaultChannelOrder(mDevice); @@ -207,21 +207,21 @@ ALCboolean SndioPlayback::reset() mBuffer.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt()); std::fill(mBuffer.begin(), mBuffer.end(), 0); - return ALC_TRUE; + return true; } -ALCboolean SndioPlayback::start() +bool SndioPlayback::start() { if(!sio_start(mSndHandle)) { ERR("Error starting playback\n"); - return ALC_FALSE; + return false; } try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SndioPlayback::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); @@ -229,7 +229,7 @@ ALCboolean SndioPlayback::start() catch(...) { } sio_stop(mSndHandle); - return ALC_FALSE; + return false; } void SndioPlayback::stop() @@ -250,9 +250,9 @@ struct SndioCapture final : public BackendBase { int recordProc(); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; sio_hdl *mSndHandle{nullptr}; @@ -417,18 +417,18 @@ ALCenum SndioCapture::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean SndioCapture::start() +bool SndioCapture::start() { if(!sio_start(mSndHandle)) { ERR("Error starting playback\n"); - return ALC_FALSE; + return false; } try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SndioCapture::recordProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create record thread: %s\n", e.what()); @@ -436,7 +436,7 @@ ALCboolean SndioCapture::start() catch(...) { } sio_stop(mSndHandle); - return ALC_FALSE; + return false; } void SndioCapture::stop() @@ -449,7 +449,7 @@ void SndioCapture::stop() ERR("Error stopping device\n"); } -ALCenum SndioCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum SndioCapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 2e8fe458..128924bb 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -62,8 +62,8 @@ struct SolarisBackend final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; int mFd{-1}; @@ -160,7 +160,7 @@ ALCenum SolarisBackend::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean SolarisBackend::reset() +bool SolarisBackend::reset() { audio_info_t info; AUDIO_INITINFO(&info); @@ -200,14 +200,14 @@ ALCboolean SolarisBackend::reset() if(ioctl(mFd, AUDIO_SETINFO, &info) < 0) { ERR("ioctl failed: %s\n", strerror(errno)); - return ALC_FALSE; + return false; } if(mDevice->channelsFromFmt() != info.play.channels) { ERR("Failed to set %s, got %u channels instead\n", DevFmtChannelsString(mDevice->FmtChans), info.play.channels); - return ALC_FALSE; + return false; } if(!((info.play.precision == 8 && info.play.encoding == AUDIO_ENCODING_LINEAR8 && mDevice->FmtType == DevFmtUByte) || @@ -217,7 +217,7 @@ ALCboolean SolarisBackend::reset() { ERR("Could not set %s samples, got %d (0x%x)\n", DevFmtTypeString(mDevice->FmtType), info.play.precision, info.play.encoding); - return ALC_FALSE; + return false; } mDevice->Frequency = info.play.sample_rate; @@ -229,22 +229,22 @@ ALCboolean SolarisBackend::reset() mBuffer.resize(mDevice->UpdateSize * mDevice->frameSizeFromFmt()); std::fill(mBuffer.begin(), mBuffer.end(), 0); - return ALC_TRUE; + return true; } -ALCboolean SolarisBackend::start() +bool SolarisBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&SolarisBackend::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Could not create playback thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void SolarisBackend::stop() diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 0d04d5a7..0dec5cb9 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -614,9 +614,9 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { HRESULT openProxy() override; void closeProxy() override; - ALCboolean reset() override; + bool reset() override; HRESULT resetProxy() override; - ALCboolean start() override; + bool start() override; HRESULT startProxy() override; void stop() override; void stopProxy() override; @@ -812,10 +812,10 @@ void WasapiPlayback::closeProxy() } -ALCboolean WasapiPlayback::reset() +bool WasapiPlayback::reset() { HRESULT hr{pushMessage(MsgType::ResetDevice).get()}; - return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE; + return SUCCEEDED(hr) ? true : false; } HRESULT WasapiPlayback::resetProxy() @@ -1073,10 +1073,10 @@ HRESULT WasapiPlayback::resetProxy() } -ALCboolean WasapiPlayback::start() +bool WasapiPlayback::start() { HRESULT hr{pushMessage(MsgType::StartDevice).get()}; - return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE; + return SUCCEEDED(hr) ? true : false; } HRESULT WasapiPlayback::startProxy() @@ -1156,12 +1156,12 @@ struct WasapiCapture final : public BackendBase, WasapiProxy { void closeProxy() override; HRESULT resetProxy() override; - ALCboolean start() override; + bool start() override; HRESULT startProxy() override; void stop() override; void stopProxy() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; std::wstring mDevId; @@ -1622,10 +1622,10 @@ HRESULT WasapiCapture::resetProxy() } -ALCboolean WasapiCapture::start() +bool WasapiCapture::start() { HRESULT hr{pushMessage(MsgType::StartDevice).get()}; - return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE; + return SUCCEEDED(hr) ? true : false; } HRESULT WasapiCapture::startProxy() @@ -1687,7 +1687,7 @@ void WasapiCapture::stopProxy() ALCuint WasapiCapture::availableSamples() { return static_cast(mRing->readSpace()); } -ALCenum WasapiCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum WasapiCapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 41d0a880..797a9fa5 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -97,8 +97,8 @@ struct WaveBackend final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; FILE *mFile{nullptr}; @@ -231,7 +231,7 @@ ALCenum WaveBackend::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean WaveBackend::reset() +bool WaveBackend::reset() { ALuint channels=0, bytes=0, chanmask=0; int isbformat = 0; @@ -324,7 +324,7 @@ ALCboolean WaveBackend::reset() if(ferror(mFile)) { ERR("Error writing header: %s\n", strerror(errno)); - return ALC_FALSE; + return false; } mDataStart = ftell(mFile); @@ -333,22 +333,22 @@ ALCboolean WaveBackend::reset() const ALuint bufsize{mDevice->frameSizeFromFmt() * mDevice->UpdateSize}; mBuffer.resize(bufsize); - return ALC_TRUE; + return true; } -ALCboolean WaveBackend::start() +bool WaveBackend::start() { try { mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&WaveBackend::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Failed to start mixing thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void WaveBackend::stop() diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 30a19e13..41c110d7 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -132,8 +132,8 @@ struct WinMMPlayback final : public BackendBase { int mixerProc(); ALCenum open(const ALCchar *name) override; - ALCboolean reset() override; - ALCboolean start() override; + bool reset() override; + bool start() override; void stop() override; std::atomic mWritable{0u}; @@ -263,7 +263,7 @@ retry_open: return ALC_NO_ERROR; } -ALCboolean WinMMPlayback::reset() +bool WinMMPlayback::reset() { mDevice->BufferSize = static_cast(uint64_t{mDevice->BufferSize} * mFormat.nSamplesPerSec / mDevice->Frequency); @@ -278,7 +278,7 @@ ALCboolean WinMMPlayback::reset() else { ERR("Unhandled IEEE float sample depth: %d\n", mFormat.wBitsPerSample); - return ALC_FALSE; + return false; } } else if(mFormat.wFormatTag == WAVE_FORMAT_PCM) @@ -290,13 +290,13 @@ ALCboolean WinMMPlayback::reset() else { ERR("Unhandled PCM sample depth: %d\n", mFormat.wBitsPerSample); - return ALC_FALSE; + return false; } } else { ERR("Unhandled format tag: 0x%04x\n", mFormat.wFormatTag); - return ALC_FALSE; + return false; } if(mFormat.nChannels == 2) @@ -306,7 +306,7 @@ ALCboolean WinMMPlayback::reset() else { ERR("Unhandled channel count: %d\n", mFormat.nChannels); - return ALC_FALSE; + return false; } SetDefaultWFXChannelOrder(mDevice); @@ -324,10 +324,10 @@ ALCboolean WinMMPlayback::reset() } mIdx = 0; - return ALC_TRUE; + return true; } -ALCboolean WinMMPlayback::start() +bool WinMMPlayback::start() { try { std::for_each(mWaveBuffer.begin(), mWaveBuffer.end(), @@ -338,14 +338,14 @@ ALCboolean WinMMPlayback::start() mKillNow.store(false, std::memory_order_release); mThread = std::thread{std::mem_fn(&WinMMPlayback::mixerProc), this}; - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Failed to start mixing thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void WinMMPlayback::stop() @@ -374,9 +374,9 @@ struct WinMMCapture final : public BackendBase { int captureProc(); ALCenum open(const ALCchar *name) override; - ALCboolean start() override; + bool start() override; void stop() override; - ALCenum captureSamples(void *buffer, ALCuint samples) override; + ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; ALCuint availableSamples() override; std::atomic mReadable{0u}; @@ -543,7 +543,7 @@ ALCenum WinMMCapture::open(const ALCchar *name) return ALC_NO_ERROR; } -ALCboolean WinMMCapture::start() +bool WinMMCapture::start() { try { for(size_t i{0};i < mWaveBuffer.size();++i) @@ -556,14 +556,14 @@ ALCboolean WinMMCapture::start() mThread = std::thread{std::mem_fn(&WinMMCapture::captureProc), this}; waveInStart(mInHdl); - return ALC_TRUE; + return true; } catch(std::exception& e) { ERR("Failed to start mixing thread: %s\n", e.what()); } catch(...) { } - return ALC_FALSE; + return false; } void WinMMCapture::stop() @@ -585,7 +585,7 @@ void WinMMCapture::stop() mIdx = 0; } -ALCenum WinMMCapture::captureSamples(void *buffer, ALCuint samples) +ALCenum WinMMCapture::captureSamples(al::byte *buffer, ALCuint samples) { mRing->read(buffer, samples); return ALC_NO_ERROR; -- cgit v1.2.3 From 02d80cd74dd7b4517550af2f4ea22c409323a1d9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 7 Oct 2019 21:37:56 -0700 Subject: Use exceptions for backend open failures --- alc/alc.cpp | 32 +++------ alc/backends/alsa.cpp | 35 ++++------ alc/backends/base.cpp | 3 +- alc/backends/base.h | 2 +- alc/backends/coreaudio.cpp | 165 ++++++++++++++++++++++---------------------- alc/backends/dsound.cpp | 122 ++++++++++++++------------------ alc/backends/jack.cpp | 23 +++--- alc/backends/loopback.cpp | 5 +- alc/backends/null.cpp | 9 ++- alc/backends/opensl.cpp | 120 ++++++++++++++++---------------- alc/backends/oss.cpp | 70 +++++++++---------- alc/backends/portaudio.cpp | 129 ++++++++++++++++------------------ alc/backends/pulseaudio.cpp | 96 ++++++++++++-------------- alc/backends/qsa.cpp | 25 +++++-- alc/backends/sdl2.cpp | 50 +++++++------- alc/backends/sndio.cpp | 85 ++++++++++++----------- alc/backends/solaris.cpp | 11 +-- alc/backends/wasapi.cpp | 25 ++++--- alc/backends/wave.cpp | 14 ++-- alc/backends/winmm.cpp | 67 +++++++++--------- 20 files changed, 524 insertions(+), 564 deletions(-) (limited to 'alc/backends/solaris.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index 119067fd..025395fe 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -3548,16 +3548,9 @@ START_API_FUNC device->NumAuxSends = DEFAULT_SENDS; try { - /* Create the device backend. */ - device->Backend = PlaybackFactory->createBackend(device.get(), BackendType::Playback); - - /* Find a playback device to open */ - ALCenum err{device->Backend->open(deviceName)}; - if(err != ALC_NO_ERROR) - { - alcSetError(nullptr, err); - return nullptr; - } + auto backend = PlaybackFactory->createBackend(device.get(), BackendType::Playback); + backend->open(deviceName); + device->Backend = std::move(backend); } catch(al::backend_exception &e) { WARN("Failed to open playback device: %s\n", e.what()); @@ -3811,17 +3804,13 @@ START_API_FUNC device->BufferSize = static_cast(samples); try { - device->Backend = CaptureFactory->createBackend(device.get(), BackendType::Capture); - TRACE("Capture format: %s, %s, %uhz, %u / %u buffer\n", DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType), device->Frequency, device->UpdateSize, device->BufferSize); - ALCenum err{device->Backend->open(deviceName)}; - if(err != ALC_NO_ERROR) - { - alcSetError(nullptr, err); - return nullptr; - } + + auto backend = CaptureFactory->createBackend(device.get(), BackendType::Capture); + backend->open(deviceName); + device->Backend = std::move(backend); } catch(al::backend_exception &e) { WARN("Failed to open capture device: %s\n", e.what()); @@ -4000,11 +3989,10 @@ START_API_FUNC device->NumMonoSources = device->SourcesMax - device->NumStereoSources; try { - device->Backend = LoopbackBackendFactory::getFactory().createBackend(device.get(), + auto backend = LoopbackBackendFactory::getFactory().createBackend(device.get(), BackendType::Playback); - - // Open the "backend" - device->Backend->open("Loopback"); + backend->open("Loopback"); + device->Backend = std::move(backend); } catch(al::backend_exception &e) { WARN("Failed to open loopback device: %s\n", e.what()); diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index da928171..2e157602 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -40,6 +40,7 @@ #include "albyte.h" #include "alcmain.h" #include "alconfig.h" +#include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" #include "aloptional.h" @@ -394,7 +395,7 @@ struct AlsaPlayback final : public BackendBase { int mixerProc(); int mixerNoMMapProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -592,7 +593,7 @@ int AlsaPlayback::mixerNoMMapProc() } -ALCenum AlsaPlayback::open(const ALCchar *name) +void AlsaPlayback::open(const ALCchar *name) { const char *driver{}; if(name) @@ -605,7 +606,7 @@ ALCenum AlsaPlayback::open(const ALCchar *name) { return entry.name == name; } ); if(iter == PlaybackDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; driver = iter->device_name.c_str(); } else @@ -619,15 +620,14 @@ ALCenum AlsaPlayback::open(const ALCchar *name) if(err < 0) { ERR("Could not open playback device '%s': %s\n", driver, snd_strerror(err)); - return ALC_OUT_OF_MEMORY; + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA playback \"%s\"", + driver}; } /* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */ snd_config_update_free_global(); mDevice->DeviceName = name; - - return ALC_NO_ERROR; } bool AlsaPlayback::reset() @@ -868,7 +868,7 @@ struct AlsaCapture final : public BackendBase { AlsaCapture(ALCdevice *device) noexcept : BackendBase{device} { } ~AlsaCapture() override; - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -895,7 +895,7 @@ AlsaCapture::~AlsaCapture() } -ALCenum AlsaCapture::open(const ALCchar *name) +void AlsaCapture::open(const ALCchar *name) { const char *driver{}; if(name) @@ -908,7 +908,7 @@ ALCenum AlsaCapture::open(const ALCchar *name) { return entry.name == name; } ); if(iter == CaptureDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; driver = iter->device_name.c_str(); } else @@ -922,7 +922,8 @@ ALCenum AlsaCapture::open(const ALCchar *name) if(err < 0) { ERR("Could not open capture device '%s': %s\n", driver, snd_strerror(err)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA capture \"%s\"", + driver}; } /* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */ @@ -994,24 +995,16 @@ ALCenum AlsaCapture::open(const ALCchar *name) if(!mRing) { ERR("ring buffer create failed\n"); - goto error2; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; } } mDevice->DeviceName = name; - - return ALC_NO_ERROR; + return; error: - ERR("%s failed: %s\n", funcerr, snd_strerror(err)); if(hp) snd_pcm_hw_params_free(hp); - -error2: - mRing = nullptr; - snd_pcm_close(mPcmHandle); - mPcmHandle = nullptr; - - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "%s failed: %s", funcerr, snd_strerror(err)}; } diff --git a/alc/backends/base.cpp b/alc/backends/base.cpp index a5f66606..4fce0a67 100644 --- a/alc/backends/base.cpp +++ b/alc/backends/base.cpp @@ -9,6 +9,7 @@ #include "AL/al.h" #include "alcmain.h" +#include "alexcpt.h" #include "alnumeric.h" #include "atomic.h" @@ -29,7 +30,7 @@ BackendBase::BackendBase(ALCdevice *device) noexcept : mDevice{device} BackendBase::~BackendBase() = default; bool BackendBase::reset() -{ return false; } +{ throw al::backend_exception{ALC_INVALID_VALUE, "Invalid BackendVase call"}; } ALCenum BackendBase::captureSamples(al::byte*, ALCuint) { return ALC_INVALID_DEVICE; } diff --git a/alc/backends/base.h b/alc/backends/base.h index 55240fd2..d4856818 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -32,7 +32,7 @@ inline std::chrono::nanoseconds GetDeviceClockTime(ALCdevice *device) ClockLatency GetClockLatency(ALCdevice *device); struct BackendBase { - virtual ALCenum open(const ALCchar *name) = 0; + virtual void open(const ALCchar *name) = 0; virtual bool reset(); virtual bool start() = 0; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 5d004efc..9254dbe0 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -27,6 +27,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "ringbuffer.h" #include "converter.h" @@ -48,17 +49,21 @@ struct CoreAudioPlayback final : public BackendBase { static OSStatus MixerProcC(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, - AudioBufferList *ioData); + AudioBufferList *ioData) + { + return static_cast(inRefCon)->MixerProc(ioActionFlags, inTimeStamp, + inBusNumber, inNumberFrames, ioData); + } OSStatus MixerProc(AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; - AudioUnit mAudioUnit; + AudioUnit mAudioUnit{}; ALuint mFrameSize{0u}; AudioStreamBasicDescription mFormat{}; // This is the OpenAL format as a CoreAudio ASBD @@ -73,14 +78,6 @@ CoreAudioPlayback::~CoreAudioPlayback() } -OSStatus CoreAudioPlayback::MixerProcC(void *inRefCon, - AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) -{ - return static_cast(inRefCon)->MixerProc(ioActionFlags, inTimeStamp, - inBusNumber, inNumberFrames, ioData); -} - OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList *ioData) { @@ -91,12 +88,12 @@ OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, } -ALCenum CoreAudioPlayback::open(const ALCchar *name) +void CoreAudioPlayback::open(const ALCchar *name) { if(!name) name = ca_device; else if(strcmp(name, ca_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; /* open the default output unit */ AudioComponentDescription desc{}; @@ -114,14 +111,15 @@ ALCenum CoreAudioPlayback::open(const ALCchar *name) if(comp == nullptr) { ERR("AudioComponentFindNext failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"}; } OSStatus err{AudioComponentInstanceNew(comp, &mAudioUnit)}; if(err != noErr) { ERR("AudioComponentInstanceNew failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u", + err}; } /* init and start the default audio unit... */ @@ -129,12 +127,10 @@ ALCenum CoreAudioPlayback::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitInitialize failed\n"); - AudioComponentInstanceDispose(mAudioUnit); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool CoreAudioPlayback::reset() @@ -307,12 +303,16 @@ struct CoreAudioCapture final : public BackendBase { static OSStatus RecordProcC(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, - AudioBufferList *ioData); + AudioBufferList *ioData) + { + return static_cast(inRefCon)->RecordProc(ioActionFlags, inTimeStamp, + inBusNumber, inNumberFrames, ioData); + } OSStatus RecordProc(AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -338,23 +338,15 @@ CoreAudioCapture::~CoreAudioCapture() } -OSStatus CoreAudioCapture::RecordProcC(void *inRefCon, - AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, - UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) -{ - return static_cast(inRefCon)->RecordProc(ioActionFlags, inTimeStamp, - inBusNumber, inNumberFrames, ioData); -} - OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, const AudioTimeStamp *inTimeStamp, UInt32, UInt32 inNumberFrames, AudioBufferList*) { AudioUnitRenderActionFlags flags = 0; union { - ALbyte _[sizeof(AudioBufferList) + sizeof(AudioBuffer)*2]; + al::byte _[sizeof(AudioBufferList) + sizeof(AudioBuffer)*2]; AudioBufferList list; - } audiobuf = { { 0 } }; + } audiobuf{}; auto rec_vec = mRing->getWriteVector(); inNumberFrames = static_cast(minz(inNumberFrames, @@ -393,7 +385,7 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, } -ALCenum CoreAudioCapture::open(const ALCchar *name) +void CoreAudioCapture::open(const ALCchar *name) { AudioStreamBasicDescription requestedFormat; // The application requested format AudioStreamBasicDescription hardwareFormat; // The hardware format @@ -412,7 +404,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(!name) name = ca_device; else if(strcmp(name, ca_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; desc.componentType = kAudioUnitType_Output; #if TARGET_OS_IOS @@ -429,7 +421,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(comp == NULL) { ERR("AudioComponentFindNext failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not finda udio component"}; } // Open the component @@ -437,7 +429,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioComponentInstanceNew failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u", + err}; } // Turn off AudioUnit output @@ -447,7 +440,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, + "Could not disable audio unit output property: %u", err}; } // Turn on AudioUnit input @@ -457,7 +451,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, + "Could not enable audio unit input property: %u", err}; } #if !TARGET_OS_IOS @@ -470,16 +465,17 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) propertyAddress.mScope = kAudioObjectPropertyScopeGlobal; propertyAddress.mElement = kAudioObjectPropertyElementMaster; - err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, &inputDevice); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, nullptr, + &propertySize, &inputDevice); if(err != noErr) { ERR("AudioObjectGetPropertyData failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input device: %u", err}; } if(inputDevice == kAudioDeviceUnknown) { ERR("No input device found\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Unknown input device"}; } // Track the input device @@ -488,7 +484,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input device: %u", err}; } } #endif @@ -502,7 +498,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not set capture callback: %u", err}; } // Initialize the device @@ -510,7 +506,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitInitialize failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err}; } // Get the hardware format @@ -520,52 +516,54 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr || propertySize != sizeof(AudioStreamBasicDescription)) { ERR("AudioUnitGetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input format: %u", err}; } // Set up the requested format description switch(mDevice->FmtType) { - case DevFmtUByte: - requestedFormat.mBitsPerChannel = 8; - requestedFormat.mFormatFlags = kAudioFormatFlagIsPacked; - break; - case DevFmtShort: - requestedFormat.mBitsPerChannel = 16; - requestedFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked; - break; - case DevFmtInt: - requestedFormat.mBitsPerChannel = 32; - requestedFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked; - break; - case DevFmtFloat: - requestedFormat.mBitsPerChannel = 32; - requestedFormat.mFormatFlags = kAudioFormatFlagIsPacked; - break; - case DevFmtByte: - case DevFmtUShort: - case DevFmtUInt: - ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); - return ALC_INVALID_VALUE; + case DevFmtUByte: + requestedFormat.mBitsPerChannel = 8; + requestedFormat.mFormatFlags = kAudioFormatFlagIsPacked; + break; + case DevFmtShort: + requestedFormat.mBitsPerChannel = 16; + requestedFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked; + break; + case DevFmtInt: + requestedFormat.mBitsPerChannel = 32; + requestedFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked; + break; + case DevFmtFloat: + requestedFormat.mBitsPerChannel = 32; + requestedFormat.mFormatFlags = kAudioFormatFlagIsPacked; + break; + case DevFmtByte: + case DevFmtUShort: + case DevFmtUInt: + ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not suppoted", + DevFmtTypeString(mDevice->FmtType)}; } switch(mDevice->FmtChans) { - case DevFmtMono: - requestedFormat.mChannelsPerFrame = 1; - break; - case DevFmtStereo: - requestedFormat.mChannelsPerFrame = 2; - break; + case DevFmtMono: + requestedFormat.mChannelsPerFrame = 1; + break; + case DevFmtStereo: + requestedFormat.mChannelsPerFrame = 2; + break; - case DevFmtQuad: - case DevFmtX51: - case DevFmtX51Rear: - case DevFmtX61: - case DevFmtX71: - case DevFmtAmbi3D: - ERR("%s not supported\n", DevFmtChannelsString(mDevice->FmtChans)); - return ALC_INVALID_VALUE; + case DevFmtQuad: + case DevFmtX51: + case DevFmtX51Rear: + case DevFmtX61: + case DevFmtX71: + case DevFmtAmbi3D: + ERR("%s not supported\n", DevFmtChannelsString(mDevice->FmtChans)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s not supported", + DevFmtChannelsString(mDevice->FmtChans)}; } requestedFormat.mBytesPerFrame = requestedFormat.mChannelsPerFrame * requestedFormat.mBitsPerChannel / 8; @@ -591,7 +589,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input format: %u", err}; } // Set the AudioUnit output format frame count @@ -602,7 +600,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(FrameCount64 > std::numeric_limits::max()/2) { ERR("FrameCount too large\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, + "Calculated frame count is too lareg: %" PRIu64, FrameCount64}; } outputFrameCount = static_cast(FrameCount64); @@ -611,7 +610,8 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) if(err != noErr) { ERR("AudioUnitSetProperty failed: %d\n", err); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set capture frame count: %u", + err}; } // Set up sample converter if needed @@ -621,10 +621,9 @@ ALCenum CoreAudioCapture::open(const ALCchar *name) mDevice->Frequency, Resampler::FastBSinc24); mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); - if(!mRing) return ALC_INVALID_VALUE; + if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to allocate ring buffer"}; mDevice->DeviceName = name; - return ALC_NO_ERROR; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index c7014e33..19a3c604 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -45,6 +45,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "ringbuffer.h" #include "compat.h" @@ -166,7 +167,7 @@ struct DSoundPlayback final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -298,7 +299,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() return 0; } -ALCenum DSoundPlayback::open(const ALCchar *name) +void DSoundPlayback::open(const ALCchar *name) { HRESULT hr; if(PlaybackDevices.empty()) @@ -325,7 +326,7 @@ ALCenum DSoundPlayback::open(const ALCchar *name) { return entry.name == name; } ); if(iter == PlaybackDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; guid = &iter->guid; } @@ -341,11 +342,10 @@ ALCenum DSoundPlayback::open(const ALCchar *name) if(FAILED(hr)) { ERR("Device init failed: 0x%08lx\n", hr); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool DSoundPlayback::reset() @@ -596,7 +596,7 @@ struct DSoundCapture final : public BackendBase { DSoundCapture(ALCdevice *device) noexcept : BackendBase{device} { } ~DSoundCapture() override; - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -627,7 +627,7 @@ DSoundCapture::~DSoundCapture() } -ALCenum DSoundCapture::open(const ALCchar *name) +void DSoundCapture::open(const ALCchar *name) { HRESULT hr; if(CaptureDevices.empty()) @@ -654,79 +654,60 @@ ALCenum DSoundCapture::open(const ALCchar *name) { return entry.name == name; } ); if(iter == CaptureDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; guid = &iter->guid; } switch(mDevice->FmtType) { - case DevFmtByte: - case DevFmtUShort: - case DevFmtUInt: - WARN("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); - return ALC_INVALID_ENUM; + case DevFmtByte: + case DevFmtUShort: + case DevFmtUInt: + WARN("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtTypeString(mDevice->FmtType)}; - case DevFmtUByte: - case DevFmtShort: - case DevFmtInt: - case DevFmtFloat: - break; + case DevFmtUByte: + case DevFmtShort: + case DevFmtInt: + case DevFmtFloat: + break; } WAVEFORMATEXTENSIBLE InputType{}; switch(mDevice->FmtChans) { - case DevFmtMono: - InputType.dwChannelMask = SPEAKER_FRONT_CENTER; - break; - case DevFmtStereo: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT; - break; - case DevFmtQuad: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT | - SPEAKER_BACK_LEFT | - SPEAKER_BACK_RIGHT; - break; - case DevFmtX51: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT | - SPEAKER_FRONT_CENTER | - SPEAKER_LOW_FREQUENCY | - SPEAKER_SIDE_LEFT | - SPEAKER_SIDE_RIGHT; - break; - case DevFmtX51Rear: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT | - SPEAKER_FRONT_CENTER | - SPEAKER_LOW_FREQUENCY | - SPEAKER_BACK_LEFT | - SPEAKER_BACK_RIGHT; - break; - case DevFmtX61: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT | - SPEAKER_FRONT_CENTER | - SPEAKER_LOW_FREQUENCY | - SPEAKER_BACK_CENTER | - SPEAKER_SIDE_LEFT | - SPEAKER_SIDE_RIGHT; - break; - case DevFmtX71: - InputType.dwChannelMask = SPEAKER_FRONT_LEFT | - SPEAKER_FRONT_RIGHT | - SPEAKER_FRONT_CENTER | - SPEAKER_LOW_FREQUENCY | - SPEAKER_BACK_LEFT | - SPEAKER_BACK_RIGHT | - SPEAKER_SIDE_LEFT | - SPEAKER_SIDE_RIGHT; - break; - case DevFmtAmbi3D: - WARN("%s capture not supported\n", DevFmtChannelsString(mDevice->FmtChans)); - return ALC_INVALID_ENUM; + case DevFmtMono: + InputType.dwChannelMask = SPEAKER_FRONT_CENTER; + break; + case DevFmtStereo: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; + break; + case DevFmtQuad: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | + SPEAKER_BACK_RIGHT; + break; + case DevFmtX51: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | + SPEAKER_LOW_FREQUENCY | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; + break; + case DevFmtX51Rear: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | + SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; + break; + case DevFmtX61: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | + SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_CENTER | SPEAKER_SIDE_LEFT | SPEAKER_SIDE_RIGHT; + break; + case DevFmtX71: + InputType.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | + SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_SIDE_LEFT | + SPEAKER_SIDE_RIGHT; + break; + case DevFmtAmbi3D: + WARN("%s capture not supported\n", DevFmtChannelsString(mDevice->FmtChans)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture not supported", + DevFmtChannelsString(mDevice->FmtChans)}; } InputType.Format.wFormatTag = WAVE_FORMAT_PCM; @@ -781,14 +762,13 @@ ALCenum DSoundCapture::open(const ALCchar *name) mDSC->Release(); mDSC = nullptr; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } mBufferBytes = DSCBDescription.dwBufferBytes; SetDefaultWFXChannelOrder(mDevice); mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool DSoundCapture::start() diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 660ea933..c7e2839c 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -32,6 +32,7 @@ #include "alcmain.h" #include "alu.h" #include "alconfig.h" +#include "alexcpt.h" #include "dynload.h" #include "ringbuffer.h" #include "threads.h" @@ -153,15 +154,17 @@ struct JackPlayback final : public BackendBase { JackPlayback(ALCdevice *device) noexcept : BackendBase{device} { } ~JackPlayback() override; - static int bufferSizeNotifyC(jack_nframes_t numframes, void *arg); + static int bufferSizeNotifyC(jack_nframes_t numframes, void *arg) + { return static_cast(arg)->bufferSizeNotify(numframes); } int bufferSizeNotify(jack_nframes_t numframes); - static int processC(jack_nframes_t numframes, void *arg); + static int processC(jack_nframes_t numframes, void *arg) + { return static_cast(arg)->process(numframes); } int process(jack_nframes_t numframes); int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -194,9 +197,6 @@ JackPlayback::~JackPlayback() } -int JackPlayback::bufferSizeNotifyC(jack_nframes_t numframes, void *arg) -{ return static_cast(arg)->bufferSizeNotify(numframes); } - int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) { std::lock_guard _{mDevice->StateLock}; @@ -221,9 +221,6 @@ int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) } -int JackPlayback::processC(jack_nframes_t numframes, void *arg) -{ return static_cast(arg)->process(numframes); } - int JackPlayback::process(jack_nframes_t numframes) { jack_default_audio_sample_t *out[MAX_OUTPUT_CHANNELS]; @@ -329,12 +326,12 @@ int JackPlayback::mixerProc() } -ALCenum JackPlayback::open(const ALCchar *name) +void JackPlayback::open(const ALCchar *name) { if(!name) name = jackDevice; else if(strcmp(name, jackDevice) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; const char *client_name{"alsoft"}; jack_status_t status; @@ -342,7 +339,8 @@ ALCenum JackPlayback::open(const ALCchar *name) if(mClient == nullptr) { ERR("jack_client_open() failed, status = 0x%02x\n", status); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to connect to JACK server: 0x%02x", + status}; } if((status&JackServerStarted)) TRACE("JACK server started\n"); @@ -356,7 +354,6 @@ ALCenum JackPlayback::open(const ALCchar *name) jack_set_buffer_size_callback(mClient, &JackPlayback::bufferSizeNotifyC, this); mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool JackPlayback::reset() diff --git a/alc/backends/loopback.cpp b/alc/backends/loopback.cpp index 7edc2d40..511061f3 100644 --- a/alc/backends/loopback.cpp +++ b/alc/backends/loopback.cpp @@ -31,7 +31,7 @@ namespace { struct LoopbackBackend final : public BackendBase { LoopbackBackend(ALCdevice *device) noexcept : BackendBase{device} { } - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -40,10 +40,9 @@ struct LoopbackBackend final : public BackendBase { }; -ALCenum LoopbackBackend::open(const ALCchar *name) +void LoopbackBackend::open(const ALCchar *name) { mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool LoopbackBackend::reset() diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index b6b115f1..aca59605 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -31,6 +31,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "almalloc.h" #include "alu.h" #include "logging.h" @@ -51,7 +52,7 @@ struct NullBackend final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -108,16 +109,14 @@ int NullBackend::mixerProc() } -ALCenum NullBackend::open(const ALCchar *name) +void NullBackend::open(const ALCchar *name) { if(!name) name = nullDevice; else if(strcmp(name, nullDevice) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; mDevice->DeviceName = name; - - return ALC_NO_ERROR; } bool NullBackend::reset() diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 50ea884d..4e4ceb5b 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -28,10 +28,12 @@ #include #include +#include #include #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "compat.h" #include "endiantest.h" @@ -58,26 +60,24 @@ SLuint32 GetChannelMask(DevFmtChannels chans) { switch(chans) { - case DevFmtMono: return SL_SPEAKER_FRONT_CENTER; - case DevFmtStereo: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT; - case DevFmtQuad: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT| - SL_SPEAKER_BACK_LEFT|SL_SPEAKER_BACK_RIGHT; - case DevFmtX51: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT| - SL_SPEAKER_FRONT_CENTER|SL_SPEAKER_LOW_FREQUENCY| - SL_SPEAKER_SIDE_LEFT|SL_SPEAKER_SIDE_RIGHT; - case DevFmtX51Rear: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT| - SL_SPEAKER_FRONT_CENTER|SL_SPEAKER_LOW_FREQUENCY| - SL_SPEAKER_BACK_LEFT|SL_SPEAKER_BACK_RIGHT; - case DevFmtX61: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT| - SL_SPEAKER_FRONT_CENTER|SL_SPEAKER_LOW_FREQUENCY| - SL_SPEAKER_BACK_CENTER| - SL_SPEAKER_SIDE_LEFT|SL_SPEAKER_SIDE_RIGHT; - case DevFmtX71: return SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT| - SL_SPEAKER_FRONT_CENTER|SL_SPEAKER_LOW_FREQUENCY| - SL_SPEAKER_BACK_LEFT|SL_SPEAKER_BACK_RIGHT| - SL_SPEAKER_SIDE_LEFT|SL_SPEAKER_SIDE_RIGHT; - case DevFmtAmbi3D: - break; + case DevFmtMono: return SL_SPEAKER_FRONT_CENTER; + case DevFmtStereo: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + case DevFmtQuad: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | + SL_SPEAKER_BACK_LEFT | SL_SPEAKER_BACK_RIGHT; + case DevFmtX51: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | + SL_SPEAKER_FRONT_CENTER | SL_SPEAKER_LOW_FREQUENCY | SL_SPEAKER_SIDE_LEFT | + SL_SPEAKER_SIDE_RIGHT; + case DevFmtX51Rear: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | + SL_SPEAKER_FRONT_CENTER | SL_SPEAKER_LOW_FREQUENCY | SL_SPEAKER_BACK_LEFT | + SL_SPEAKER_BACK_RIGHT; + case DevFmtX61: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | + SL_SPEAKER_FRONT_CENTER | SL_SPEAKER_LOW_FREQUENCY | SL_SPEAKER_BACK_CENTER | + SL_SPEAKER_SIDE_LEFT | SL_SPEAKER_SIDE_RIGHT; + case DevFmtX71: return SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT | + SL_SPEAKER_FRONT_CENTER | SL_SPEAKER_LOW_FREQUENCY | SL_SPEAKER_BACK_LEFT | + SL_SPEAKER_BACK_RIGHT | SL_SPEAKER_SIDE_LEFT | SL_SPEAKER_SIDE_RIGHT; + case DevFmtAmbi3D: + break; } return 0; } @@ -87,16 +87,16 @@ SLuint32 GetTypeRepresentation(DevFmtType type) { switch(type) { - case DevFmtUByte: - case DevFmtUShort: - case DevFmtUInt: - return SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT; - case DevFmtByte: - case DevFmtShort: - case DevFmtInt: - return SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT; - case DevFmtFloat: - return SL_ANDROID_PCM_REPRESENTATION_FLOAT; + case DevFmtUByte: + case DevFmtUShort: + case DevFmtUInt: + return SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT; + case DevFmtByte: + case DevFmtShort: + case DevFmtInt: + return SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT; + case DevFmtFloat: + return SL_ANDROID_PCM_REPRESENTATION_FLOAT; } return 0; } @@ -106,31 +106,31 @@ const char *res_str(SLresult result) { switch(result) { - case SL_RESULT_SUCCESS: return "Success"; - case SL_RESULT_PRECONDITIONS_VIOLATED: return "Preconditions violated"; - case SL_RESULT_PARAMETER_INVALID: return "Parameter invalid"; - case SL_RESULT_MEMORY_FAILURE: return "Memory failure"; - case SL_RESULT_RESOURCE_ERROR: return "Resource error"; - case SL_RESULT_RESOURCE_LOST: return "Resource lost"; - case SL_RESULT_IO_ERROR: return "I/O error"; - case SL_RESULT_BUFFER_INSUFFICIENT: return "Buffer insufficient"; - case SL_RESULT_CONTENT_CORRUPTED: return "Content corrupted"; - case SL_RESULT_CONTENT_UNSUPPORTED: return "Content unsupported"; - case SL_RESULT_CONTENT_NOT_FOUND: return "Content not found"; - case SL_RESULT_PERMISSION_DENIED: return "Permission denied"; - case SL_RESULT_FEATURE_UNSUPPORTED: return "Feature unsupported"; - case SL_RESULT_INTERNAL_ERROR: return "Internal error"; - case SL_RESULT_UNKNOWN_ERROR: return "Unknown error"; - case SL_RESULT_OPERATION_ABORTED: return "Operation aborted"; - case SL_RESULT_CONTROL_LOST: return "Control lost"; + case SL_RESULT_SUCCESS: return "Success"; + case SL_RESULT_PRECONDITIONS_VIOLATED: return "Preconditions violated"; + case SL_RESULT_PARAMETER_INVALID: return "Parameter invalid"; + case SL_RESULT_MEMORY_FAILURE: return "Memory failure"; + case SL_RESULT_RESOURCE_ERROR: return "Resource error"; + case SL_RESULT_RESOURCE_LOST: return "Resource lost"; + case SL_RESULT_IO_ERROR: return "I/O error"; + case SL_RESULT_BUFFER_INSUFFICIENT: return "Buffer insufficient"; + case SL_RESULT_CONTENT_CORRUPTED: return "Content corrupted"; + case SL_RESULT_CONTENT_UNSUPPORTED: return "Content unsupported"; + case SL_RESULT_CONTENT_NOT_FOUND: return "Content not found"; + case SL_RESULT_PERMISSION_DENIED: return "Permission denied"; + case SL_RESULT_FEATURE_UNSUPPORTED: return "Feature unsupported"; + case SL_RESULT_INTERNAL_ERROR: return "Internal error"; + case SL_RESULT_UNKNOWN_ERROR: return "Unknown error"; + case SL_RESULT_OPERATION_ABORTED: return "Operation aborted"; + case SL_RESULT_CONTROL_LOST: return "Control lost"; #ifdef SL_RESULT_READONLY - case SL_RESULT_READONLY: return "ReadOnly"; + case SL_RESULT_READONLY: return "ReadOnly"; #endif #ifdef SL_RESULT_ENGINEOPTION_UNSUPPORTED - case SL_RESULT_ENGINEOPTION_UNSUPPORTED: return "Engine option unsupported"; + case SL_RESULT_ENGINEOPTION_UNSUPPORTED: return "Engine option unsupported"; #endif #ifdef SL_RESULT_SOURCE_SINK_INCOMPATIBLE - case SL_RESULT_SOURCE_SINK_INCOMPATIBLE: return "Source/Sink incompatible"; + case SL_RESULT_SOURCE_SINK_INCOMPATIBLE: return "Source/Sink incompatible"; #endif } return "Unknown error code"; @@ -152,7 +152,7 @@ struct OpenSLPlayback final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -298,12 +298,12 @@ int OpenSLPlayback::mixerProc() } -ALCenum OpenSLPlayback::open(const ALCchar *name) +void OpenSLPlayback::open(const ALCchar *name) { if(!name) name = opensl_device; else if(strcmp(name, opensl_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; // create engine SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)}; @@ -340,11 +340,11 @@ ALCenum OpenSLPlayback::open(const ALCchar *name) mEngineObj = nullptr; mEngine = nullptr; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x", + result}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool OpenSLPlayback::reset() @@ -635,7 +635,7 @@ struct OpenSLCapture final : public BackendBase { { static_cast(context)->process(bq); } void process(SLAndroidSimpleBufferQueueItf bq); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -676,12 +676,12 @@ void OpenSLCapture::process(SLAndroidSimpleBufferQueueItf) } -ALCenum OpenSLCapture::open(const ALCchar* name) +void OpenSLCapture::open(const ALCchar* name) { if(!name) name = opensl_device; else if(strcmp(name, opensl_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)}; PRINTERR(result, "slCreateEngine"); @@ -841,11 +841,11 @@ ALCenum OpenSLCapture::open(const ALCchar* name) mEngineObj = nullptr; mEngine = nullptr; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x", + result}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool OpenSLCapture::start() diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index c825ce3e..1e3ad28b 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -45,6 +45,7 @@ #include "alcmain.h" #include "alconfig.h" +#include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" #include "aloptional.h" @@ -248,7 +249,7 @@ struct OSSPlayback final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -329,7 +330,7 @@ int OSSPlayback::mixerProc() } -ALCenum OSSPlayback::open(const ALCchar *name) +void OSSPlayback::open(const ALCchar *name) { const char *devname{DefaultPlayback.c_str()}; if(!name) @@ -344,7 +345,7 @@ ALCenum OSSPlayback::open(const ALCchar *name) { return entry.name == name; } ); if(iter == PlaybackDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; devname = iter->device_name.c_str(); } @@ -352,11 +353,11 @@ ALCenum OSSPlayback::open(const ALCchar *name) if(mFd == -1) { ERR("Could not open %s: %s\n", devname, strerror(errno)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname, + strerror(errno)}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool OSSPlayback::reset() @@ -469,7 +470,7 @@ struct OSScapture final : public BackendBase { int recordProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -539,7 +540,7 @@ int OSScapture::recordProc() } -ALCenum OSScapture::open(const ALCchar *name) +void OSScapture::open(const ALCchar *name) { const char *devname{DefaultCapture.c_str()}; if(!name) @@ -554,7 +555,7 @@ ALCenum OSScapture::open(const ALCchar *name) { return entry.name == name; } ); if(iter == CaptureDevices.cend()) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; devname = iter->device_name.c_str(); } @@ -562,27 +563,29 @@ ALCenum OSScapture::open(const ALCchar *name) if(mFd == -1) { ERR("Could not open %s: %s\n", devname, strerror(errno)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname, + strerror(errno)}; } int ossFormat{}; switch(mDevice->FmtType) { - case DevFmtByte: - ossFormat = AFMT_S8; - break; - case DevFmtUByte: - ossFormat = AFMT_U8; - break; - case DevFmtShort: - ossFormat = AFMT_S16_NE; - break; - case DevFmtUShort: - case DevFmtInt: - case DevFmtUInt: - case DevFmtFloat: - ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); - return ALC_INVALID_VALUE; + case DevFmtByte: + ossFormat = AFMT_S8; + break; + case DevFmtUByte: + ossFormat = AFMT_U8; + break; + case DevFmtShort: + ossFormat = AFMT_S16_NE; + break; + case DevFmtUShort: + case DevFmtInt: + case DevFmtUInt: + case DevFmtFloat: + ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtTypeString(mDevice->FmtType)}; } ALuint periods{4}; @@ -608,9 +611,7 @@ ALCenum OSScapture::open(const ALCchar *name) { err: ERR("%s failed: %s\n", err, strerror(errno)); - close(mFd); - mFd = -1; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "%s failed: %s", err, strerror(errno)}; } #undef CHECKERR @@ -618,9 +619,8 @@ ALCenum OSScapture::open(const ALCchar *name) { ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(mDevice->FmtChans), numChannels); - close(mFd); - mFd = -1; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s capture", + DevFmtChannelsString(mDevice->FmtChans)}; } if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte) || @@ -628,22 +628,18 @@ ALCenum OSScapture::open(const ALCchar *name) (ossFormat == AFMT_S16_NE && mDevice->FmtType == DevFmtShort))) { ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(mDevice->FmtType), ossFormat); - close(mFd); - mFd = -1; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s samples", + DevFmtTypeString(mDevice->FmtType)}; } mRing = CreateRingBuffer(mDevice->BufferSize, frameSize, false); if(!mRing) { ERR("Ring buffer create failed\n"); - close(mFd); - mFd = -1; - return ALC_OUT_OF_MEMORY; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool OSScapture::start() diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 0b77f622..7847f41d 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -27,6 +27,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "alconfig.h" #include "dynload.h" @@ -76,11 +77,15 @@ struct PortPlayback final : public BackendBase { static int writeCallbackC(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, - const PaStreamCallbackFlags statusFlags, void *userData); + const PaStreamCallbackFlags statusFlags, void *userData) + { + return static_cast(userData)->writeCallback(inputBuffer, outputBuffer, + framesPerBuffer, timeInfo, statusFlags); + } int writeCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -101,14 +106,6 @@ PortPlayback::~PortPlayback() } -int PortPlayback::writeCallbackC(const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, - const PaStreamCallbackFlags statusFlags, void *userData) -{ - return static_cast(userData)->writeCallback(inputBuffer, outputBuffer, - framesPerBuffer, timeInfo, statusFlags); -} - int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo*, const PaStreamCallbackFlags) @@ -120,12 +117,12 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, } -ALCenum PortPlayback::open(const ALCchar *name) +void PortPlayback::open(const ALCchar *name) { if(!name) name = pa_device; else if(strcmp(name, pa_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; mUpdateSize = mDevice->UpdateSize; @@ -139,25 +136,25 @@ ALCenum PortPlayback::open(const ALCchar *name) switch(mDevice->FmtType) { - case DevFmtByte: - mParams.sampleFormat = paInt8; - break; - case DevFmtUByte: - mParams.sampleFormat = paUInt8; - break; - case DevFmtUShort: - /* fall-through */ - case DevFmtShort: - mParams.sampleFormat = paInt16; - break; - case DevFmtUInt: - /* fall-through */ - case DevFmtInt: - mParams.sampleFormat = paInt32; - break; - case DevFmtFloat: - mParams.sampleFormat = paFloat32; - break; + case DevFmtByte: + mParams.sampleFormat = paInt8; + break; + case DevFmtUByte: + mParams.sampleFormat = paUInt8; + break; + case DevFmtUShort: + /* fall-through */ + case DevFmtShort: + mParams.sampleFormat = paInt16; + break; + case DevFmtUInt: + /* fall-through */ + case DevFmtInt: + mParams.sampleFormat = paInt32; + break; + case DevFmtFloat: + mParams.sampleFormat = paFloat32; + break; } retry_open: @@ -171,12 +168,11 @@ retry_open: goto retry_open; } ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s", + Pa_GetErrorText(err)}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; - } bool PortPlayback::reset() @@ -240,11 +236,15 @@ struct PortCapture final : public BackendBase { static int readCallbackC(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, - const PaStreamCallbackFlags statusFlags, void *userData); + const PaStreamCallbackFlags statusFlags, void *userData) + { + return static_cast(userData)->readCallback(inputBuffer, outputBuffer, + framesPerBuffer, timeInfo, statusFlags); + } int readCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -267,14 +267,6 @@ PortCapture::~PortCapture() } -int PortCapture::readCallbackC(const void *inputBuffer, void *outputBuffer, - unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, - const PaStreamCallbackFlags statusFlags, void* userData) -{ - return static_cast(userData)->readCallback(inputBuffer, outputBuffer, - framesPerBuffer, timeInfo, statusFlags); -} - int PortCapture::readCallback(const void *inputBuffer, void*, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo*, const PaStreamCallbackFlags) @@ -284,19 +276,19 @@ int PortCapture::readCallback(const void *inputBuffer, void*, } -ALCenum PortCapture::open(const ALCchar *name) +void PortCapture::open(const ALCchar *name) { if(!name) name = pa_device; else if(strcmp(name, pa_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; ALuint samples{mDevice->BufferSize}; samples = maxu(samples, 100 * mDevice->Frequency / 1000); ALuint frame_size{mDevice->frameSizeFromFmt()}; mRing = CreateRingBuffer(samples, frame_size, false); - if(!mRing) return ALC_INVALID_VALUE; + if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; auto devidopt = ConfigValueInt(nullptr, "port", "capture"); if(devidopt && *devidopt >= 0) mParams.device = *devidopt; @@ -306,25 +298,26 @@ ALCenum PortCapture::open(const ALCchar *name) switch(mDevice->FmtType) { - case DevFmtByte: - mParams.sampleFormat = paInt8; - break; - case DevFmtUByte: - mParams.sampleFormat = paUInt8; - break; - case DevFmtShort: - mParams.sampleFormat = paInt16; - break; - case DevFmtInt: - mParams.sampleFormat = paInt32; - break; - case DevFmtFloat: - mParams.sampleFormat = paFloat32; - break; - case DevFmtUInt: - case DevFmtUShort: - ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); - return ALC_INVALID_VALUE; + case DevFmtByte: + mParams.sampleFormat = paInt8; + break; + case DevFmtUByte: + mParams.sampleFormat = paUInt8; + break; + case DevFmtShort: + mParams.sampleFormat = paInt16; + break; + case DevFmtInt: + mParams.sampleFormat = paInt32; + break; + case DevFmtFloat: + mParams.sampleFormat = paFloat32; + break; + case DevFmtUInt: + case DevFmtUShort: + ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not supported", + DevFmtTypeString(mDevice->FmtType)}; } mParams.channelCount = static_cast(mDevice->channelsFromFmt()); @@ -333,11 +326,11 @@ ALCenum PortCapture::open(const ALCchar *name) if(err != paNoError) { ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s", + Pa_GetErrorText(err)}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 4d3b34d9..be78ee17 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -663,7 +663,7 @@ struct PulsePlayback final : public BackendBase { static void streamMovedCallbackC(pa_stream *stream, void *pdata); void streamMovedCallback(pa_stream *stream); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -818,7 +818,7 @@ void PulsePlayback::streamMovedCallback(pa_stream *stream) } -ALCenum PulsePlayback::open(const ALCchar *name) +void PulsePlayback::open(const ALCchar *name) { const char *pulse_name{nullptr}; const char *dev_name{nullptr}; @@ -873,8 +873,6 @@ ALCenum PulsePlayback::open(const ALCchar *name) } else mDevice->DeviceName = dev_name; - - return ALC_NO_ERROR; } bool PulsePlayback::reset() @@ -1107,7 +1105,7 @@ struct PulseCapture final : public BackendBase { static void streamMovedCallbackC(pa_stream *stream, void *pdata); void streamMovedCallback(pa_stream *stream); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -1192,7 +1190,7 @@ void PulseCapture::streamMovedCallback(pa_stream *stream) } -ALCenum PulseCapture::open(const ALCchar *name) +void PulseCapture::open(const ALCchar *name) { const char *pulse_name{nullptr}; if(name) @@ -1218,53 +1216,53 @@ ALCenum PulseCapture::open(const ALCchar *name) pa_channel_map chanmap{}; switch(mDevice->FmtChans) { - case DevFmtMono: - chanmap = MonoChanMap; - break; - case DevFmtStereo: - chanmap = StereoChanMap; - break; - case DevFmtQuad: - chanmap = QuadChanMap; - break; - case DevFmtX51: - chanmap = X51ChanMap; - break; - case DevFmtX51Rear: - chanmap = X51RearChanMap; - break; - case DevFmtX61: - chanmap = X61ChanMap; - break; - case DevFmtX71: - chanmap = X71ChanMap; - break; - case DevFmtAmbi3D: - throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", - DevFmtChannelsString(mDevice->FmtChans)}; + case DevFmtMono: + chanmap = MonoChanMap; + break; + case DevFmtStereo: + chanmap = StereoChanMap; + break; + case DevFmtQuad: + chanmap = QuadChanMap; + break; + case DevFmtX51: + chanmap = X51ChanMap; + break; + case DevFmtX51Rear: + chanmap = X51RearChanMap; + break; + case DevFmtX61: + chanmap = X61ChanMap; + break; + case DevFmtX71: + chanmap = X71ChanMap; + break; + case DevFmtAmbi3D: + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtChannelsString(mDevice->FmtChans)}; } SetChannelOrderFromMap(mDevice, chanmap); switch(mDevice->FmtType) { - case DevFmtUByte: - mSilentVal = al::byte(0x80); - mSpec.format = PA_SAMPLE_U8; - break; - case DevFmtShort: - mSpec.format = PA_SAMPLE_S16NE; - break; - case DevFmtInt: - mSpec.format = PA_SAMPLE_S32NE; - break; - case DevFmtFloat: - mSpec.format = PA_SAMPLE_FLOAT32NE; - break; - case DevFmtByte: - case DevFmtUShort: - case DevFmtUInt: - throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", - DevFmtTypeString(mDevice->FmtType)}; + case DevFmtUByte: + mSilentVal = al::byte(0x80); + mSpec.format = PA_SAMPLE_U8; + break; + case DevFmtShort: + mSpec.format = PA_SAMPLE_S16NE; + break; + case DevFmtInt: + mSpec.format = PA_SAMPLE_S32NE; + break; + case DevFmtFloat: + mSpec.format = PA_SAMPLE_FLOAT32NE; + break; + case DevFmtByte: + case DevFmtUShort: + case DevFmtUInt: + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtTypeString(mDevice->FmtType)}; } mSpec.rate = mDevice->Frequency; mSpec.channels = static_cast(mDevice->channelsFromFmt()); @@ -1297,8 +1295,6 @@ ALCenum PulseCapture::open(const ALCchar *name) &PulseCapture::sourceNameCallbackC, this)}; wait_for_operation(op, plock); } - - return ALC_NO_ERROR; } bool PulseCapture::start() diff --git a/alc/backends/qsa.cpp b/alc/backends/qsa.cpp index 5fee2989..872a8541 100644 --- a/alc/backends/qsa.cpp +++ b/alc/backends/qsa.cpp @@ -34,6 +34,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "threads.h" @@ -174,7 +175,7 @@ struct PlaybackWrapper final : public BackendBase { PlaybackWrapper(ALCdevice *device) noexcept : BackendBase{device} { } ~PlaybackWrapper() override; - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -613,11 +614,18 @@ PlaybackWrapper::~PlaybackWrapper() qsa_close_playback(this); } -ALCenum PlaybackWrapper::open(const ALCchar *name) -{ return qsa_open_playback(this, name); } +void PlaybackWrapper::open(const ALCchar *name) +{ + if(auto err = qsa_open_playback(this, name)) + throw al::backend_exception{ALC_INVALID_VALUE, "%d", err}; +} bool PlaybackWrapper::reset() -{ return qsa_reset_playback(this); } +{ + if(!qsa_reset_playback(this)) + throw al::backend_exception{ALC_INVALID_VALUE, ""}; + return true; +} bool PlaybackWrapper::start() { return qsa_start_playback(this); } @@ -634,7 +642,7 @@ struct CaptureWrapper final : public BackendBase { CaptureWrapper(ALCdevice *device) noexcept : BackendBase{device} { } ~CaptureWrapper() override; - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -891,8 +899,11 @@ CaptureWrapper::~CaptureWrapper() qsa_close_capture(this); } -ALCenum CaptureWrapper::open(const ALCchar *name) -{ return qsa_open_capture(this, name); } +void CaptureWrapper::open(const ALCchar *name) +{ + if(auto err = qsa_open_capture(this, name)) + throw al::backend_exception{ALC_INVALID_VALUE, "%d", err}; +} bool CaptureWrapper::start() { qsa_start_capture(this); return true; } diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index 71616906..1063ca7a 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -30,6 +30,7 @@ #include "AL/al.h" #include "alcmain.h" +#include "alexcpt.h" #include "almalloc.h" #include "alu.h" #include "logging.h" @@ -54,7 +55,7 @@ struct Sdl2Backend final : public BackendBase { static void audioCallbackC(void *ptr, Uint8 *stream, int len); void audioCallback(Uint8 *stream, int len); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -89,20 +90,20 @@ void Sdl2Backend::audioCallback(Uint8 *stream, int len) aluMixData(mDevice, stream, ulen / mFrameSize); } -ALCenum Sdl2Backend::open(const ALCchar *name) +void Sdl2Backend::open(const ALCchar *name) { SDL_AudioSpec want{}, have{}; want.freq = static_cast(mDevice->Frequency); switch(mDevice->FmtType) { - case DevFmtUByte: want.format = AUDIO_U8; break; - case DevFmtByte: want.format = AUDIO_S8; break; - case DevFmtUShort: want.format = AUDIO_U16SYS; break; - case DevFmtShort: want.format = AUDIO_S16SYS; break; - case DevFmtUInt: /* fall-through */ - case DevFmtInt: want.format = AUDIO_S32SYS; break; - case DevFmtFloat: want.format = AUDIO_F32; break; + case DevFmtUByte: want.format = AUDIO_U8; break; + case DevFmtByte: want.format = AUDIO_S8; break; + case DevFmtUShort: want.format = AUDIO_U16SYS; break; + case DevFmtShort: want.format = AUDIO_S16SYS; break; + case DevFmtUInt: /* fall-through */ + case DevFmtInt: want.format = AUDIO_S32SYS; break; + case DevFmtFloat: want.format = AUDIO_F32; break; } want.channels = (mDevice->FmtChans == DevFmtMono) ? 1 : 2; want.samples = static_cast(mDevice->UpdateSize); @@ -114,19 +115,19 @@ ALCenum Sdl2Backend::open(const ALCchar *name) */ if(!name || strcmp(name, defaultDeviceName) == 0) mDeviceID = SDL_OpenAudioDevice(nullptr, SDL_FALSE, &want, &have, - SDL_AUDIO_ALLOW_ANY_CHANGE); + SDL_AUDIO_ALLOW_ANY_CHANGE); else { const size_t prefix_len = strlen(DEVNAME_PREFIX); if(strncmp(name, DEVNAME_PREFIX, prefix_len) == 0) mDeviceID = SDL_OpenAudioDevice(name+prefix_len, SDL_FALSE, &want, &have, - SDL_AUDIO_ALLOW_ANY_CHANGE); + SDL_AUDIO_ALLOW_ANY_CHANGE); else mDeviceID = SDL_OpenAudioDevice(name, SDL_FALSE, &want, &have, - SDL_AUDIO_ALLOW_ANY_CHANGE); + SDL_AUDIO_ALLOW_ANY_CHANGE); } if(mDeviceID == 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "%s", SDL_GetError()}; mDevice->Frequency = static_cast(have.freq); if(have.channels == 1) @@ -136,19 +137,21 @@ ALCenum Sdl2Backend::open(const ALCchar *name) else { ERR("Got unhandled SDL channel count: %d\n", int{have.channels}); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL channel count: %d", + int{have.channels}}; } switch(have.format) { - case AUDIO_U8: mDevice->FmtType = DevFmtUByte; break; - case AUDIO_S8: mDevice->FmtType = DevFmtByte; break; - case AUDIO_U16SYS: mDevice->FmtType = DevFmtUShort; break; - case AUDIO_S16SYS: mDevice->FmtType = DevFmtShort; break; - case AUDIO_S32SYS: mDevice->FmtType = DevFmtInt; break; - case AUDIO_F32SYS: mDevice->FmtType = DevFmtFloat; break; - default: - ERR("Got unsupported SDL format: 0x%04x\n", have.format); - return ALC_INVALID_VALUE; + case AUDIO_U8: mDevice->FmtType = DevFmtUByte; break; + case AUDIO_S8: mDevice->FmtType = DevFmtByte; break; + case AUDIO_U16SYS: mDevice->FmtType = DevFmtUShort; break; + case AUDIO_S16SYS: mDevice->FmtType = DevFmtShort; break; + case AUDIO_S32SYS: mDevice->FmtType = DevFmtInt; break; + case AUDIO_F32SYS: mDevice->FmtType = DevFmtFloat; break; + default: + ERR("Got unsupported SDL format: 0x%04x\n", have.format); + throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL format: 0x%04x", + have.format}; } mDevice->UpdateSize = have.samples; mDevice->BufferSize = have.samples * 2; /* SDL always (tries to) use two periods. */ @@ -160,7 +163,6 @@ ALCenum Sdl2Backend::open(const ALCchar *name) mUpdateSize = mDevice->UpdateSize; mDevice->DeviceName = name ? name : defaultDeviceName; - return ALC_NO_ERROR; } bool Sdl2Backend::reset() diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index d2654853..e0c70762 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -30,6 +30,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "threads.h" #include "vector.h" @@ -49,7 +50,7 @@ struct SndioPlayback final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -106,22 +107,21 @@ int SndioPlayback::mixerProc() } -ALCenum SndioPlayback::open(const ALCchar *name) +void SndioPlayback::open(const ALCchar *name) { if(!name) name = sndio_device; else if(strcmp(name, sndio_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; mSndHandle = sio_open(nullptr, SIO_PLAY, 0); if(mSndHandle == nullptr) { ERR("Could not open device\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool SndioPlayback::reset() @@ -249,7 +249,7 @@ struct SndioCapture final : public BackendBase { int recordProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -319,18 +319,18 @@ int SndioCapture::recordProc() } -ALCenum SndioCapture::open(const ALCchar *name) +void SndioCapture::open(const ALCchar *name) { if(!name) name = sndio_device; else if(strcmp(name, sndio_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; mSndHandle = sio_open(nullptr, SIO_REC, 0); if(mSndHandle == nullptr) { ERR("Could not open device\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"}; } sio_par par; @@ -338,33 +338,34 @@ ALCenum SndioCapture::open(const ALCchar *name) switch(mDevice->FmtType) { - case DevFmtByte: - par.bps = 1; - par.sig = 1; - break; - case DevFmtUByte: - par.bps = 1; - par.sig = 0; - break; - case DevFmtShort: - par.bps = 2; - par.sig = 1; - break; - case DevFmtUShort: - par.bps = 2; - par.sig = 0; - break; - case DevFmtInt: - par.bps = 4; - par.sig = 1; - break; - case DevFmtUInt: - par.bps = 4; - par.sig = 0; - break; - case DevFmtFloat: - ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); - return ALC_INVALID_VALUE; + case DevFmtByte: + par.bps = 1; + par.sig = 1; + break; + case DevFmtUByte: + par.bps = 1; + par.sig = 0; + break; + case DevFmtShort: + par.bps = 2; + par.sig = 1; + break; + case DevFmtUShort: + par.bps = 2; + par.sig = 0; + break; + case DevFmtInt: + par.bps = 4; + par.sig = 1; + break; + case DevFmtUInt: + par.bps = 4; + par.sig = 0; + break; + case DevFmtFloat: + ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + DevFmtTypeString(mDevice->FmtType)}; } par.bits = par.bps * 8; par.le = SIO_LE_NATIVE; @@ -381,13 +382,14 @@ ALCenum SndioCapture::open(const ALCchar *name) if(!sio_setpar(mSndHandle, &par) || !sio_getpar(mSndHandle, &par)) { ERR("Failed to set device parameters\n"); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set device praameters"}; } if(par.bits != par.bps*8) { ERR("Padded samples not supported (%u of %u bits)\n", par.bits, par.bps*8); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, + "Padded samples not supported (got %u of %u bits)", par.bits, par.bps*8}; } if(!((mDevice->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0) || @@ -401,20 +403,21 @@ ALCenum SndioCapture::open(const ALCchar *name) ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n", DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not set format %s %s %uhz", + DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), + mDevice->Frequency}; } mRing = CreateRingBuffer(mDevice->BufferSize, par.bps*par.rchan, false); if(!mRing) { ERR("Failed to allocate %u-byte ringbuffer\n", mDevice->BufferSize*par.bps*par.rchan); - return ALC_OUT_OF_MEMORY; + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"}; } SetDefaultChannelOrder(mDevice); mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool SndioCapture::start() diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 128924bb..5963a4b2 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -39,6 +39,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "alconfig.h" #include "threads.h" @@ -61,7 +62,7 @@ struct SolarisBackend final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -142,22 +143,22 @@ int SolarisBackend::mixerProc() } -ALCenum SolarisBackend::open(const ALCchar *name) +void SolarisBackend::open(const ALCchar *name) { if(!name) name = solaris_device; else if(strcmp(name, solaris_device) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; mFd = ::open(solaris_driver.c_str(), O_WRONLY); if(mFd == -1) { ERR("Could not open %s: %s\n", solaris_driver.c_str(), strerror(errno)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", + solaris_driver.c_str(), strerror(errno)}; } mDevice->DeviceName = name; - return ALC_NO_ERROR; } bool SolarisBackend::reset() diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 2a610c8d..b6f5b5fb 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -55,6 +55,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "ringbuffer.h" #include "compat.h" @@ -610,7 +611,7 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; HRESULT openProxy() override; void closeProxy() override; @@ -708,7 +709,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() } -ALCenum WasapiPlayback::open(const ALCchar *name) +void WasapiPlayback::open(const ALCchar *name) { HRESULT hr{S_OK}; @@ -762,10 +763,8 @@ ALCenum WasapiPlayback::open(const ALCchar *name) mDevId.clear(); ERR("Device init failed: 0x%08lx\n", hr); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } - - return ALC_NO_ERROR; } HRESULT WasapiPlayback::openProxy() @@ -815,7 +814,9 @@ void WasapiPlayback::closeProxy() bool WasapiPlayback::reset() { HRESULT hr{pushMessage(MsgType::ResetDevice).get()}; - return SUCCEEDED(hr) ? true : false; + if(FAILED(hr)) + throw al::backend_exception{ALC_INVALID_VALUE, "0x%08lx", hr}; + return true; } HRESULT WasapiPlayback::resetProxy() @@ -1151,7 +1152,7 @@ struct WasapiCapture final : public BackendBase, WasapiProxy { int recordProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; HRESULT openProxy() override; void closeProxy() override; @@ -1283,7 +1284,7 @@ FORCE_ALIGN int WasapiCapture::recordProc() } -ALCenum WasapiCapture::open(const ALCchar *name) +void WasapiCapture::open(const ALCchar *name) { HRESULT hr{S_OK}; @@ -1337,18 +1338,16 @@ ALCenum WasapiCapture::open(const ALCchar *name) mDevId.clear(); ERR("Device init failed: 0x%08lx\n", hr); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } hr = pushMessage(MsgType::ResetDevice).get(); if(FAILED(hr)) { if(hr == E_OUTOFMEMORY) - return ALC_OUT_OF_MEMORY; - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Out of memory"}; + throw al::backend_exception{ALC_INVALID_VALUE, "Device reset failed"}; } - - return ALC_NO_ERROR; } HRESULT WasapiCapture::openProxy() diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 797a9fa5..927cb276 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -38,6 +38,7 @@ #include "albyte.h" #include "alcmain.h" #include "alconfig.h" +#include "alexcpt.h" #include "almalloc.h" #include "alnumeric.h" #include "alu.h" @@ -96,7 +97,7 @@ struct WaveBackend final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -202,15 +203,15 @@ int WaveBackend::mixerProc() return 0; } -ALCenum WaveBackend::open(const ALCchar *name) +void WaveBackend::open(const ALCchar *name) { const char *fname{GetConfigValue(nullptr, "wave", "file", "")}; - if(!fname[0]) return ALC_INVALID_VALUE; + if(!fname[0]) throw al::backend_exception{ALC_INVALID_VALUE, "No wave output filename"}; if(!name) name = waveDevice; else if(strcmp(name, waveDevice) != 0) - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; #ifdef _WIN32 { @@ -223,12 +224,11 @@ ALCenum WaveBackend::open(const ALCchar *name) if(!mFile) { ERR("Could not open file '%s': %s\n", fname, strerror(errno)); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open file '%s': %s", fname, + strerror(errno)}; } mDevice->DeviceName = name; - - return ALC_NO_ERROR; } bool WaveBackend::reset() diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index d58fa959..c287e136 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -38,6 +38,7 @@ #include #include "alcmain.h" +#include "alexcpt.h" #include "alu.h" #include "ringbuffer.h" #include "strutils.h" @@ -131,7 +132,7 @@ struct WinMMPlayback final : public BackendBase { int mixerProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool reset() override; bool start() override; void stop() override; @@ -212,7 +213,7 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() } -ALCenum WinMMPlayback::open(const ALCchar *name) +void WinMMPlayback::open(const ALCchar *name) { if(PlaybackDevices.empty()) ProbePlaybackDevices(); @@ -221,7 +222,8 @@ ALCenum WinMMPlayback::open(const ALCchar *name) auto iter = name ? std::find(PlaybackDevices.cbegin(), PlaybackDevices.cend(), name) : PlaybackDevices.cbegin(); - if(iter == PlaybackDevices.cend()) return ALC_INVALID_VALUE; + if(iter == PlaybackDevices.cend()) + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; auto DeviceID = static_cast(std::distance(PlaybackDevices.cbegin(), iter)); retry_open: @@ -256,11 +258,10 @@ retry_open: goto retry_open; } ERR("waveOutOpen failed: %u\n", res); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "waveOutOpen failed: %u", res}; } mDevice->DeviceName = PlaybackDevices[DeviceID]; - return ALC_NO_ERROR; } bool WinMMPlayback::reset() @@ -373,7 +374,7 @@ struct WinMMCapture final : public BackendBase { int captureProc(); - ALCenum open(const ALCchar *name) override; + void open(const ALCchar *name) override; bool start() override; void stop() override; ALCenum captureSamples(al::byte *buffer, ALCuint samples) override; @@ -456,7 +457,7 @@ int WinMMCapture::captureProc() } -ALCenum WinMMCapture::open(const ALCchar *name) +void WinMMCapture::open(const ALCchar *name) { if(CaptureDevices.empty()) ProbeCaptureDevices(); @@ -465,36 +466,39 @@ ALCenum WinMMCapture::open(const ALCchar *name) auto iter = name ? std::find(CaptureDevices.cbegin(), CaptureDevices.cend(), name) : CaptureDevices.cbegin(); - if(iter == CaptureDevices.cend()) return ALC_INVALID_VALUE; + if(iter == CaptureDevices.cend()) + throw al::backend_exception{ALC_INVALID_VALUE, "Device name \"%s\" not found", name}; auto DeviceID = static_cast(std::distance(CaptureDevices.cbegin(), iter)); switch(mDevice->FmtChans) { - case DevFmtMono: - case DevFmtStereo: - break; - - case DevFmtQuad: - case DevFmtX51: - case DevFmtX51Rear: - case DevFmtX61: - case DevFmtX71: - case DevFmtAmbi3D: - return ALC_INVALID_ENUM; + case DevFmtMono: + case DevFmtStereo: + break; + + case DevFmtQuad: + case DevFmtX51: + case DevFmtX51Rear: + case DevFmtX61: + case DevFmtX71: + case DevFmtAmbi3D: + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture not supported", + DevFmtChannelsString(mDevice->FmtChans)}; } switch(mDevice->FmtType) { - case DevFmtUByte: - case DevFmtShort: - case DevFmtInt: - case DevFmtFloat: - break; - - case DevFmtByte: - case DevFmtUShort: - case DevFmtUInt: - return ALC_INVALID_ENUM; + case DevFmtUByte: + case DevFmtShort: + case DevFmtInt: + case DevFmtFloat: + break; + + case DevFmtByte: + case DevFmtUShort: + case DevFmtUInt: + throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not supported", + DevFmtTypeString(mDevice->FmtType)}; } mFormat = WAVEFORMATEX{}; @@ -513,7 +517,7 @@ ALCenum WinMMCapture::open(const ALCchar *name) if(res != MMSYSERR_NOERROR) { ERR("waveInOpen failed: %u\n", res); - return ALC_INVALID_VALUE; + throw al::backend_exception{ALC_INVALID_VALUE, "waveInOpen failed: %u", res}; } // Ensure each buffer is 50ms each @@ -526,7 +530,7 @@ ALCenum WinMMCapture::open(const ALCchar *name) CapturedDataSize = static_cast(maxz(CapturedDataSize, BufferSize*mWaveBuffer.size())); mRing = CreateRingBuffer(CapturedDataSize, mFormat.nBlockAlign, false); - if(!mRing) return ALC_INVALID_VALUE; + if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Could not create ring buffer"}; al_free(mWaveBuffer[0].lpData); mWaveBuffer[0] = WAVEHDR{}; @@ -540,7 +544,6 @@ ALCenum WinMMCapture::open(const ALCchar *name) } mDevice->DeviceName = CaptureDevices[DeviceID]; - return ALC_NO_ERROR; } bool WinMMCapture::start() -- cgit v1.2.3 From 52a003e9bb7c870f26436b38e62edc96385805dc Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 7 Oct 2019 23:22:06 -0700 Subject: Avoid raw lock/unlock calls --- alc/backends/alsa.cpp | 12 ++++-------- alc/backends/coreaudio.cpp | 3 +-- alc/backends/dsound.cpp | 5 +++-- alc/backends/jack.cpp | 10 ++++------ alc/backends/null.cpp | 3 +-- alc/backends/opensl.cpp | 10 ++++------ alc/backends/oss.cpp | 7 +++---- alc/backends/portaudio.cpp | 3 +-- alc/backends/qsa.cpp | 7 +++---- alc/backends/sndio.cpp | 7 ++++--- alc/backends/solaris.cpp | 7 +++---- alc/backends/wasapi.cpp | 7 +++---- alc/backends/wave.cpp | 7 ++++--- alc/backends/winmm.cpp | 14 ++++++-------- 14 files changed, 44 insertions(+), 58 deletions(-) (limited to 'alc/backends/solaris.cpp') diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 2e157602..a9eb6d5f 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -471,7 +471,7 @@ int AlsaPlayback::mixerProc() avail -= avail%update_size; // it is possible that contiguous areas are smaller, thus we use a loop - lock(); + std::lock_guard _{*this}; while(avail > 0) { snd_pcm_uframes_t frames{avail}; @@ -498,7 +498,6 @@ int AlsaPlayback::mixerProc() avail -= frames; } - unlock(); } return 0; @@ -551,7 +550,7 @@ int AlsaPlayback::mixerNoMMapProc() continue; } - lock(); + std::lock_guard _{*this}; al::byte *WritePtr{mBuffer.data()}; avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast(mBuffer.size())); aluMixData(mDevice, WritePtr, static_cast(avail)); @@ -586,7 +585,6 @@ int AlsaPlayback::mixerNoMMapProc() if(ret < 0) break; } } - unlock(); } return 0; @@ -847,7 +845,7 @@ ClockLatency AlsaPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -858,7 +856,6 @@ ClockLatency AlsaPlayback::getClockLatency() } ret.Latency = std::chrono::seconds{std::max(0, delay)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } @@ -1188,7 +1185,7 @@ ClockLatency AlsaCapture::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); snd_pcm_sframes_t delay{}; int err{snd_pcm_delay(mPcmHandle, &delay)}; @@ -1199,7 +1196,6 @@ ClockLatency AlsaCapture::getClockLatency() } ret.Latency = std::chrono::seconds{std::max(0, delay)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 9254dbe0..3a97c105 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -81,9 +81,8 @@ CoreAudioPlayback::~CoreAudioPlayback() OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, const AudioTimeStamp*, UInt32, UInt32, AudioBufferList *ioData) { - lock(); + std::lock_guard _{*this}; aluMixData(mDevice, ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize/mFrameSize); - unlock(); return noErr; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 19a3c604..d48b74e2 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -276,17 +276,18 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() if(SUCCEEDED(err)) { - lock(); + std::unique_lock dlock{*this}; aluMixData(mDevice, WritePtr1, WriteCnt1/FrameSize); if(WriteCnt2 > 0) aluMixData(mDevice, WritePtr2, WriteCnt2/FrameSize); - unlock(); + dlock.unlock(); mBuffer->Unlock(WritePtr1, WriteCnt1, WritePtr2, WriteCnt2); } else { ERR("Buffer lock error: %#lx\n", err); + std::lock_guard _{*this}; aluHandleDisconnect(mDevice, "Failed to lock output buffer: 0x%lx", err); return 1; } diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index c7e2839c..7c3f1822 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -296,15 +296,15 @@ int JackPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - lock(); + std::unique_lock dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { if(mRing->writeSpace() < mDevice->UpdateSize) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -320,7 +320,6 @@ int JackPlayback::mixerProc() aluMixData(mDevice, data.second.buf, len2); mRing->writeAdvance(todo); } - unlock(); return 0; } @@ -484,11 +483,10 @@ ClockLatency JackPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace()}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index aca59605..bc2a0c9c 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -86,9 +86,8 @@ int NullBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - lock(); + std::lock_guard _{*this}; aluMixData(mDevice, nullptr, mDevice->UpdateSize); - unlock(); done += mDevice->UpdateSize; } diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 4e4ceb5b..f546f168 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -228,7 +228,7 @@ int OpenSLPlayback::mixerProc() PRINTERR(result, "bufferQueue->GetInterface SL_IID_PLAY"); } - lock(); + std::unique_lock dlock{*this}; if(SL_RESULT_SUCCESS != result) aluHandleDisconnect(mDevice, "Failed to get playback buffer: 0x%08x", result); @@ -254,9 +254,9 @@ int OpenSLPlayback::mixerProc() if(mRing->writeSpace() == 0) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } } @@ -292,7 +292,6 @@ int OpenSLPlayback::mixerProc() data.first.buf += mDevice->UpdateSize*mFrameSize; } } - unlock(); return 0; } @@ -617,11 +616,10 @@ ClockLatency OpenSLPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mRing->readSpace() * mDevice->UpdateSize}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 1e3ad28b..5ab07dbe 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -279,7 +279,7 @@ int OSSPlayback::mixerProc() const ALuint frame_size{mDevice->frameSizeFromFmt()}; - lock(); + std::unique_lock dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -287,9 +287,9 @@ int OSSPlayback::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - unlock(); + dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - lock(); + dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) @@ -324,7 +324,6 @@ int OSSPlayback::mixerProc() write_ptr += wrote; } } - unlock(); return 0; } diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 7847f41d..ba8e4984 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -110,9 +110,8 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo*, const PaStreamCallbackFlags) { - lock(); + std::lock_guard _{*this}; aluMixData(mDevice, outputBuffer, static_cast(framesPerBuffer)); - unlock(); return 0; } diff --git a/alc/backends/qsa.cpp b/alc/backends/qsa.cpp index 872a8541..5ed65798 100644 --- a/alc/backends/qsa.cpp +++ b/alc/backends/qsa.cpp @@ -207,7 +207,7 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) const ALint frame_size = device->frameSizeFromFmt(); - self->lock(); + std::unique_lock dlock{*self}; while(!data->mKillNow.load(std::memory_order_acquire)) { pollfd pollitem{}; @@ -215,9 +215,9 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) pollitem.events = POLLOUT; /* Select also works like time slice to OS */ - self->unlock(); + dlock.unlock(); sret = poll(&pollitem, 1, 2000); - self->lock(); + dlock.lock(); if(sret == -1) { if(errno == EINTR || errno == EAGAIN) @@ -266,7 +266,6 @@ FORCE_ALIGN static int qsa_proc_playback(void *ptr) } } } - self->unlock(); return 0; } diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index e0c70762..5657a241 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -85,9 +85,10 @@ int SndioPlayback::mixerProc() ALubyte *WritePtr{mBuffer.data()}; size_t len{mBuffer.size()}; - lock(); - aluMixData(mDevice, WritePtr, static_cast(len/frameSize)); - unlock(); + { + std::lock_guard _{*this}; + aluMixData(mDevice, WritePtr, static_cast(len/frameSize)); + } while(len > 0 && !mKillNow.load(std::memory_order_acquire)) { size_t wrote{sio_write(mSndHandle, WritePtr, len)}; diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 5963a4b2..79cc224d 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -91,7 +91,7 @@ int SolarisBackend::mixerProc() const ALuint frame_size{mDevice->frameSizeFromFmt()}; - lock(); + std::unique_lock dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { @@ -99,9 +99,9 @@ int SolarisBackend::mixerProc() pollitem.fd = mFd; pollitem.events = POLLOUT; - unlock(); + dlock.unlock(); int pret{poll(&pollitem, 1, 1000)}; - lock(); + dlock.lock(); if(pret < 0) { if(errno == EINTR || errno == EAGAIN) @@ -137,7 +137,6 @@ int SolarisBackend::mixerProc() write_ptr += wrote; } } - unlock(); return 0; } diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index b6f5b5fb..181518d0 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -689,10 +689,10 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() hr = mRender->GetBuffer(len, &buffer); if(SUCCEEDED(hr)) { - lock(); + std::unique_lock dlock{*this}; aluMixData(mDevice, buffer, len); mPadding.store(written + len, std::memory_order_relaxed); - unlock(); + dlock.unlock(); hr = mRender->ReleaseBuffer(len, 0); } if(FAILED(hr)) @@ -1136,11 +1136,10 @@ ClockLatency WasapiPlayback::getClockLatency() { ClockLatency ret; - lock(); + std::lock_guard _{*this}; ret.ClockTime = GetDeviceClockTime(mDevice); ret.Latency = std::chrono::seconds{mPadding.load(std::memory_order_relaxed)}; ret.Latency /= mDevice->Frequency; - unlock(); return ret; } diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 927cb276..3b0a30d8 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -145,9 +145,10 @@ int WaveBackend::mixerProc() } while(avail-done >= mDevice->UpdateSize) { - lock(); - aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize); - unlock(); + { + std::lock_guard _{*this}; + aluMixData(mDevice, mBuffer.data(), mDevice->UpdateSize); + } done += mDevice->UpdateSize; if(!IS_LITTLE_ENDIAN) diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index c287e136..8f85f351 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -183,16 +183,16 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); - lock(); + std::unique_lock dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { ALsizei todo = mWritable.load(std::memory_order_acquire); if(todo < 1) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -207,7 +207,6 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() } while(--todo); mIdx = static_cast(widx); } - unlock(); return 0; } @@ -427,16 +426,16 @@ int WinMMCapture::captureProc() { althrd_setname(RECORD_THREAD_NAME); - lock(); + std::unique_lock dlock{*this}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { ALuint todo{mReadable.load(std::memory_order_acquire)}; if(todo < 1) { - unlock(); + dlock.unlock(); mSem.wait(); - lock(); + dlock.lock(); continue; } @@ -451,7 +450,6 @@ int WinMMCapture::captureProc() } while(--todo); mIdx = static_cast(widx); } - unlock(); return 0; } -- cgit v1.2.3 From 7726a06d26e59dc6a8e109af2e268de878c4f606 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 8 Oct 2019 05:44:38 -0700 Subject: Clean up some exception messages and avoid duplicate log messages --- alc/backends/alsa.cpp | 16 +++----------- alc/backends/coreaudio.cpp | 54 ++------------------------------------------- alc/backends/dsound.cpp | 5 ----- alc/backends/jack.cpp | 6 ++--- alc/backends/opensl.cpp | 12 +++++----- alc/backends/oss.cpp | 46 +++++++++----------------------------- alc/backends/portaudio.cpp | 5 ----- alc/backends/pulseaudio.cpp | 2 +- alc/backends/sdl2.cpp | 12 ++++------ alc/backends/sndio.cpp | 47 +++++++++++---------------------------- alc/backends/solaris.cpp | 3 --- alc/backends/wasapi.cpp | 2 -- alc/backends/wave.cpp | 3 --- alc/backends/winmm.cpp | 17 ++++---------- 14 files changed, 46 insertions(+), 184 deletions(-) (limited to 'alc/backends/solaris.cpp') diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index a9eb6d5f..7c6ce4f9 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -616,11 +616,8 @@ void AlsaPlayback::open(const ALCchar *name) TRACE("Opening device \"%s\"\n", driver); int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)}; if(err < 0) - { - ERR("Could not open playback device '%s': %s\n", driver, snd_strerror(err)); - throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA playback \"%s\"", + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA device \"%s\"", driver}; - } /* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */ snd_config_update_free_global(); @@ -917,11 +914,8 @@ void AlsaCapture::open(const ALCchar *name) TRACE("Opening device \"%s\"\n", driver); int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)}; if(err < 0) - { - ERR("Could not open capture device '%s': %s\n", driver, snd_strerror(err)); - throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA capture \"%s\"", + throw al::backend_exception{ALC_OUT_OF_MEMORY, "Could not open ALSA device \"%s\"", driver}; - } /* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */ snd_config_update_free_global(); @@ -989,11 +983,7 @@ void AlsaCapture::open(const ALCchar *name) if(needring) { mRing = CreateRingBuffer(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false); - if(!mRing) - { - ERR("ring buffer create failed\n"); - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; - } + if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; } mDevice->DeviceName = name; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 3a97c105..9e1d4e47 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -108,26 +108,17 @@ void CoreAudioPlayback::open(const ALCchar *name) AudioComponent comp{AudioComponentFindNext(NULL, &desc)}; if(comp == nullptr) - { - ERR("AudioComponentFindNext failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"}; - } OSStatus err{AudioComponentInstanceNew(comp, &mAudioUnit)}; if(err != noErr) - { - ERR("AudioComponentInstanceNew failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u", err}; - } /* init and start the default audio unit... */ err = AudioUnitInitialize(mAudioUnit); if(err != noErr) - { - ERR("AudioUnitInitialize failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err}; - } mDevice->DeviceName = name; } @@ -418,41 +409,29 @@ void CoreAudioCapture::open(const ALCchar *name) // Search for component with given description comp = AudioComponentFindNext(NULL, &desc); if(comp == NULL) - { - ERR("AudioComponentFindNext failed\n"); - throw al::backend_exception{ALC_INVALID_VALUE, "Could not finda udio component"}; - } + throw al::backend_exception{ALC_INVALID_VALUE, "Could not find audio component"}; // Open the component err = AudioComponentInstanceNew(comp, &mAudioUnit); if(err != noErr) - { - ERR("AudioComponentInstanceNew failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not create component instance: %u", err}; - } // Turn off AudioUnit output enableIO = 0; err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(ALuint)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not disable audio unit output property: %u", err}; - } // Turn on AudioUnit input enableIO = 1; err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &enableIO, sizeof(ALuint)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not enable audio unit input property: %u", err}; - } #if !TARGET_OS_IOS { @@ -467,24 +446,15 @@ void CoreAudioCapture::open(const ALCchar *name) err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, nullptr, &propertySize, &inputDevice); if(err != noErr) - { - ERR("AudioObjectGetPropertyData failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input device: %u", err}; - } if(inputDevice == kAudioDeviceUnknown) - { - ERR("No input device found\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Unknown input device"}; - } // Track the input device err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &inputDevice, sizeof(AudioDeviceID)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input device: %u", err}; - } } #endif @@ -495,28 +465,19 @@ void CoreAudioCapture::open(const ALCchar *name) err = AudioUnitSetProperty(mAudioUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &input, sizeof(AURenderCallbackStruct)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not set capture callback: %u", err}; - } // Initialize the device err = AudioUnitInitialize(mAudioUnit); if(err != noErr) - { - ERR("AudioUnitInitialize failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not initialize audio unit: %u", err}; - } // Get the hardware format propertySize = sizeof(AudioStreamBasicDescription); err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 1, &hardwareFormat, &propertySize); if(err != noErr || propertySize != sizeof(AudioStreamBasicDescription)) - { - ERR("AudioUnitGetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not get input format: %u", err}; - } // Set up the requested format description switch(mDevice->FmtType) @@ -540,7 +501,6 @@ void CoreAudioCapture::open(const ALCchar *name) case DevFmtByte: case DevFmtUShort: case DevFmtUInt: - ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not suppoted", DevFmtTypeString(mDevice->FmtType)}; } @@ -560,7 +520,6 @@ void CoreAudioCapture::open(const ALCchar *name) case DevFmtX61: case DevFmtX71: case DevFmtAmbi3D: - ERR("%s not supported\n", DevFmtChannelsString(mDevice->FmtChans)); throw al::backend_exception{ALC_INVALID_VALUE, "%s not supported", DevFmtChannelsString(mDevice->FmtChans)}; } @@ -586,10 +545,7 @@ void CoreAudioCapture::open(const ALCchar *name) err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &outputFormat, sizeof(outputFormat)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Could not set input format: %u", err}; - } // Set the AudioUnit output format frame count uint64_t FrameCount64{mDevice->UpdateSize}; @@ -597,21 +553,15 @@ void CoreAudioCapture::open(const ALCchar *name) mDevice->Frequency; FrameCount64 += MAX_RESAMPLER_PADDING; if(FrameCount64 > std::numeric_limits::max()/2) - { - ERR("FrameCount too large\n"); throw al::backend_exception{ALC_INVALID_VALUE, - "Calculated frame count is too lareg: %" PRIu64, FrameCount64}; - } + "Calculated frame count is too large: %" PRIu64, FrameCount64}; outputFrameCount = static_cast(FrameCount64); err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Output, 0, &outputFrameCount, sizeof(outputFrameCount)); if(err != noErr) - { - ERR("AudioUnitSetProperty failed: %d\n", err); throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set capture frame count: %u", err}; - } // Set up sample converter if needed if(outputFormat.mSampleRate != mDevice->Frequency) diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index d48b74e2..005c9584 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -341,10 +341,7 @@ void DSoundPlayback::open(const ALCchar *name) if(SUCCEEDED(hr)) hr = mDS->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY); if(FAILED(hr)) - { - ERR("Device init failed: 0x%08lx\n", hr); throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; - } mDevice->DeviceName = name; } @@ -753,8 +750,6 @@ void DSoundCapture::open(const ALCchar *name) if(FAILED(hr)) { - ERR("Device init failed: 0x%08lx\n", hr); - mRing = nullptr; if(mDSCbuffer) mDSCbuffer->Release(); diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 7c3f1822..2a22ed84 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -336,11 +336,9 @@ void JackPlayback::open(const ALCchar *name) jack_status_t status; mClient = jack_client_open(client_name, ClientOptions, &status, nullptr); if(mClient == nullptr) - { - ERR("jack_client_open() failed, status = 0x%02x\n", status); - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to connect to JACK server: 0x%02x", + throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open client connection: 0x%02x", status}; - } + if((status&JackServerStarted)) TRACE("JACK server started\n"); if((status&JackNameNotUnique)) diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index f546f168..4e68da27 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -146,9 +146,9 @@ struct OpenSLPlayback final : public BackendBase { OpenSLPlayback(ALCdevice *device) noexcept : BackendBase{device} { } ~OpenSLPlayback() override; + void process(SLAndroidSimpleBufferQueueItf bq); static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) { static_cast(context)->process(bq); } - void process(SLAndroidSimpleBufferQueueItf bq); int mixerProc(); @@ -339,8 +339,8 @@ void OpenSLPlayback::open(const ALCchar *name) mEngineObj = nullptr; mEngine = nullptr; - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x", - result}; + throw al::backend_exception{ALC_INVALID_VALUE, + "Failed to initialize OpenSL device: 0x%08x", result}; } mDevice->DeviceName = name; @@ -629,9 +629,9 @@ struct OpenSLCapture final : public BackendBase { OpenSLCapture(ALCdevice *device) noexcept : BackendBase{device} { } ~OpenSLCapture() override; + void process(SLAndroidSimpleBufferQueueItf bq); static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) { static_cast(context)->process(bq); } - void process(SLAndroidSimpleBufferQueueItf bq); void open(const ALCchar *name) override; bool start() override; @@ -839,8 +839,8 @@ void OpenSLCapture::open(const ALCchar* name) mEngineObj = nullptr; mEngine = nullptr; - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to initialize OpenSL: 0x%08x", - result}; + throw al::backend_exception{ALC_INVALID_VALUE, + "Failed to initialize OpenSL device: 0x%08x", result}; } mDevice->DeviceName = name; diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 5ab07dbe..856aceb0 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -350,11 +350,8 @@ void OSSPlayback::open(const ALCchar *name) mFd = ::open(devname, O_WRONLY); if(mFd == -1) - { - ERR("Could not open %s: %s\n", devname, strerror(errno)); throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname, strerror(errno)}; - } mDevice->DeviceName = name; } @@ -560,11 +557,8 @@ void OSScapture::open(const ALCchar *name) mFd = ::open(devname, O_RDONLY); if(mFd == -1) - { - ERR("Could not open %s: %s\n", devname, strerror(errno)); throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", devname, strerror(errno)}; - } int ossFormat{}; switch(mDevice->FmtType) @@ -582,7 +576,6 @@ void OSScapture::open(const ALCchar *name) case DevFmtInt: case DevFmtUInt: case DevFmtFloat: - ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", DevFmtTypeString(mDevice->FmtType)}; } @@ -596,47 +589,30 @@ void OSScapture::open(const ALCchar *name) ALuint numFragmentsLogSize{(periods << 16) | log2FragmentSize}; audio_buf_info info{}; - const char *err; #define CHECKERR(func) if((func) < 0) { \ - err = #func; \ - goto err; \ + throw al::backend_exception{ALC_INVALID_VALUE, #func " failed: %s", strerror(errno)}; \ } CHECKERR(ioctl(mFd, SNDCTL_DSP_SETFRAGMENT, &numFragmentsLogSize)); CHECKERR(ioctl(mFd, SNDCTL_DSP_SETFMT, &ossFormat)); CHECKERR(ioctl(mFd, SNDCTL_DSP_CHANNELS, &numChannels)); CHECKERR(ioctl(mFd, SNDCTL_DSP_SPEED, &ossSpeed)); CHECKERR(ioctl(mFd, SNDCTL_DSP_GETISPACE, &info)); - if(0) - { - err: - ERR("%s failed: %s\n", err, strerror(errno)); - throw al::backend_exception{ALC_INVALID_VALUE, "%s failed: %s", err, strerror(errno)}; - } #undef CHECKERR if(mDevice->channelsFromFmt() != numChannels) - { - ERR("Failed to set %s, got %d channels instead\n", DevFmtChannelsString(mDevice->FmtChans), - numChannels); - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s capture", - DevFmtChannelsString(mDevice->FmtChans)}; - } + throw al::backend_exception{ALC_INVALID_VALUE, + "Failed to set %s, got %d channels instead", DevFmtChannelsString(mDevice->FmtChans), + numChannels}; - if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte) || - (ossFormat == AFMT_U8 && mDevice->FmtType == DevFmtUByte) || - (ossFormat == AFMT_S16_NE && mDevice->FmtType == DevFmtShort))) - { - ERR("Failed to set %s samples, got OSS format %#x\n", DevFmtTypeString(mDevice->FmtType), ossFormat); - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set %s samples", - DevFmtTypeString(mDevice->FmtType)}; - } + if(!((ossFormat == AFMT_S8 && mDevice->FmtType == DevFmtByte) + || (ossFormat == AFMT_U8 && mDevice->FmtType == DevFmtUByte) + || (ossFormat == AFMT_S16_NE && mDevice->FmtType == DevFmtShort))) + throw al::backend_exception{ALC_INVALID_VALUE, + "Failed to set %s samples, got OSS format %#x", DevFmtTypeString(mDevice->FmtType), + ossFormat}; mRing = CreateRingBuffer(mDevice->BufferSize, frameSize, false); - if(!mRing) - { - ERR("Ring buffer create failed\n"); - throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; - } + if(!mRing) throw al::backend_exception{ALC_INVALID_VALUE, "Failed to create ring buffer"}; mDevice->DeviceName = name; } diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index ba8e4984..7c60d2bb 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -166,7 +166,6 @@ retry_open: mParams.sampleFormat = paInt16; goto retry_open; } - ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err)); throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s", Pa_GetErrorText(err)}; } @@ -314,7 +313,6 @@ void PortCapture::open(const ALCchar *name) break; case DevFmtUInt: case DevFmtUShort: - ERR("%s samples not supported\n", DevFmtTypeString(mDevice->FmtType)); throw al::backend_exception{ALC_INVALID_VALUE, "%s samples not supported", DevFmtTypeString(mDevice->FmtType)}; } @@ -323,11 +321,8 @@ void PortCapture::open(const ALCchar *name) PaError err{Pa_OpenStream(&mStream, &mParams, nullptr, mDevice->Frequency, paFramesPerBufferUnspecified, paNoFlag, &PortCapture::readCallbackC, this)}; if(err != paNoError) - { - ERR("Pa_OpenStream() returned an error: %s\n", Pa_GetErrorText(err)); throw al::backend_exception{ALC_INVALID_VALUE, "Failed to open stream: %s", Pa_GetErrorText(err)}; - } mDevice->DeviceName = name; } diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index e4b1baa2..2521084d 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -1211,7 +1211,7 @@ void PulseCapture::open(const ALCchar *name) chanmap = X71ChanMap; break; case DevFmtAmbi3D: - throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", + throw al::backend_exception{ALC_INVALID_VALUE, "%s capture not supported", DevFmtChannelsString(mDevice->FmtChans)}; } SetChannelOrderFromMap(mDevice, chanmap); diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index 1063ca7a..4cdf05b4 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -52,8 +52,9 @@ struct Sdl2Backend final : public BackendBase { Sdl2Backend(ALCdevice *device) noexcept : BackendBase{device} { } ~Sdl2Backend() override; - static void audioCallbackC(void *ptr, Uint8 *stream, int len); void audioCallback(Uint8 *stream, int len); + static void audioCallbackC(void *ptr, Uint8 *stream, int len) + { static_cast(ptr)->audioCallback(stream, len); } void open(const ALCchar *name) override; bool reset() override; @@ -80,9 +81,6 @@ Sdl2Backend::~Sdl2Backend() mDeviceID = 0; } -void Sdl2Backend::audioCallbackC(void *ptr, Uint8 *stream, int len) -{ static_cast(ptr)->audioCallback(stream, len); } - void Sdl2Backend::audioCallback(Uint8 *stream, int len) { const auto ulen = static_cast(len); @@ -130,16 +128,15 @@ void Sdl2Backend::open(const ALCchar *name) throw al::backend_exception{ALC_INVALID_VALUE, "%s", SDL_GetError()}; mDevice->Frequency = static_cast(have.freq); + if(have.channels == 1) mDevice->FmtChans = DevFmtMono; else if(have.channels == 2) mDevice->FmtChans = DevFmtStereo; else - { - ERR("Got unhandled SDL channel count: %d\n", int{have.channels}); throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL channel count: %d", int{have.channels}}; - } + switch(have.format) { case AUDIO_U8: mDevice->FmtType = DevFmtUByte; break; @@ -149,7 +146,6 @@ void Sdl2Backend::open(const ALCchar *name) case AUDIO_S32SYS: mDevice->FmtType = DevFmtInt; break; case AUDIO_F32SYS: mDevice->FmtType = DevFmtFloat; break; default: - ERR("Got unsupported SDL format: 0x%04x\n", have.format); throw al::backend_exception{ALC_INVALID_VALUE, "Unhandled SDL format: 0x%04x", have.format}; } diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 5657a241..026ff2b9 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -117,10 +117,7 @@ void SndioPlayback::open(const ALCchar *name) mSndHandle = sio_open(nullptr, SIO_PLAY, 0); if(mSndHandle == nullptr) - { - ERR("Could not open device\n"); - throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"}; - } + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open backend device"}; mDevice->DeviceName = name; } @@ -329,10 +326,7 @@ void SndioCapture::open(const ALCchar *name) mSndHandle = sio_open(nullptr, SIO_REC, 0); if(mSndHandle == nullptr) - { - ERR("Could not open device\n"); - throw al::backend_exception{ALC_INVALID_VALUE, "Could not open sound device"}; - } + throw al::backend_exception{ALC_INVALID_VALUE, "Could not open backend device"}; sio_par par; sio_initpar(&par); @@ -364,7 +358,6 @@ void SndioCapture::open(const ALCchar *name) par.sig = 0; break; case DevFmtFloat: - ERR("%s capture samples not supported\n", DevFmtTypeString(mDevice->FmtType)); throw al::backend_exception{ALC_INVALID_VALUE, "%s capture samples not supported", DevFmtTypeString(mDevice->FmtType)}; } @@ -381,40 +374,26 @@ void SndioCapture::open(const ALCchar *name) mDevice->BufferSize = par.appbufsz; if(!sio_setpar(mSndHandle, &par) || !sio_getpar(mSndHandle, &par)) - { - ERR("Failed to set device parameters\n"); throw al::backend_exception{ALC_INVALID_VALUE, "Failed to set device praameters"}; - } if(par.bits != par.bps*8) - { - ERR("Padded samples not supported (%u of %u bits)\n", par.bits, par.bps*8); throw al::backend_exception{ALC_INVALID_VALUE, "Padded samples not supported (got %u of %u bits)", par.bits, par.bps*8}; - } - if(!((mDevice->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0) || - (mDevice->FmtType == DevFmtUByte && par.bits == 8 && par.sig == 0) || - (mDevice->FmtType == DevFmtShort && par.bits == 16 && par.sig != 0) || - (mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) || - (mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) || - (mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) || - mDevice->channelsFromFmt() != par.rchan || mDevice->Frequency != par.rate) - { - ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n", - DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), - mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate); - throw al::backend_exception{ALC_INVALID_VALUE, "Could not set format %s %s %uhz", + if(!((mDevice->FmtType == DevFmtByte && par.bits == 8 && par.sig != 0) + || (mDevice->FmtType == DevFmtUByte && par.bits == 8 && par.sig == 0) + || (mDevice->FmtType == DevFmtShort && par.bits == 16 && par.sig != 0) + || (mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) + || (mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) + || (mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) + || mDevice->channelsFromFmt() != par.rchan || mDevice->Frequency != par.rate) + throw al::backend_exception{ALC_INVALID_VALUE, + "Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead", DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), - mDevice->Frequency}; - } + mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate}; mRing = CreateRingBuffer(mDevice->BufferSize, par.bps*par.rchan, false); - if(!mRing) - { - ERR("Failed to allocate %u-byte ringbuffer\n", mDevice->BufferSize*par.bps*par.rchan); - throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"}; - } + if(!mRing) throw al::backend_exception{ALC_OUT_OF_MEMORY, "Failed to allocate ring buffer"}; SetDefaultChannelOrder(mDevice); diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 79cc224d..7cc2606e 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -151,11 +151,8 @@ void SolarisBackend::open(const ALCchar *name) mFd = ::open(solaris_driver.c_str(), O_WRONLY); if(mFd == -1) - { - ERR("Could not open %s: %s\n", solaris_driver.c_str(), strerror(errno)); throw al::backend_exception{ALC_INVALID_VALUE, "Could not open %s: %s", solaris_driver.c_str(), strerror(errno)}; - } mDevice->DeviceName = name; } diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 181518d0..2c4fe130 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -762,7 +762,6 @@ void WasapiPlayback::open(const ALCchar *name) mDevId.clear(); - ERR("Device init failed: 0x%08lx\n", hr); throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } } @@ -1336,7 +1335,6 @@ void WasapiCapture::open(const ALCchar *name) mDevId.clear(); - ERR("Device init failed: 0x%08lx\n", hr); throw al::backend_exception{ALC_INVALID_VALUE, "Device init failed: 0x%08lx", hr}; } diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 3b0a30d8..7bcc3436 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -223,11 +223,8 @@ void WaveBackend::open(const ALCchar *name) mFile = fopen(fname, "wb"); #endif if(!mFile) - { - ERR("Could not open file '%s': %s\n", fname, strerror(errno)); throw al::backend_exception{ALC_INVALID_VALUE, "Could not open file '%s': %s", fname, strerror(errno)}; - } mDevice->DeviceName = name; } diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 8f85f351..dde74304 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -127,8 +127,9 @@ struct WinMMPlayback final : public BackendBase { WinMMPlayback(ALCdevice *device) noexcept : BackendBase{device} { } ~WinMMPlayback() override; - static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2); void CALLBACK waveOutProc(HWAVEOUT device, UINT msg, DWORD_PTR param1, DWORD_PTR param2); + static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) + { reinterpret_cast(instance)->waveOutProc(device, msg, param1, param2); } int mixerProc(); @@ -162,10 +163,6 @@ WinMMPlayback::~WinMMPlayback() std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{}); } - -void CALLBACK WinMMPlayback::waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) -{ reinterpret_cast(instance)->waveOutProc(device, msg, param1, param2); } - /* WinMMPlayback::waveOutProc * * Posts a message to 'WinMMPlayback::mixerProc' everytime a WaveOut Buffer is @@ -256,7 +253,6 @@ retry_open: mDevice->FmtType = DevFmtShort; goto retry_open; } - ERR("waveOutOpen failed: %u\n", res); throw al::backend_exception{ALC_INVALID_VALUE, "waveOutOpen failed: %u", res}; } @@ -368,8 +364,9 @@ struct WinMMCapture final : public BackendBase { WinMMCapture(ALCdevice *device) noexcept : BackendBase{device} { } ~WinMMCapture() override; - static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2); void CALLBACK waveInProc(HWAVEIN device, UINT msg, DWORD_PTR param1, DWORD_PTR param2); + static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) + { reinterpret_cast(instance)->waveInProc(device, msg, param1, param2); } int captureProc(); @@ -407,9 +404,6 @@ WinMMCapture::~WinMMCapture() std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{}); } -void CALLBACK WinMMCapture::waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2) -{ reinterpret_cast(instance)->waveInProc(device, msg, param1, param2); } - /* WinMMCapture::waveInProc * * Posts a message to 'WinMMCapture::captureProc' everytime a WaveIn Buffer is @@ -513,10 +507,7 @@ void WinMMCapture::open(const ALCchar *name) reinterpret_cast(&WinMMCapture::waveInProcC), reinterpret_cast(this), CALLBACK_FUNCTION)}; if(res != MMSYSERR_NOERROR) - { - ERR("waveInOpen failed: %u\n", res); throw al::backend_exception{ALC_INVALID_VALUE, "waveInOpen failed: %u", res}; - } // Ensure each buffer is 50ms each DWORD BufferSize{mFormat.nAvgBytesPerSec / 20u}; -- cgit v1.2.3