From 7cda37a67c8f147536c53f0073df9a9e61d40587 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 4 May 2023 08:03:40 -0700 Subject: Replace al::optional with std::optional --- alc/backends/oss.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'alc/backends/oss.cpp') diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 6d4fa261..f76024f4 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -45,7 +45,6 @@ #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" -#include "aloptional.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" -- cgit v1.2.3 From 7cbf3ba2e2bab5c3aecb001e1d387c89309dbec4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 4 May 2023 11:39:13 -0700 Subject: Use std::byte instead of a custom al::byte --- CMakeLists.txt | 1 - al/buffer.cpp | 14 ++++---- al/buffer.h | 4 +-- al/event.cpp | 1 - alc/alc.cpp | 4 +-- alc/backends/alsa.cpp | 15 ++++---- alc/backends/base.cpp | 2 +- alc/backends/base.h | 4 +-- alc/backends/coreaudio.cpp | 6 ++-- alc/backends/dsound.cpp | 4 +-- alc/backends/oboe.cpp | 4 +-- alc/backends/opensl.cpp | 6 ++-- alc/backends/oss.cpp | 9 +++-- alc/backends/pipewire.cpp | 10 +++--- alc/backends/portaudio.cpp | 4 +-- alc/backends/pulseaudio.cpp | 15 ++++---- alc/backends/sndio.cpp | 16 ++++----- alc/backends/solaris.cpp | 7 ++-- alc/backends/wasapi.cpp | 4 +-- alc/backends/wave.cpp | 3 +- alc/backends/winmm.cpp | 4 +-- alc/effects/convolution.cpp | 3 +- common/albyte.h | 17 --------- common/ringbuffer.cpp | 85 ++++++++++++++++++++++----------------------- common/ringbuffer.h | 39 ++++++++++----------- core/buffer_storage.h | 4 +-- core/converter.cpp | 10 +++--- core/effects/base.h | 1 - core/fmt_traits.h | 20 +++++------ core/hrtf.cpp | 6 ++-- core/voice.cpp | 35 +++++++++---------- core/voice.h | 5 ++- utils/uhjdecoder.cpp | 53 ++++++++++++++-------------- 33 files changed, 191 insertions(+), 224 deletions(-) delete mode 100644 common/albyte.h (limited to 'alc/backends/oss.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 07377ddb..fe46a688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -589,7 +589,6 @@ check_symbol_exists(getopt unistd.h HAVE_GETOPT) # router, and certain tools and examples. set(COMMON_OBJS common/albit.h - common/albyte.h common/alcomplex.cpp common/alcomplex.h common/aldeque.h diff --git a/al/buffer.cpp b/al/buffer.cpp index ad74a7f7..1a042f46 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -44,7 +45,6 @@ #include "AL/alext.h" #include "albit.h" -#include "albyte.h" #include "alc/context.h" #include "alc/device.h" #include "alc/inprogext.h" @@ -277,7 +277,7 @@ ALuint SanitizeAlignment(FmtType type, ALuint align) /** Loads the specified data into the buffer, using the specified format. */ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, - const FmtChannels DstChannels, const FmtType DstType, const al::byte *SrcData, + const FmtChannels DstChannels, const FmtType DstType, const std::byte *SrcData, ALbitfieldSOFT access) { if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) UNLIKELY @@ -343,7 +343,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, */ if(newsize != ALBuf->mDataStorage.size()) { - auto newdata = al::vector(newsize, al::byte{}); + auto newdata = al::vector(newsize, std::byte{}); if((access&AL_PRESERVE_DATA_BIT_SOFT)) { const size_t tocopy{minz(newdata.size(), ALBuf->mDataStorage.size())}; @@ -437,7 +437,7 @@ void PrepareCallback(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, /** Prepares the buffer to use caller-specified storage. */ void PrepareUserPtr(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, - const FmtChannels DstChannels, const FmtType DstType, al::byte *sdata, const ALuint sdatalen) + const FmtChannels DstChannels, const FmtType DstType, std::byte *sdata, const ALuint sdatalen) { if(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) UNLIKELY return context->setError(AL_INVALID_OPERATION, "Modifying storage for in-use buffer %u", @@ -506,7 +506,7 @@ void PrepareUserPtr(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, #endif decltype(ALBuf->mDataStorage){}.swap(ALBuf->mDataStorage); - ALBuf->mData = {static_cast(sdata), sdatalen}; + ALBuf->mData = {static_cast(sdata), sdatalen}; #ifdef ALSOFT_EAX eax_x_ram_clear(*context->mALDevice, *ALBuf); @@ -767,7 +767,7 @@ START_API_FUNC else { LoadData(context.get(), albuf, freq, static_cast(size), usrfmt->channels, - usrfmt->type, static_cast(data), flags); + usrfmt->type, static_cast(data), flags); } } } @@ -796,7 +796,7 @@ START_API_FUNC return context->setError(AL_INVALID_ENUM, "Invalid format 0x%04x", format); PrepareUserPtr(context.get(), albuf, freq, usrfmt->channels, usrfmt->type, - static_cast(data), static_cast(size)); + static_cast(data), static_cast(size)); } END_API_FUNC diff --git a/al/buffer.h b/al/buffer.h index 64ebe1f3..3df1fa4c 100644 --- a/al/buffer.h +++ b/al/buffer.h @@ -2,10 +2,10 @@ #define AL_BUFFER_H #include +#include #include "AL/al.h" -#include "albyte.h" #include "alc/inprogext.h" #include "almalloc.h" #include "atomic.h" @@ -26,7 +26,7 @@ enum class EaxStorage : uint8_t { struct ALbuffer : public BufferStorage { ALbitfieldSOFT Access{0u}; - al::vector mDataStorage; + al::vector mDataStorage; ALuint OriginalSize{0}; diff --git a/al/event.cpp b/al/event.cpp index 1bc39d1e..acb4958a 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -17,7 +17,6 @@ #include "AL/al.h" #include "AL/alc.h" -#include "albyte.h" #include "alc/context.h" #include "alc/effects/base.h" #include "alc/inprogext.h" diff --git a/alc/alc.cpp b/alc/alc.cpp index 149223f4..d226b39d 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -68,7 +69,6 @@ #include "al/listener.h" #include "al/source.h" #include "albit.h" -#include "albyte.h" #include "alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -3883,7 +3883,7 @@ START_API_FUNC return; } - backend->captureSamples(static_cast(buffer), usamples); + backend->captureSamples(static_cast(buffer), usamples); } END_API_FUNC diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index b162f84e..74713590 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -36,7 +36,6 @@ #include #include "albit.h" -#include "albyte.h" #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -439,7 +438,7 @@ struct AlsaPlayback final : public BackendBase { std::mutex mMutex; uint mFrameStep{}; - al::vector mBuffer; + al::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; @@ -585,7 +584,7 @@ int AlsaPlayback::mixerNoMMapProc() continue; } - al::byte *WritePtr{mBuffer.data()}; + std::byte *WritePtr{mBuffer.data()}; avail = snd_pcm_bytes_to_frames(mPcmHandle, static_cast(mBuffer.size())); std::lock_guard _{mMutex}; mDevice->renderSamples(WritePtr, static_cast(avail), mFrameStep); @@ -874,13 +873,13 @@ struct AlsaCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; ClockLatency getClockLatency() override; snd_pcm_t *mPcmHandle{nullptr}; - al::vector mBuffer; + al::vector mBuffer; bool mDoCapture{false}; RingBufferPtr mRing{nullptr}; @@ -1024,7 +1023,7 @@ void AlsaCapture::stop() /* The ring buffer implicitly captures when checking availability. * Direct access needs to explicitly capture it into temp storage. */ - auto temp = al::vector( + auto temp = al::vector( static_cast(snd_pcm_frames_to_bytes(mPcmHandle, avail))); captureSamples(temp.data(), avail); mBuffer = std::move(temp); @@ -1035,7 +1034,7 @@ void AlsaCapture::stop() mDoCapture = false; } -void AlsaCapture::captureSamples(al::byte *buffer, uint samples) +void AlsaCapture::captureSamples(std::byte *buffer, uint samples) { if(mRing) { @@ -1093,7 +1092,7 @@ void AlsaCapture::captureSamples(al::byte *buffer, uint samples) } if(samples > 0) std::fill_n(buffer, snd_pcm_frames_to_bytes(mPcmHandle, samples), - al::byte((mDevice->FmtType == DevFmtUByte) ? 0x80 : 0)); + std::byte((mDevice->FmtType == DevFmtUByte) ? 0x80 : 0)); } uint AlsaCapture::availableSamples() diff --git a/alc/backends/base.cpp b/alc/backends/base.cpp index 45254c47..ab3ad028 100644 --- a/alc/backends/base.cpp +++ b/alc/backends/base.cpp @@ -37,7 +37,7 @@ backend_exception::~backend_exception() = default; bool BackendBase::reset() { throw al::backend_exception{al::backend_error::DeviceError, "Invalid BackendBase call"}; } -void BackendBase::captureSamples(al::byte*, uint) +void BackendBase::captureSamples(std::byte*, uint) { } uint BackendBase::availableSamples() diff --git a/alc/backends/base.h b/alc/backends/base.h index b6b3d922..07b430e0 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -3,11 +3,11 @@ #include #include +#include #include #include #include -#include "albyte.h" #include "core/device.h" #include "core/except.h" @@ -26,7 +26,7 @@ struct BackendBase { virtual void start() = 0; virtual void stop() = 0; - virtual void captureSamples(al::byte *buffer, uint samples); + virtual void captureSamples(std::byte *buffer, uint samples); virtual uint availableSamples(); virtual ClockLatency getClockLatency(); diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index ae220d7a..19a1f753 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -568,7 +568,7 @@ struct CoreAudioCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; AudioUnit mAudioUnit{0}; @@ -598,7 +598,7 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags *ioActionFlags, AudioBufferList*) noexcept { union { - al::byte _[maxz(sizeof(AudioBufferList), offsetof(AudioBufferList, mBuffers[1]))]; + std::byte _[maxz(sizeof(AudioBufferList), offsetof(AudioBufferList, mBuffers[1]))]; AudioBufferList list; } audiobuf{}; @@ -878,7 +878,7 @@ void CoreAudioCapture::stop() ERR("AudioOutputUnitStop failed: '%s' (%u)\n", FourCCPrinter{err}.c_str(), err); } -void CoreAudioCapture::captureSamples(al::byte *buffer, uint samples) +void CoreAudioCapture::captureSamples(std::byte *buffer, uint samples) { if(!mConverter) { diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 8b967c95..05117781 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -551,7 +551,7 @@ struct DSoundCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; ComPtr mDSC; @@ -717,7 +717,7 @@ void DSoundCapture::stop() } } -void DSoundCapture::captureSamples(al::byte *buffer, uint samples) +void DSoundCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } uint DSoundCapture::availableSamples() diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp index 461f5a6a..4c47190e 100644 --- a/alc/backends/oboe.cpp +++ b/alc/backends/oboe.cpp @@ -215,7 +215,7 @@ struct OboeCapture final : public BackendBase, public oboe::AudioStreamCallback void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; }; @@ -322,7 +322,7 @@ void OboeCapture::stop() uint OboeCapture::availableSamples() { return static_cast(mRing->readSpace()); } -void OboeCapture::captureSamples(al::byte *buffer, uint samples) +void OboeCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } } // namespace diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index f5b98fb8..0c2936b2 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -648,7 +648,7 @@ struct OpenSLCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; /* engine interfaces */ @@ -819,7 +819,7 @@ void OpenSLCapture::open(const char* name) if(SL_RESULT_SUCCESS == result) { const uint chunk_size{mDevice->UpdateSize * mFrameSize}; - const auto silence = (mDevice->FmtType == DevFmtUByte) ? al::byte{0x80} : al::byte{0}; + const auto silence = (mDevice->FmtType == DevFmtUByte) ? std::byte{0x80} : std::byte{0}; auto data = mRing->getWriteVector(); std::fill_n(data.first.buf, data.first.len*chunk_size, silence); @@ -883,7 +883,7 @@ void OpenSLCapture::stop() } } -void OpenSLCapture::captureSamples(al::byte *buffer, uint samples) +void OpenSLCapture::captureSamples(std::byte *buffer, uint samples) { const uint update_size{mDevice->UpdateSize}; const uint chunk_size{update_size * mFrameSize}; diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index f76024f4..9e247be1 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -41,7 +41,6 @@ #include #include -#include "albyte.h" #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -237,7 +236,7 @@ struct OSSPlayback final : public BackendBase { int mFd{-1}; - al::vector mMixData; + al::vector mMixData; std::atomic mKillNow{true}; std::thread mThread; @@ -283,7 +282,7 @@ int OSSPlayback::mixerProc() continue; } - al::byte *write_ptr{mMixData.data()}; + std::byte *write_ptr{mMixData.data()}; size_t to_write{mMixData.size()}; mDevice->renderSamples(write_ptr, static_cast(to_write/frame_size), frame_step); while(to_write > 0 && !mKillNow.load(std::memory_order_acquire)) @@ -449,7 +448,7 @@ struct OSScapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; int mFd{-1}; @@ -619,7 +618,7 @@ void OSScapture::stop() ERR("Error resetting device: %s\n", strerror(errno)); } -void OSScapture::captureSamples(al::byte *buffer, uint samples) +void OSScapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } uint OSScapture::availableSamples() diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 5b1596aa..3f372a4a 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,6 @@ #include #include "albit.h" -#include "albyte.h" #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -1528,7 +1528,7 @@ bool PipeWirePlayback::reset() * magic value. */ constexpr uint32_t pod_buffer_size{1024}; - auto pod_buffer = std::make_unique(pod_buffer_size); + auto pod_buffer = std::make_unique(pod_buffer_size); spa_pod_builder b{make_pod_builder(pod_buffer.get(), pod_buffer_size)}; const spa_pod *params{spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &info)}; @@ -1793,7 +1793,7 @@ class PipeWireCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; uint64_t mTargetId{PwIdAny}; @@ -1954,7 +1954,7 @@ void PipeWireCapture::open(const char *name) spa_audio_info_raw info{make_spa_info(mDevice, is51rear, UseDevType)}; constexpr uint32_t pod_buffer_size{1024}; - auto pod_buffer = std::make_unique(pod_buffer_size); + auto pod_buffer = std::make_unique(pod_buffer_size); spa_pod_builder b{make_pod_builder(pod_buffer.get(), pod_buffer_size)}; const spa_pod *params[]{spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &info)}; @@ -2055,7 +2055,7 @@ void PipeWireCapture::stop() uint PipeWireCapture::availableSamples() { return static_cast(mRing->readSpace()); } -void PipeWireCapture::captureSamples(al::byte *buffer, uint samples) +void PipeWireCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } } // namespace diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index d652d4cd..2551f448 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -248,7 +248,7 @@ struct PortCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; PaStream *mStream{nullptr}; @@ -349,7 +349,7 @@ void PortCapture::stop() uint PortCapture::availableSamples() { return static_cast(mRing->readSpace()); } -void PortCapture::captureSamples(al::byte *buffer, uint samples) +void PortCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } } // namespace diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 6e8bfe1b..e5696817 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -39,7 +39,6 @@ #include #include "albit.h" -#include "albyte.h" #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -1037,7 +1036,7 @@ struct PulseCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; ClockLatency getClockLatency() override; @@ -1045,12 +1044,12 @@ struct PulseCapture final : public BackendBase { std::optional mDeviceName{std::nullopt}; - al::span mCapBuffer; + al::span mCapBuffer; size_t mHoleLength{0}; size_t mPacketLength{0}; uint mLastReadable{0u}; - al::byte mSilentVal{}; + std::byte mSilentVal{}; pa_buffer_attr mAttr{}; pa_sample_spec mSpec{}; @@ -1159,7 +1158,7 @@ void PulseCapture::open(const char *name) switch(mDevice->FmtType) { case DevFmtUByte: - mSilentVal = al::byte(0x80); + mSilentVal = std::byte(0x80); mSpec.format = PA_SAMPLE_U8; break; case DevFmtShort: @@ -1231,9 +1230,9 @@ void PulseCapture::stop() plock.waitForOperation(op); } -void PulseCapture::captureSamples(al::byte *buffer, uint samples) +void PulseCapture::captureSamples(std::byte *buffer, uint samples) { - al::span dstbuf{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. @@ -1291,7 +1290,7 @@ void PulseCapture::captureSamples(al::byte *buffer, uint samples) if(!capbuf) UNLIKELY mHoleLength = caplen; else - mCapBuffer = {static_cast(capbuf), caplen}; + mCapBuffer = {static_cast(capbuf), caplen}; mPacketLength = caplen; } if(!dstbuf.empty()) diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 077e77f2..2040dd3a 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "alnumeric.h" #include "core/device.h" @@ -36,7 +37,6 @@ #include "core/logging.h" #include "ringbuffer.h" #include "threads.h" -#include "vector.h" #include @@ -65,7 +65,7 @@ struct SndioPlayback final : public BackendBase { sio_hdl *mSndHandle{nullptr}; uint mFrameStep{}; - al::vector mBuffer; + std::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; @@ -91,7 +91,7 @@ int SndioPlayback::mixerProc() while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { - al::span buffer{mBuffer}; + al::span buffer{mBuffer}; mDevice->renderSamples(buffer.data(), static_cast(buffer.size() / frameSize), frameStep); @@ -231,9 +231,9 @@ retry_params: mBuffer.resize(mDevice->UpdateSize * par.pchan*par.bps); if(par.sig == 1) - std::fill(mBuffer.begin(), mBuffer.end(), al::byte{}); + std::fill(mBuffer.begin(), mBuffer.end(), std::byte{}); else if(par.bits == 8) - std::fill_n(mBuffer.data(), mBuffer.size(), al::byte(0x80)); + std::fill_n(mBuffer.data(), mBuffer.size(), std::byte(0x80)); else if(par.bits == 16) std::fill_n(reinterpret_cast(mBuffer.data()), mBuffer.size()/2, 0x8000); else if(par.bits == 32) @@ -283,7 +283,7 @@ struct SndioCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; sio_hdl *mSndHandle{nullptr}; @@ -349,7 +349,7 @@ int SndioCapture::recordProc() continue; auto data = mRing->getWriteVector(); - al::span buffer{data.first.buf, data.first.len*frameSize}; + al::span buffer{data.first.buf, data.first.len*frameSize}; while(!buffer.empty()) { size_t got{sio_read(mSndHandle, buffer.data(), buffer.size())}; @@ -496,7 +496,7 @@ void SndioCapture::stop() ERR("Error stopping device\n"); } -void SndioCapture::captureSamples(al::byte *buffer, uint samples) +void SndioCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } uint SndioCapture::availableSamples() diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 791609ce..4eeeafac 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -39,7 +39,6 @@ #include #include -#include "albyte.h" #include "alc/alconfig.h" #include "core/device.h" #include "core/helpers.h" @@ -71,7 +70,7 @@ struct SolarisBackend final : public BackendBase { int mFd{-1}; uint mFrameStep{}; - al::vector mBuffer; + al::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; @@ -116,7 +115,7 @@ int SolarisBackend::mixerProc() continue; } - al::byte *write_ptr{mBuffer.data()}; + std::byte *write_ptr{mBuffer.data()}; size_t to_write{mBuffer.size()}; mDevice->renderSamples(write_ptr, static_cast(to_write/frame_size), frame_step); while(to_write > 0 && !mKillNow.load(std::memory_order_acquire)) @@ -231,7 +230,7 @@ bool SolarisBackend::reset() setDefaultChannelOrder(); mBuffer.resize(mDevice->UpdateSize * size_t{frame_size}); - std::fill(mBuffer.begin(), mBuffer.end(), al::byte{}); + std::fill(mBuffer.begin(), mBuffer.end(), std::byte{}); return true; } diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index ea6ecbe0..16576733 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1309,7 +1309,7 @@ struct WasapiCapture final : public BackendBase, WasapiProxy { void stop() override; void stopProxy() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; HRESULT mOpenStatus{E_FAIL}; @@ -1881,7 +1881,7 @@ void WasapiCapture::stopProxy() } -void WasapiCapture::captureSamples(al::byte *buffer, uint samples) +void WasapiCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } uint WasapiCapture::availableSamples() diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 1b40640c..f8302f1e 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -34,7 +34,6 @@ #include #include "albit.h" -#include "albyte.h" #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" @@ -105,7 +104,7 @@ struct WaveBackend final : public BackendBase { FILE *mFile{nullptr}; long mDataStart{-1}; - al::vector mBuffer; + al::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 38e1193f..135b59df 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -372,7 +372,7 @@ struct WinMMCapture final : public BackendBase { void open(const char *name) override; void start() override; void stop() override; - void captureSamples(al::byte *buffer, uint samples) override; + void captureSamples(std::byte *buffer, uint samples) override; uint availableSamples() override; std::atomic mReadable{0u}; @@ -571,7 +571,7 @@ void WinMMCapture::stop() mIdx = 0; } -void WinMMCapture::captureSamples(al::byte *buffer, uint samples) +void WinMMCapture::captureSamples(std::byte *buffer, uint samples) { mRing->read(buffer, samples); } uint WinMMCapture::availableSamples() diff --git a/alc/effects/convolution.cpp b/alc/effects/convolution.cpp index 7f36c415..4ca31246 100644 --- a/alc/effects/convolution.cpp +++ b/alc/effects/convolution.cpp @@ -17,7 +17,6 @@ #include #endif -#include "albyte.h" #include "alcomplex.h" #include "almalloc.h" #include "alnumbers.h" @@ -72,7 +71,7 @@ namespace { */ -void LoadSamples(float *RESTRICT dst, const al::byte *src, const size_t srcstep, FmtType srctype, +void LoadSamples(float *RESTRICT dst, const std::byte *src, const size_t srcstep, FmtType srctype, const size_t samples) noexcept { #define HANDLE_FMT(T) case T: al::LoadSampleArray(dst, src, srcstep, samples); break diff --git a/common/albyte.h b/common/albyte.h deleted file mode 100644 index be586869..00000000 --- a/common/albyte.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef AL_BYTE_H -#define AL_BYTE_H - -#include -#include -#include -#include - -using uint = unsigned int; - -namespace al { - -using byte = unsigned char; - -} // namespace al - -#endif /* AL_BYTE_H */ diff --git a/common/ringbuffer.cpp b/common/ringbuffer.cpp index 0aec1d49..af1f3669 100644 --- a/common/ringbuffer.cpp +++ b/common/ringbuffer.cpp @@ -29,9 +29,9 @@ #include "almalloc.h" -RingBufferPtr RingBuffer::Create(size_t sz, size_t elem_sz, int limit_writes) +RingBufferPtr RingBuffer::Create(std::size_t sz, std::size_t elem_sz, int limit_writes) { - size_t power_of_two{0u}; + std::size_t power_of_two{0u}; if(sz > 0) { power_of_two = sz; @@ -40,15 +40,14 @@ RingBufferPtr RingBuffer::Create(size_t sz, size_t elem_sz, int limit_writes) power_of_two |= power_of_two>>4; power_of_two |= power_of_two>>8; power_of_two |= power_of_two>>16; -#if SIZE_MAX > UINT_MAX - power_of_two |= power_of_two>>32; -#endif + if constexpr(SIZE_MAX > UINT_MAX) + power_of_two |= power_of_two>>32; } ++power_of_two; - if(power_of_two <= sz || power_of_two > std::numeric_limits::max()/elem_sz) + if(power_of_two <= sz || power_of_two > std::numeric_limits::max()/elem_sz) throw std::overflow_error{"Ring buffer size overflow"}; - const size_t bufbytes{power_of_two * elem_sz}; + const std::size_t bufbytes{power_of_two * elem_sz}; RingBufferPtr rb{new(FamCount(bufbytes)) RingBuffer{bufbytes}}; rb->mWriteSize = limit_writes ? sz : (power_of_two-1); rb->mSizeMask = power_of_two - 1; @@ -61,20 +60,20 @@ void RingBuffer::reset() noexcept { mWritePtr.store(0, std::memory_order_relaxed); mReadPtr.store(0, std::memory_order_relaxed); - std::fill_n(mBuffer.begin(), (mSizeMask+1)*mElemSize, al::byte{}); + std::fill_n(mBuffer.begin(), (mSizeMask+1)*mElemSize, std::byte{}); } -size_t RingBuffer::read(void *dest, size_t cnt) noexcept +std::size_t RingBuffer::read(void *dest, std::size_t cnt) noexcept { - const size_t free_cnt{readSpace()}; + const std::size_t free_cnt{readSpace()}; if(free_cnt == 0) return 0; - const size_t to_read{std::min(cnt, free_cnt)}; - size_t read_ptr{mReadPtr.load(std::memory_order_relaxed) & mSizeMask}; + const std::size_t to_read{std::min(cnt, free_cnt)}; + std::size_t read_ptr{mReadPtr.load(std::memory_order_relaxed) & mSizeMask}; - size_t n1, n2; - const size_t cnt2{read_ptr + to_read}; + std::size_t n1, n2; + const std::size_t cnt2{read_ptr + to_read}; if(cnt2 > mSizeMask+1) { n1 = mSizeMask+1 - read_ptr; @@ -87,7 +86,7 @@ size_t RingBuffer::read(void *dest, size_t cnt) noexcept } auto outiter = std::copy_n(mBuffer.begin() + read_ptr*mElemSize, n1*mElemSize, - static_cast(dest)); + static_cast(dest)); read_ptr += n1; if(n2 > 0) { @@ -98,16 +97,16 @@ size_t RingBuffer::read(void *dest, size_t cnt) noexcept return to_read; } -size_t RingBuffer::peek(void *dest, size_t cnt) const noexcept +std::size_t RingBuffer::peek(void *dest, std::size_t cnt) const noexcept { - const size_t free_cnt{readSpace()}; + const std::size_t free_cnt{readSpace()}; if(free_cnt == 0) return 0; - const size_t to_read{std::min(cnt, free_cnt)}; - size_t read_ptr{mReadPtr.load(std::memory_order_relaxed) & mSizeMask}; + const std::size_t to_read{std::min(cnt, free_cnt)}; + std::size_t read_ptr{mReadPtr.load(std::memory_order_relaxed) & mSizeMask}; - size_t n1, n2; - const size_t cnt2{read_ptr + to_read}; + std::size_t n1, n2; + const std::size_t cnt2{read_ptr + to_read}; if(cnt2 > mSizeMask+1) { n1 = mSizeMask+1 - read_ptr; @@ -120,22 +119,22 @@ size_t RingBuffer::peek(void *dest, size_t cnt) const noexcept } auto outiter = std::copy_n(mBuffer.begin() + read_ptr*mElemSize, n1*mElemSize, - static_cast(dest)); + static_cast(dest)); if(n2 > 0) std::copy_n(mBuffer.begin(), n2*mElemSize, outiter); return to_read; } -size_t RingBuffer::write(const void *src, size_t cnt) noexcept +std::size_t RingBuffer::write(const void *src, std::size_t cnt) noexcept { - const size_t free_cnt{writeSpace()}; + const std::size_t free_cnt{writeSpace()}; if(free_cnt == 0) return 0; - const size_t to_write{std::min(cnt, free_cnt)}; - size_t write_ptr{mWritePtr.load(std::memory_order_relaxed) & mSizeMask}; + const std::size_t to_write{std::min(cnt, free_cnt)}; + std::size_t write_ptr{mWritePtr.load(std::memory_order_relaxed) & mSizeMask}; - size_t n1, n2; - const size_t cnt2{write_ptr + to_write}; + std::size_t n1, n2; + const std::size_t cnt2{write_ptr + to_write}; if(cnt2 > mSizeMask+1) { n1 = mSizeMask+1 - write_ptr; @@ -147,7 +146,7 @@ size_t RingBuffer::write(const void *src, size_t cnt) noexcept n2 = 0; } - auto srcbytes = static_cast(src); + auto srcbytes = static_cast(src); std::copy_n(srcbytes, n1*mElemSize, mBuffer.begin() + write_ptr*mElemSize); write_ptr += n1; if(n2 > 0) @@ -164,26 +163,26 @@ auto RingBuffer::getReadVector() const noexcept -> DataPair { DataPair ret; - size_t w{mWritePtr.load(std::memory_order_acquire)}; - size_t r{mReadPtr.load(std::memory_order_acquire)}; + std::size_t w{mWritePtr.load(std::memory_order_acquire)}; + std::size_t r{mReadPtr.load(std::memory_order_acquire)}; w &= mSizeMask; r &= mSizeMask; - const size_t free_cnt{(w-r) & mSizeMask}; + const std::size_t free_cnt{(w-r) & mSizeMask}; - const size_t cnt2{r + free_cnt}; + const std::size_t cnt2{r + free_cnt}; if(cnt2 > mSizeMask+1) { /* Two part vector: the rest of the buffer after the current read ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast(mBuffer.data() + r*mElemSize); + ret.first.buf = const_cast(mBuffer.data() + r*mElemSize); ret.first.len = mSizeMask+1 - r; - ret.second.buf = const_cast(mBuffer.data()); + ret.second.buf = const_cast(mBuffer.data()); ret.second.len = cnt2 & mSizeMask; } else { /* Single part vector: just the rest of the buffer */ - ret.first.buf = const_cast(mBuffer.data() + r*mElemSize); + ret.first.buf = const_cast(mBuffer.data() + r*mElemSize); ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; @@ -196,25 +195,25 @@ auto RingBuffer::getWriteVector() const noexcept -> DataPair { DataPair ret; - size_t w{mWritePtr.load(std::memory_order_acquire)}; - size_t r{mReadPtr.load(std::memory_order_acquire) + mWriteSize - mSizeMask}; + std::size_t w{mWritePtr.load(std::memory_order_acquire)}; + std::size_t r{mReadPtr.load(std::memory_order_acquire) + mWriteSize - mSizeMask}; w &= mSizeMask; r &= mSizeMask; - const size_t free_cnt{(r-w-1) & mSizeMask}; + const std::size_t free_cnt{(r-w-1) & mSizeMask}; - const size_t cnt2{w + free_cnt}; + const std::size_t cnt2{w + free_cnt}; if(cnt2 > mSizeMask+1) { /* Two part vector: the rest of the buffer after the current write ptr, * plus some from the start of the buffer. */ - ret.first.buf = const_cast(mBuffer.data() + w*mElemSize); + ret.first.buf = const_cast(mBuffer.data() + w*mElemSize); ret.first.len = mSizeMask+1 - w; - ret.second.buf = const_cast(mBuffer.data()); + ret.second.buf = const_cast(mBuffer.data()); ret.second.len = cnt2 & mSizeMask; } else { - ret.first.buf = const_cast(mBuffer.data() + w*mElemSize); + ret.first.buf = const_cast(mBuffer.data() + w*mElemSize); ret.first.len = free_cnt; ret.second.buf = nullptr; ret.second.len = 0; diff --git a/common/ringbuffer.h b/common/ringbuffer.h index 2a3797b0..8c65c3af 100644 --- a/common/ringbuffer.h +++ b/common/ringbuffer.h @@ -2,11 +2,10 @@ #define RINGBUFFER_H #include +#include #include -#include #include -#include "albyte.h" #include "almalloc.h" @@ -18,23 +17,23 @@ struct RingBuffer { private: - std::atomic mWritePtr{0u}; - std::atomic mReadPtr{0u}; - size_t mWriteSize{0u}; - size_t mSizeMask{0u}; - size_t mElemSize{0u}; + std::atomic mWritePtr{0u}; + std::atomic mReadPtr{0u}; + std::size_t mWriteSize{0u}; + std::size_t mSizeMask{0u}; + std::size_t mElemSize{0u}; - al::FlexArray mBuffer; + al::FlexArray mBuffer; public: struct Data { - al::byte *buf; - size_t len; + std::byte *buf; + std::size_t len; }; using DataPair = std::pair; - RingBuffer(const size_t count) : mBuffer{count} { } + RingBuffer(const std::size_t count) : mBuffer{count} { } /** Reset the read and write pointers to zero. This is not thread safe. */ void reset() noexcept; @@ -56,7 +55,7 @@ public: * Return the number of elements available for reading. This is the number * of elements in front of the read pointer and behind the write pointer. */ - size_t readSpace() const noexcept + std::size_t readSpace() const noexcept { const size_t w{mWritePtr.load(std::memory_order_acquire)}; const size_t r{mReadPtr.load(std::memory_order_acquire)}; @@ -67,14 +66,14 @@ public: * The copying data reader. Copy at most `cnt' elements into `dest'. * Returns the actual number of elements copied. */ - size_t read(void *dest, size_t cnt) noexcept; + std::size_t read(void *dest, std::size_t cnt) noexcept; /** * The copying data reader w/o read pointer advance. Copy at most `cnt' * elements into `dest'. Returns the actual number of elements copied. */ - size_t peek(void *dest, size_t cnt) const noexcept; + std::size_t peek(void *dest, std::size_t cnt) const noexcept; /** Advance the read pointer `cnt' places. */ - void readAdvance(size_t cnt) noexcept + void readAdvance(std::size_t cnt) noexcept { mReadPtr.fetch_add(cnt, std::memory_order_acq_rel); } @@ -82,7 +81,7 @@ public: * Return the number of elements available for writing. This is the number * of elements in front of the write pointer and behind the read pointer. */ - size_t writeSpace() const noexcept + std::size_t writeSpace() const noexcept { const size_t w{mWritePtr.load(std::memory_order_acquire)}; const size_t r{mReadPtr.load(std::memory_order_acquire) + mWriteSize - mSizeMask}; @@ -93,12 +92,12 @@ public: * The copying data writer. Copy at most `cnt' elements from `src'. Returns * the actual number of elements copied. */ - size_t write(const void *src, size_t cnt) noexcept; + std::size_t write(const void *src, std::size_t cnt) noexcept; /** Advance the write pointer `cnt' places. */ - void writeAdvance(size_t cnt) noexcept + void writeAdvance(std::size_t cnt) noexcept { mWritePtr.fetch_add(cnt, std::memory_order_acq_rel); } - size_t getElemSize() const noexcept { return mElemSize; } + std::size_t getElemSize() const noexcept { return mElemSize; } /** * Create a new ringbuffer to hold at least `sz' elements of `elem_sz' @@ -106,7 +105,7 @@ public: * (even if it is already a power of two, to ensure the requested amount * can be written). */ - static std::unique_ptr Create(size_t sz, size_t elem_sz, int limit_writes); + static std::unique_ptr Create(std::size_t sz, std::size_t elem_sz, int limit_writes); DEF_FAM_NEWDEL(RingBuffer, mBuffer) }; diff --git a/core/buffer_storage.h b/core/buffer_storage.h index 282d5b53..d8ab0b67 100644 --- a/core/buffer_storage.h +++ b/core/buffer_storage.h @@ -2,8 +2,8 @@ #define CORE_BUFFER_STORAGE_H #include +#include -#include "albyte.h" #include "alnumeric.h" #include "alspan.h" #include "ambidefs.h" @@ -85,7 +85,7 @@ struct BufferStorage { CallbackType mCallback{nullptr}; void *mUserData{nullptr}; - al::span mData; + al::span mData; uint mSampleRate{0u}; FmtChannels mChannels{FmtMono}; diff --git a/core/converter.cpp b/core/converter.cpp index a5141448..b3994d3f 100644 --- a/core/converter.cpp +++ b/core/converter.cpp @@ -6,12 +6,12 @@ #include #include #include +#include #include #include #include #include "albit.h" -#include "albyte.h" #include "alnumeric.h" #include "fpu_ctrl.h" @@ -219,7 +219,7 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint const uint SrcFrameSize{static_cast(mChan.size()) * mSrcTypeSize}; const uint DstFrameSize{static_cast(mChan.size()) * mDstTypeSize}; const uint increment{mIncrement}; - auto SamplesIn = static_cast(*src); + auto SamplesIn = static_cast(*src); uint NumSrcSamples{*srcframes}; FPUCtl mixer_mode{}; @@ -265,8 +265,8 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint for(size_t chan{0u};chan < mChan.size();chan++) { - const al::byte *SrcSamples{SamplesIn + mSrcTypeSize*chan}; - al::byte *DstSamples = static_cast(dst) + mDstTypeSize*chan; + const std::byte *SrcSamples{SamplesIn + mSrcTypeSize*chan}; + std::byte *DstSamples = static_cast(dst) + mDstTypeSize*chan; /* Load the previous samples into the source data first, then the * new samples from the input buffer. @@ -299,7 +299,7 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint SamplesIn += SrcFrameSize*srcread; NumSrcSamples -= srcread; - dst = static_cast(dst) + DstFrameSize*DstSize; + dst = static_cast(dst) + DstFrameSize*DstSize; pos += DstSize; } diff --git a/core/effects/base.h b/core/effects/base.h index 4ee19f37..b02d33b7 100644 --- a/core/effects/base.h +++ b/core/effects/base.h @@ -3,7 +3,6 @@ #include -#include "albyte.h" #include "almalloc.h" #include "alspan.h" #include "atomic.h" diff --git a/core/fmt_traits.h b/core/fmt_traits.h index f797f836..1879c81b 100644 --- a/core/fmt_traits.h +++ b/core/fmt_traits.h @@ -1,10 +1,9 @@ #ifndef CORE_FMT_TRAITS_H #define CORE_FMT_TRAITS_H -#include +#include #include -#include "albyte.h" #include "buffer_storage.h" @@ -22,36 +21,35 @@ struct FmtTypeTraits { using Type = uint8_t; template - static constexpr inline OutT to(const Type val) noexcept - { return val*OutT{1.0/128.0} - OutT{1.0}; } + static constexpr OutT to(const Type val) noexcept { return val*OutT{1.0/128.0} - OutT{1.0}; } }; template<> struct FmtTypeTraits { using Type = int16_t; template - static constexpr inline OutT to(const Type val) noexcept { return val*OutT{1.0/32768.0}; } + static constexpr OutT to(const Type val) noexcept { return val*OutT{1.0/32768.0}; } }; template<> struct FmtTypeTraits { using Type = float; template - static constexpr inline OutT to(const Type val) noexcept { return val; } + static constexpr OutT to(const Type val) noexcept { return val; } }; template<> struct FmtTypeTraits { using Type = double; template - static constexpr inline OutT to(const Type val) noexcept { return static_cast(val); } + static constexpr OutT to(const Type val) noexcept { return static_cast(val); } }; template<> struct FmtTypeTraits { using Type = uint8_t; template - static constexpr inline OutT to(const Type val) noexcept + static constexpr OutT to(const Type val) noexcept { return muLawDecompressionTable[val] * OutT{1.0/32768.0}; } }; template<> @@ -59,14 +57,14 @@ struct FmtTypeTraits { using Type = uint8_t; template - static constexpr inline OutT to(const Type val) noexcept + static constexpr OutT to(const Type val) noexcept { return aLawDecompressionTable[val] * OutT{1.0/32768.0}; } }; template -inline void LoadSampleArray(DstT *RESTRICT dst, const al::byte *src, const size_t srcstep, - const size_t samples) noexcept +inline void LoadSampleArray(DstT *RESTRICT dst, const std::byte *src, const std::size_t srcstep, + const std::size_t samples) noexcept { using TypeTraits = FmtTypeTraits; using SampleType = typename TypeTraits::Type; diff --git a/core/hrtf.cpp b/core/hrtf.cpp index c54d96d1..1d9bc368 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include #include "albit.h" -#include "albyte.h" #include "alfstream.h" #include "almalloc.h" #include "alnumbers.h" @@ -492,10 +492,10 @@ T> readle(std::istream &data) static_assert(num_bits <= sizeof(T)*8, "num_bits is too large for the type"); T ret{}; - al::byte b[sizeof(T)]{}; + std::byte b[sizeof(T)]{}; if(!data.read(reinterpret_cast(b), num_bits/8)) return static_cast(EOF); - std::reverse_copy(std::begin(b), std::end(b), reinterpret_cast(&ret)); + std::reverse_copy(std::begin(b), std::end(b), reinterpret_cast(&ret)); return fixsign(ret); } diff --git a/core/voice.cpp b/core/voice.cpp index 090b10a3..cbf84c2a 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -17,7 +17,6 @@ #include #include -#include "albyte.h" #include "alnumeric.h" #include "alspan.h" #include "alstring.h" @@ -264,7 +263,7 @@ const float *DoFilters(BiquadFilter &lpfilter, BiquadFilter &hpfilter, float *ds template -inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src, const size_t srcChan, +inline void LoadSamples(float *RESTRICT dstSamples, const std::byte *src, const size_t srcChan, const size_t srcOffset, const size_t srcStep, const size_t /*samplesPerBlock*/, const size_t samplesToLoad) noexcept { @@ -275,7 +274,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src, const s } template<> -inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src, +inline void LoadSamples(float *RESTRICT dstSamples, const std::byte *src, const size_t srcChan, const size_t srcOffset, const size_t srcStep, const size_t samplesPerBlock, const size_t samplesToLoad) noexcept { @@ -293,8 +292,8 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src /* Each IMA4 block starts with a signed 16-bit sample, and a signed * 16-bit table index. The table index needs to be clamped. */ - int sample{src[srcChan*4] | (src[srcChan*4 + 1] << 8)}; - int index{src[srcChan*4 + 2] | (src[srcChan*4 + 3] << 8)}; + int sample{int(src[srcChan*4]) | (int(src[srcChan*4 + 1]) << 8)}; + int index{int(src[srcChan*4 + 2]) | (int(src[srcChan*4 + 3]) << 8)}; sample = (sample^0x8000) - 32768; index = clampi((index^0x8000) - 32768, 0, MaxStepIndex); @@ -326,7 +325,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src * always be less than the block size). They need to be decoded despite * being ignored for proper state on the remaining samples. */ - const al::byte *nibbleData{src + (srcStep+srcChan)*4}; + const std::byte *nibbleData{src + (srcStep+srcChan)*4}; size_t nibbleOffset{0}; const size_t startOffset{skip + 1}; for(;skip;--skip) @@ -336,7 +335,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src const size_t byteOffset{wordOffset*srcStep + ((nibbleOffset>>1)&3u)}; ++nibbleOffset; - std::ignore = decode_sample((nibbleData[byteOffset]>>byteShift) & 15u); + std::ignore = decode_sample(uint(nibbleData[byteOffset]>>byteShift) & 15u); } /* Second, decode the rest of the block and write to the output, until @@ -350,7 +349,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src const size_t byteOffset{wordOffset*srcStep + ((nibbleOffset>>1)&3u)}; ++nibbleOffset; - const int result{decode_sample((nibbleData[byteOffset]>>byteShift) & 15u)}; + const int result{decode_sample(uint(nibbleData[byteOffset]>>byteShift) & 15u)}; dstSamples[wrote++] = static_cast(result) / 32768.0f; } if(wrote == samplesToLoad) @@ -361,7 +360,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src } template<> -inline void LoadSamples(float *RESTRICT dstSamples, const al::byte *src, +inline void LoadSamples(float *RESTRICT dstSamples, const std::byte *src, const size_t srcChan, const size_t srcOffset, const size_t srcStep, const size_t samplesPerBlock, const size_t samplesToLoad) noexcept { @@ -378,16 +377,16 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte * * nibble sample value. This is followed by the two initial 16-bit * sample history values. */ - const al::byte *input{src}; - const uint8_t blockpred{std::min(input[srcChan], uint8_t{6})}; + const std::byte *input{src}; + const uint8_t blockpred{std::min(uint8_t(input[srcChan]), uint8_t{6})}; input += srcStep; - int delta{input[2*srcChan + 0] | (input[2*srcChan + 1] << 8)}; + int delta{int(input[2*srcChan + 0]) | (int(input[2*srcChan + 1]) << 8)}; input += srcStep*2; int sampleHistory[2]{}; - sampleHistory[0] = input[2*srcChan + 0] | (input[2*srcChan + 1]<<8); + sampleHistory[0] = int(input[2*srcChan + 0]) | (int(input[2*srcChan + 1])<<8); input += srcStep*2; - sampleHistory[1] = input[2*srcChan + 0] | (input[2*srcChan + 1]<<8); + sampleHistory[1] = int(input[2*srcChan + 0]) | (int(input[2*srcChan + 1])<<8); input += srcStep*2; const auto coeffs = al::as_span(MSADPCMAdaptionCoeff[blockpred]); @@ -440,7 +439,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte * const size_t byteShift{((nibbleOffset&1)^1) * 4}; nibbleOffset += srcStep; - std::ignore = decode_sample((input[byteOffset]>>byteShift) & 15); + std::ignore = decode_sample(int(input[byteOffset]>>byteShift) & 15); } /* Now decode the rest of the block, until the end of the block or the @@ -453,7 +452,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte * const size_t byteShift{((nibbleOffset&1)^1) * 4}; nibbleOffset += srcStep; - const int sample{decode_sample((input[byteOffset]>>byteShift) & 15)}; + const int sample{decode_sample(int(input[byteOffset]>>byteShift) & 15)}; dstSamples[wrote++] = static_cast(sample) / 32768.0f; } if(wrote == samplesToLoad) @@ -463,7 +462,7 @@ inline void LoadSamples(float *RESTRICT dstSamples, const al::byte * } while(true); } -void LoadSamples(float *dstSamples, const al::byte *src, const size_t srcChan, +void LoadSamples(float *dstSamples, const std::byte *src, const size_t srcChan, const size_t srcOffset, const FmtType srcType, const size_t srcStep, const size_t samplesPerBlock, const size_t samplesToLoad) noexcept { @@ -1102,7 +1101,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi { const size_t byteOffset{blocksDone*mBytesPerBlock}; const size_t byteEnd{mNumCallbackBlocks*mBytesPerBlock}; - al::byte *data{BufferListItem->mSamples}; + std::byte *data{BufferListItem->mSamples}; std::copy(data+byteOffset, data+byteEnd, data); mNumCallbackBlocks -= blocksDone; mCallbackBlockBase += blocksDone; diff --git a/core/voice.h b/core/voice.h index 9d74ff6b..a599eda8 100644 --- a/core/voice.h +++ b/core/voice.h @@ -5,12 +5,11 @@ #include #include #include +#include #include #include -#include #include -#include "albyte.h" #include "almalloc.h" #include "alspan.h" #include "bufferline.h" @@ -100,7 +99,7 @@ struct VoiceBufferItem { uint mLoopStart{0u}; uint mLoopEnd{0u}; - al::byte *mSamples{nullptr}; + std::byte *mSamples{nullptr}; }; diff --git a/utils/uhjdecoder.cpp b/utils/uhjdecoder.cpp index 6d992e30..c7efa376 100644 --- a/utils/uhjdecoder.cpp +++ b/utils/uhjdecoder.cpp @@ -26,15 +26,14 @@ #include #include +#include #include #include -#include #include #include #include #include "albit.h" -#include "albyte.h" #include "alcomplex.h" #include "almalloc.h" #include "alnumbers.h" @@ -64,7 +63,7 @@ using ushort = unsigned short; using uint = unsigned int; using complex_d = std::complex; -using byte4 = std::array; +using byte4 = std::array; constexpr ubyte SUBTYPE_BFORMAT_FLOAT[]{ @@ -113,7 +112,7 @@ using FloatBufferSpan = al::span; struct UhjDecoder { - constexpr static size_t sFilterDelay{1024}; + constexpr static std::size_t sFilterDelay{1024}; alignas(16) std::array mS{}; alignas(16) std::array mD{}; @@ -126,10 +125,10 @@ struct UhjDecoder { alignas(16) std::array mTemp{}; - void decode(const float *RESTRICT InSamples, const size_t InChannels, - const al::span OutSamples, const size_t SamplesToDo); + void decode(const float *RESTRICT InSamples, const std::size_t InChannels, + const al::span OutSamples, const std::size_t SamplesToDo); void decode2(const float *RESTRICT InSamples, const al::span OutSamples, - const size_t SamplesToDo); + const std::size_t SamplesToDo); DEF_NEWDEL(UhjDecoder) }; @@ -210,8 +209,8 @@ const PhaseShifterT PShift{}; * * Not halving produces a result matching the original input. */ -void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels, - const al::span OutSamples, const size_t SamplesToDo) +void UhjDecoder::decode(const float *RESTRICT InSamples, const std::size_t InChannels, + const al::span OutSamples, const std::size_t SamplesToDo) { ASSUME(SamplesToDo > 0); @@ -224,23 +223,23 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels */ /* S = Left + Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mS[sFilterDelay+i] = InSamples[i*InChannels + 0] + InSamples[i*InChannels + 1]; /* D = Left - Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mD[sFilterDelay+i] = InSamples[i*InChannels + 0] - InSamples[i*InChannels + 1]; if(InChannels > 2) { /* T */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mT[sFilterDelay+i] = InSamples[i*InChannels + 2]; } if(InChannels > 3) { /* Q */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mQ[sFilterDelay+i] = InSamples[i*InChannels + 3]; } @@ -251,7 +250,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels std::copy_n(mTemp.cbegin()+SamplesToDo, mDTHistory.size(), mDTHistory.begin()); PShift.process({xoutput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* W = 0.981532*S + 0.197484*j(0.828331*D + 0.767820*T) */ woutput[i] = 0.981532f*mS[i] + 0.197484f*xoutput[i]; @@ -265,7 +264,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels std::copy_n(mTemp.cbegin()+SamplesToDo, mSHistory.size(), mSHistory.begin()); PShift.process({youtput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* Y = 0.795968*D - 0.676392*T + j(0.186633*S) */ youtput[i] = 0.795968f*mD[i] - 0.676392f*mT[i] + 0.186633f*youtput[i]; @@ -275,7 +274,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels { float *zoutput{OutSamples[3].data()}; /* Z = 1.023332*Q */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) zoutput[i] = 1.023332f*mQ[i]; } @@ -305,7 +304,7 @@ void UhjDecoder::decode(const float *RESTRICT InSamples, const size_t InChannels * halving here is merely a -6dB reduction in output, but it's still incorrect. */ void UhjDecoder::decode2(const float *RESTRICT InSamples, - const al::span OutSamples, const size_t SamplesToDo) + const al::span OutSamples, const std::size_t SamplesToDo) { ASSUME(SamplesToDo > 0); @@ -314,11 +313,11 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, float *youtput{OutSamples[2].data()}; /* S = Left + Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mS[sFilterDelay+i] = InSamples[i*2 + 0] + InSamples[i*2 + 1]; /* D = Left - Right */ - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) mD[sFilterDelay+i] = InSamples[i*2 + 0] - InSamples[i*2 + 1]; /* Precompute j*D and store in xoutput. */ @@ -327,7 +326,7 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, std::copy_n(mTemp.cbegin()+SamplesToDo, mDTHistory.size(), mDTHistory.begin()); PShift.process({xoutput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* W = 0.981530*S + j*0.163585*D */ woutput[i] = 0.981530f*mS[i] + 0.163585f*xoutput[i]; @@ -341,7 +340,7 @@ void UhjDecoder::decode2(const float *RESTRICT InSamples, std::copy_n(mTemp.cbegin()+SamplesToDo, mSHistory.size(), mSHistory.begin()); PShift.process({youtput, SamplesToDo}, mTemp.data()); - for(size_t i{0};i < SamplesToDo;++i) + for(std::size_t i{0};i < SamplesToDo;++i) { /* Y = 0.762956*D + j*0.384230*S */ youtput[i] = 0.762956f*mD[i] + 0.384230f*youtput[i]; @@ -368,7 +367,7 @@ int main(int argc, char **argv) return 1; } - size_t num_files{0}, num_decoded{0}; + std::size_t num_files{0}, num_decoded{0}; bool use_general{true}; for(int fidx{1};fidx < argc;++fidx) { @@ -473,7 +472,7 @@ int main(int argc, char **argv) * be fed through the decoder after reaching the end of the input file * to ensure none of the original input is lost. */ - size_t LeadIn{UhjDecoder::sFilterDelay}; + std::size_t LeadIn{UhjDecoder::sFilterDelay}; sf_count_t LeadOut{UhjDecoder::sFilterDelay}; while(LeadOut > 0) { @@ -487,7 +486,7 @@ int main(int argc, char **argv) LeadOut -= remaining; } - auto got = static_cast(sgot); + auto got = static_cast(sgot); if(ininfo.channels > 2 || use_general) decoder->decode(inmem.get(), static_cast(ininfo.channels), decmem, got); else @@ -499,16 +498,16 @@ int main(int argc, char **argv) } got -= LeadIn; - for(size_t i{0};i < got;++i) + for(std::size_t i{0};i < got;++i) { /* Attenuate by -3dB for FuMa output levels. */ constexpr auto inv_sqrt2 = static_cast(1.0/al::numbers::sqrt2); - for(size_t j{0};j < outchans;++j) + for(std::size_t j{0};j < outchans;++j) outmem[i*outchans + j] = f32AsLEBytes(decmem[j][LeadIn+i] * inv_sqrt2); } LeadIn = 0; - size_t wrote{fwrite(outmem.get(), sizeof(byte4)*outchans, got, outfile.get())}; + std::size_t wrote{fwrite(outmem.get(), sizeof(byte4)*outchans, got, outfile.get())}; if(wrote < got) { fprintf(stderr, "Error writing wave data: %s (%d)\n", strerror(errno), errno); -- cgit v1.2.3 From 72f02418e505a192c0cc7b27cd7b3aa28a7a03ec Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 12 May 2023 16:01:06 -0700 Subject: Clean up some more includes --- alc/backends/alsa.cpp | 1 + alc/backends/coreaudio.cpp | 8 ++++---- alc/backends/dsound.cpp | 14 +++++++------- alc/backends/jack.cpp | 4 ++-- alc/backends/oboe.cpp | 1 + alc/backends/opensl.cpp | 3 ++- alc/backends/oss.cpp | 2 -- alc/backends/winmm.cpp | 4 ++-- core/context.cpp | 3 +++ core/context.h | 13 +++++-------- core/device.h | 4 +--- 11 files changed, 28 insertions(+), 29 deletions(-) (limited to 'alc/backends/oss.cpp') diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 74713590..c1690867 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 19a1f753..c2a79815 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -22,17 +22,17 @@ #include "coreaudio.h" +#include #include +#include +#include #include #include #include +#include #include #include -#include -#include -#include - #include "alnumeric.h" #include "core/converter.h" #include "core/device.h" diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 05117781..ffcd8430 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -25,10 +25,6 @@ #define WIN32_LEAN_AND_MEAN #include -#include -#include -#include - #include #include #ifndef _WAVEFORMATEXTENSIBLE_ @@ -36,13 +32,17 @@ #include #endif +#include #include #include -#include +#include +#include +#include +#include +#include #include +#include #include -#include -#include #include "albit.h" #include "alnumeric.h" diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 7e1e8fc7..b12edf9f 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -22,12 +22,12 @@ #include "jack.h" +#include #include #include #include #include - -#include +#include #include #include diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp index 4c47190e..c74b0180 100644 --- a/alc/backends/oboe.cpp +++ b/alc/backends/oboe.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include "alnumeric.h" diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 0c2936b2..c9053816 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -26,9 +26,10 @@ #include #include -#include #include #include +#include +#include #include #include diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 9e247be1..1fdee701 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -31,12 +31,10 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 135b59df..edb875a0 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -55,8 +55,8 @@ namespace { #define DEVNAME_HEAD "OpenAL Soft on " -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; bool checkName(const al::vector &list, const std::string &name) { return std::find(list.cbegin(), list.cend(), name) != list.cend(); } diff --git a/core/context.cpp b/core/context.cpp index d94daf16..145ce349 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -2,7 +2,10 @@ #include "config.h" #include +#include #include +#include +#include #include "async_event.h" #include "context.h" diff --git a/core/context.h b/core/context.h index 4febd38d..629e67a5 100644 --- a/core/context.h +++ b/core/context.h @@ -7,16 +7,15 @@ #include #include #include +#include #include "almalloc.h" #include "alspan.h" #include "async_event.h" #include "atomic.h" -#include "bufferline.h" #include "opthelpers.h" #include "threads.h" #include "vecmat.h" -#include "vector.h" struct DeviceBase; struct EffectSlot; @@ -26,8 +25,6 @@ struct Voice; struct VoiceChange; struct VoicePropsItem; -using uint = unsigned int; - constexpr float SpeedOfSoundMetersPerSec{343.3f}; @@ -147,20 +144,20 @@ struct ContextBase { * in clusters that are stored in a vector for easy automatic cleanup. */ using VoiceChangeCluster = std::unique_ptr; - al::vector mVoiceChangeClusters; + std::vector mVoiceChangeClusters; using VoiceCluster = std::unique_ptr; - al::vector mVoiceClusters; + std::vector mVoiceClusters; using VoicePropsCluster = std::unique_ptr; - al::vector mVoicePropClusters; + std::vector mVoicePropClusters; static constexpr size_t EffectSlotClusterSize{4}; EffectSlot *getEffectSlot(); using EffectSlotCluster = std::unique_ptr; - al::vector mEffectSlotClusters; + std::vector mEffectSlotClusters; ContextBase(DeviceBase *device); diff --git a/core/device.h b/core/device.h index bc180582..33cdfe89 100644 --- a/core/device.h +++ b/core/device.h @@ -1,14 +1,12 @@ #ifndef CORE_DEVICE_H #define CORE_DEVICE_H -#include - #include #include #include #include #include -#include +#include #include #include -- cgit v1.2.3 From e7ea579ca5f3c0da6cfe80ec9a7295bca60198aa Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 12 May 2023 18:02:12 -0700 Subject: Avoid using al::vector unnecessarily --- al/auxeffectslot.cpp | 8 +++---- al/buffer.cpp | 5 +++-- al/effect.cpp | 4 ++-- al/error.cpp | 4 ++-- al/filter.cpp | 4 ++-- al/source.cpp | 13 ++++++------ alc/alc.cpp | 12 +++++------ alc/backends/alsa.cpp | 16 +++++++------- alc/backends/coreaudio.cpp | 4 ++-- alc/backends/dsound.cpp | 9 ++++---- alc/backends/jack.cpp | 5 +++-- alc/backends/oss.cpp | 14 ++++++------ alc/backends/pulseaudio.cpp | 6 +++--- alc/backends/solaris.cpp | 4 ++-- alc/backends/wasapi.cpp | 18 ++++++++-------- alc/backends/wave.cpp | 4 ++-- alc/backends/winmm.cpp | 2 +- alc/context.h | 6 +++--- alc/device.h | 10 ++++----- alc/effects/chorus.cpp | 4 ++-- alc/effects/echo.cpp | 6 +++--- alc/panning.cpp | 3 ++- core/bformatdec.h | 4 ++-- core/hrtf.cpp | 52 ++++++++++++++++++++++----------------------- core/hrtf.h | 4 ++-- core/logging.cpp | 4 ++-- 26 files changed, 115 insertions(+), 110 deletions(-) (limited to 'alc/backends/oss.cpp') diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index c69990fe..3a3222b8 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -341,7 +341,7 @@ START_API_FUNC } else { - al::vector ids; + std::vector ids; ALsizei count{n}; ids.reserve(static_cast(count)); do { @@ -383,7 +383,7 @@ START_API_FUNC } else { - auto slots = al::vector(static_cast(n)); + auto slots = std::vector(static_cast(n)); for(size_t i{0};i < slots.size();++i) { ALeffectslot *slot{LookupEffectSlot(context.get(), effectslots[i])}; @@ -466,7 +466,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Playing %d effect slots", n); if(n <= 0) UNLIKELY return; - auto slots = al::vector(static_cast(n)); + auto slots = std::vector(static_cast(n)); std::lock_guard _{context->mEffectSlotLock}; for(size_t i{0};i < slots.size();++i) { @@ -520,7 +520,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Stopping %d effect slots", n); if(n <= 0) UNLIKELY return; - auto slots = al::vector(static_cast(n)); + auto slots = std::vector(static_cast(n)); std::lock_guard _{context->mEffectSlotLock}; for(size_t i{0};i < slots.size();++i) { diff --git a/al/buffer.cpp b/al/buffer.cpp index 1f008c8e..bfc10906 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -345,7 +346,7 @@ void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, */ if(newsize != ALBuf->mDataStorage.size()) { - auto newdata = al::vector(newsize, std::byte{}); + auto newdata = decltype(ALBuf->mDataStorage)(newsize, std::byte{}); if((access&AL_PRESERVE_DATA_BIT_SOFT)) { const size_t tocopy{minz(newdata.size(), ALBuf->mDataStorage.size())}; @@ -663,7 +664,7 @@ START_API_FUNC /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. */ - al::vector ids; + std::vector ids; ids.reserve(static_cast(n)); do { ALbuffer *buffer{AllocBuffer(device)}; diff --git a/al/effect.cpp b/al/effect.cpp index 3d91139a..3ca7c37e 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -49,7 +50,6 @@ #include "core/except.h" #include "core/logging.h" #include "opthelpers.h" -#include "vector.h" #ifdef ALSOFT_EAX #include @@ -259,7 +259,7 @@ START_API_FUNC /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. */ - al::vector ids; + std::vector ids; ids.reserve(static_cast(n)); do { ALeffect *effect{AllocEffect(device)}; diff --git a/al/error.cpp b/al/error.cpp index 39fd9f0a..b0607d66 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -41,14 +42,13 @@ #include "core/except.h" #include "core/logging.h" #include "opthelpers.h" -#include "vector.h" bool TrapALError{false}; void ALCcontext::setError(ALenum errorCode, const char *msg, ...) { - auto message = al::vector(256); + auto message = std::vector(256); va_list args, args2; va_start(args, msg); diff --git a/al/filter.cpp b/al/filter.cpp index 0fd8eaa8..11d71179 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -43,7 +44,6 @@ #include "alnumeric.h" #include "core/except.h" #include "opthelpers.h" -#include "vector.h" namespace { @@ -430,7 +430,7 @@ START_API_FUNC /* Store the allocated buffer IDs in a separate local list, to avoid * modifying the user storage in case of failure. */ - al::vector ids; + std::vector ids; ids.reserve(static_cast(n)); do { ALfilter *filter{AllocFilter(device)}; diff --git a/al/source.cpp b/al/source.cpp index efe65332..1bfd5a94 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -2659,7 +2660,7 @@ START_API_FUNC } else { - al::vector ids; + std::vector ids; ids.reserve(static_cast(n)); do { ALsource *source{AllocSource(context.get())}; @@ -3223,7 +3224,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Playing %d sources", n); if(n <= 0) UNLIKELY return; - al::vector extra_sources; + std::vector extra_sources; std::array source_storage; al::span srchandles; if(static_cast(n) <= source_storage.size()) LIKELY @@ -3261,7 +3262,7 @@ START_API_FUNC if(start_time < 0) UNLIKELY return context->setError(AL_INVALID_VALUE, "Invalid time point %" PRId64, start_time); - al::vector extra_sources; + std::vector extra_sources; std::array source_storage; al::span srchandles; if(static_cast(n) <= source_storage.size()) LIKELY @@ -3301,7 +3302,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Pausing %d sources", n); if(n <= 0) UNLIKELY return; - al::vector extra_sources; + std::vector extra_sources; std::array source_storage; al::span srchandles; if(static_cast(n) <= source_storage.size()) LIKELY @@ -3377,7 +3378,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Stopping %d sources", n); if(n <= 0) UNLIKELY return; - al::vector extra_sources; + std::vector extra_sources; std::array source_storage; al::span srchandles; if(static_cast(n) <= source_storage.size()) LIKELY @@ -3440,7 +3441,7 @@ START_API_FUNC context->setError(AL_INVALID_VALUE, "Rewinding %d sources", n); if(n <= 0) UNLIKELY return; - al::vector extra_sources; + std::vector extra_sources; std::array source_storage; al::span srchandles; if(static_cast(n) <= source_storage.size()) LIKELY diff --git a/alc/alc.cpp b/alc/alc.cpp index 290cc3d1..9fedee0b 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -102,7 +103,6 @@ #include "opthelpers.h" #include "strutils.h" #include "threads.h" -#include "vector.h" #include "backends/base.h" #include "backends/null.h" @@ -1050,8 +1050,8 @@ using DeviceRef = al::intrusive_ptr; /************************************************ * Device lists ************************************************/ -al::vector DeviceList; -al::vector ContextList; +std::vector DeviceList; +std::vector ContextList; std::recursive_mutex ListLock; @@ -3130,7 +3130,7 @@ START_API_FUNC } if(!dev || dev->Type == DeviceType::Capture) { - auto ivals = al::vector(static_cast(size)); + auto ivals = std::vector(static_cast(size)); if(size_t got{GetIntegerv(dev.get(), pname, ivals)}) std::copy_n(ivals.begin(), got, values); return; @@ -3249,7 +3249,7 @@ START_API_FUNC break; default: - auto ivals = al::vector(static_cast(size)); + auto ivals = std::vector(static_cast(size)); if(size_t got{GetIntegerv(dev.get(), pname, ivals)}) std::copy_n(ivals.begin(), got, values); break; @@ -3676,7 +3676,7 @@ START_API_FUNC DeviceList.erase(iter); std::unique_lock statelock{dev->StateLock}; - al::vector orphanctxs; + std::vector orphanctxs; for(ContextBase *ctx : *dev->mContexts.load()) { auto ctxiter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index c1690867..ce368f5e 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "albit.h" #include "alc/alconfig.h" @@ -46,7 +47,6 @@ #include "dynload.h" #include "ringbuffer.h" #include "threads.h" -#include "vector.h" #include @@ -248,8 +248,8 @@ struct DevMap { { } }; -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; const char *prefix_name(snd_pcm_stream_t stream) @@ -258,9 +258,9 @@ const char *prefix_name(snd_pcm_stream_t stream) return (stream==SND_PCM_STREAM_PLAYBACK) ? "device-prefix" : "capture-prefix"; } -al::vector probe_devices(snd_pcm_stream_t stream) +std::vector probe_devices(snd_pcm_stream_t stream) { - al::vector devlist; + std::vector devlist; snd_ctl_card_info_t *info; snd_ctl_card_info_malloc(&info); @@ -439,7 +439,7 @@ struct AlsaPlayback final : public BackendBase { std::mutex mMutex; uint mFrameStep{}; - al::vector mBuffer; + std::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; @@ -880,7 +880,7 @@ struct AlsaCapture final : public BackendBase { snd_pcm_t *mPcmHandle{nullptr}; - al::vector mBuffer; + std::vector mBuffer; bool mDoCapture{false}; RingBufferPtr mRing{nullptr}; @@ -1024,7 +1024,7 @@ void AlsaCapture::stop() /* The ring buffer implicitly captures when checking availability. * Direct access needs to explicitly capture it into temp storage. */ - auto temp = al::vector( + auto temp = std::vector( static_cast(snd_pcm_frames_to_bytes(mPcmHandle, avail))); captureSamples(temp.data(), avail); mBuffer = std::move(temp); diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index c2a79815..521f085d 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -25,13 +25,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include "alnumeric.h" #include "core/converter.h" @@ -578,7 +578,7 @@ struct CoreAudioCapture final : public BackendBase { SampleConverterPtr mConverter; - al::vector mCaptureData; + std::vector mCaptureData; RingBufferPtr mRing{nullptr}; diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index ffcd8430..5fc8a1c7 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -46,6 +46,7 @@ #include "albit.h" #include "alnumeric.h" +#include "alspan.h" #include "comptr.h" #include "core/device.h" #include "core/helpers.h" @@ -130,10 +131,10 @@ struct DevMap { { } }; -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; -bool checkName(const al::vector &list, const std::string &name) +bool checkName(const al::span list, const std::string &name) { auto match_name = [&name](const DevMap &entry) -> bool { return entry.name == name; }; @@ -145,7 +146,7 @@ BOOL CALLBACK DSoundEnumDevices(GUID *guid, const WCHAR *desc, const WCHAR*, voi if(!guid) return TRUE; - auto& devices = *static_cast*>(data); + auto& devices = *static_cast*>(data); const std::string basename{DEVNAME_HEAD + wstr_to_utf8(desc)}; int count{1}; diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index b12edf9f..9e023e21 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "albit.h" #include "alc/alconfig.h" @@ -168,10 +169,10 @@ struct DeviceEntry { { } }; -al::vector PlaybackList; +std::vector PlaybackList; -void EnumerateDevices(jack_client_t *client, al::vector &list) +void EnumerateDevices(jack_client_t *client, std::vector &list) { std::remove_reference_t{}.swap(list); diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 1fdee701..dc18c4c3 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "alc/alconfig.h" #include "almalloc.h" @@ -47,7 +48,6 @@ #include "core/logging.h" #include "ringbuffer.h" #include "threads.h" -#include "vector.h" #include @@ -88,22 +88,22 @@ struct DevMap { std::string device_name; }; -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; #ifdef ALC_OSS_COMPAT #define DSP_CAP_OUTPUT 0x00020000 #define DSP_CAP_INPUT 0x00010000 -void ALCossListPopulate(al::vector &devlist, int type) +void ALCossListPopulate(std::vector &devlist, int type) { devlist.emplace_back(DevMap{DefaultName, (type==DSP_CAP_INPUT) ? DefaultCapture : DefaultPlayback}); } #else -void ALCossListAppend(al::vector &list, al::span handle, al::span path) +void ALCossListAppend(std::vector &list, al::span handle, al::span path) { #ifdef ALC_OSS_DEVNODE_TRUC for(size_t i{0};i < path.size();++i) @@ -148,7 +148,7 @@ void ALCossListAppend(al::vector &list, al::span handle, al: TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); } -void ALCossListPopulate(al::vector &devlist, int type_flag) +void ALCossListPopulate(std::vector &devlist, int type_flag) { int fd{open("/dev/mixer", O_RDONLY)}; if(fd < 0) @@ -234,7 +234,7 @@ struct OSSPlayback final : public BackendBase { int mFd{-1}; - al::vector mMixData; + std::vector mMixData; std::atomic mKillNow{true}; std::thread mThread; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index e5696817..d2883f5c 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "albit.h" #include "alc/alconfig.h" @@ -49,7 +50,6 @@ #include "dynload.h" #include "opthelpers.h" #include "strutils.h" -#include "vector.h" #include @@ -282,8 +282,8 @@ bool checkName(const al::span list, const std::string &name) return std::find_if(list.cbegin(), list.cend(), match_name) != list.cend(); } -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; /* Global flags and properties */ diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 4eeeafac..ae87e7eb 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -44,7 +45,6 @@ #include "core/helpers.h" #include "core/logging.h" #include "threads.h" -#include "vector.h" #include @@ -70,7 +70,7 @@ struct SolarisBackend final : public BackendBase { int mFd{-1}; uint mFrameStep{}; - al::vector mBuffer; + std::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 97f0a291..d4ad38e2 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -59,6 +59,7 @@ #include "albit.h" #include "alc/alconfig.h" #include "alnumeric.h" +#include "alspan.h" #include "comptr.h" #include "core/converter.h" #include "core/device.h" @@ -180,15 +181,14 @@ struct DevMap { { } }; -bool checkName(const al::vector &list, const std::string &name) +bool checkName(const al::span list, const std::string &name) { - auto match_name = [&name](const DevMap &entry) -> bool - { return entry.name == name; }; + auto match_name = [&name](const DevMap &entry) -> bool { return entry.name == name; }; return std::find_if(list.cbegin(), list.cend(), match_name) != list.cend(); } -al::vector PlaybackDevices; -al::vector CaptureDevices; +std::vector PlaybackDevices; +std::vector CaptureDevices; using NameGUIDPair = std::pair; @@ -262,7 +262,7 @@ EndpointFormFactor get_device_formfactor(IMMDevice *device) } -void add_device(IMMDevice *device, const WCHAR *devid, al::vector &list) +void add_device(IMMDevice *device, const WCHAR *devid, std::vector &list) { for(auto &entry : list) { @@ -301,9 +301,9 @@ WCHAR *get_device_id(IMMDevice *device) return devid; } -void probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, al::vector &list) +void probe_devices(IMMDeviceEnumerator *devenum, EDataFlow flowdir, std::vector &list) { - al::vector{}.swap(list); + std::vector{}.swap(list); ComPtr coll; HRESULT hr{devenum->EnumAudioEndpoints(flowdir, DEVICE_STATE_ACTIVE, al::out_ptr(coll))}; @@ -1355,7 +1355,7 @@ FORCE_ALIGN int WasapiCapture::recordProc() althrd_setname(RECORD_THREAD_NAME); - al::vector samples; + std::vector samples; while(!mKillNow.load(std::memory_order_relaxed)) { UINT32 avail; diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index f8302f1e..1ee2fe51 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "albit.h" #include "alc/alconfig.h" @@ -43,7 +44,6 @@ #include "opthelpers.h" #include "strutils.h" #include "threads.h" -#include "vector.h" namespace { @@ -104,7 +104,7 @@ struct WaveBackend final : public BackendBase { FILE *mFile{nullptr}; long mDataStart{-1}; - al::vector mBuffer; + std::vector mBuffer; std::atomic mKillNow{true}; std::thread mThread; diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index edb875a0..0345fe10 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -58,7 +58,7 @@ namespace { std::vector PlaybackDevices; std::vector CaptureDevices; -bool checkName(const al::vector &list, const std::string &name) +bool checkName(const std::vector &list, const std::string &name) { return std::find(list.cbegin(), list.cend(), name) != list.cend(); } void ProbePlaybackDevices(void) diff --git a/alc/context.h b/alc/context.h index acbb3788..779be113 100644 --- a/alc/context.h +++ b/alc/context.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -21,7 +22,6 @@ #include "core/context.h" #include "inprogext.h" #include "intrusive_ptr.h" -#include "vector.h" #ifdef ALSOFT_EAX #include "al/eax/call.h" @@ -132,11 +132,11 @@ struct ALCcontext : public al::intrusive_ref, ContextBase { ALlistener mListener{}; - al::vector mSourceList; + std::vector mSourceList; ALuint mNumSources{0}; std::mutex mSourceLock; - al::vector mEffectSlotList; + std::vector mEffectSlotList; ALuint mNumEffectSlots{0u}; std::mutex mEffectSlotLock; diff --git a/alc/device.h b/alc/device.h index d5e82ce3..1274e287 100644 --- a/alc/device.h +++ b/alc/device.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "AL/alc.h" #include "AL/alext.h" @@ -18,7 +19,6 @@ #include "core/device.h" #include "inprogext.h" #include "intrusive_ptr.h" -#include "vector.h" #ifdef ALSOFT_EAX #include "al/eax/x_ram.h" @@ -95,7 +95,7 @@ struct ALCdevice : public al::intrusive_ref, DeviceBase { uint AuxiliaryEffectSlotMax{}; std::string mHrtfName; - al::vector mHrtfList; + std::vector mHrtfList; ALCenum mHrtfStatus{ALC_FALSE}; enum class OutputMode1 : ALCenum { @@ -118,15 +118,15 @@ struct ALCdevice : public al::intrusive_ref, DeviceBase { // Map of Buffers for this device std::mutex BufferLock; - al::vector BufferList; + std::vector BufferList; // Map of Effects for this device std::mutex EffectLock; - al::vector EffectList; + std::vector EffectList; // Map of Filters for this device std::mutex FilterLock; - al::vector FilterList; + std::vector FilterList; #ifdef ALSOFT_EAX ALuint eax_x_ram_free_size{eax_x_ram_max_size}; diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp index 10ccf9f6..7c281aa5 100644 --- a/alc/effects/chorus.cpp +++ b/alc/effects/chorus.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "alc/effects/base.h" #include "almalloc.h" @@ -41,7 +42,6 @@ #include "core/resampler_limits.h" #include "intrusive_ptr.h" #include "opthelpers.h" -#include "vector.h" namespace { @@ -49,7 +49,7 @@ namespace { using uint = unsigned int; struct ChorusState final : public EffectState { - al::vector mDelayBuffer; + std::vector mDelayBuffer; uint mOffset{0}; uint mLfoOffset{0}; diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp index a69529dc..7824c246 100644 --- a/alc/effects/echo.cpp +++ b/alc/effects/echo.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "alc/effects/base.h" #include "almalloc.h" @@ -39,7 +40,6 @@ #include "core/mixer.h" #include "intrusive_ptr.h" #include "opthelpers.h" -#include "vector.h" namespace { @@ -49,7 +49,7 @@ using uint = unsigned int; constexpr float LowpassFreqRef{5000.0f}; struct EchoState final : public EffectState { - al::vector mSampleBuffer; + std::vector mSampleBuffer; // The echo is two tap. The delay is the number of samples from before the // current offset @@ -87,7 +87,7 @@ void EchoState::deviceUpdate(const DeviceBase *Device, const BufferStorage*) const uint maxlen{NextPowerOf2(float2uint(EchoMaxDelay*frequency + 0.5f) + float2uint(EchoMaxLRDelay*frequency + 0.5f))}; if(maxlen != mSampleBuffer.size()) - al::vector(maxlen).swap(mSampleBuffer); + decltype(mSampleBuffer)(maxlen).swap(mSampleBuffer); std::fill(mSampleBuffer.begin(), mSampleBuffer.end(), 0.0f); for(auto &e : mGains) diff --git a/alc/panning.cpp b/alc/panning.cpp index 60ce7ca4..6fc955ee 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include "AL/al.h" #include "AL/alc.h" @@ -628,7 +629,7 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize= const size_t ambicount{decoder.mIs3D ? AmbiChannelsFromOrder(decoder.mOrder) : Ambi2DChannelsFromOrder(decoder.mOrder)}; const bool dual_band{hqdec && !decoder.mCoeffsLF.empty()}; - al::vector chancoeffs, chancoeffslf; + std::vector chancoeffs, chancoeffslf; for(size_t i{0u};i < decoder.mChannels.size();++i) { const uint idx{device->channelIdxByName(decoder.mChannels[i])}; diff --git a/core/bformatdec.h b/core/bformatdec.h index 7a27a5a4..42024bd9 100644 --- a/core/bformatdec.h +++ b/core/bformatdec.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "almalloc.h" #include "alspan.h" @@ -11,7 +12,6 @@ #include "bufferline.h" #include "devformat.h" #include "filters/splitter.h" -#include "vector.h" struct FrontStablizer; @@ -43,7 +43,7 @@ class BFormatDec { * only be used in a standard layout struct, and a std::unique_ptr member * (mStablizer) causes GCC and Clang to warn it's not. */ - al::vector mChannelDec; + std::vector mChannelDec; public: BFormatDec(const size_t inchans, const al::span coeffs, diff --git a/core/hrtf.cpp b/core/hrtf.cpp index 607e3d3d..7d11ee19 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "albit.h" #include "alfstream.h" @@ -34,7 +35,6 @@ #include "mixer/hrtfdefs.h" #include "opthelpers.h" #include "polyphase_resampler.h" -#include "vector.h" namespace { @@ -98,10 +98,10 @@ constexpr char magicMarker03[8]{'M','i','n','P','H','R','0','3'}; constexpr auto PassthruCoeff = static_cast(1.0/al::numbers::sqrt2); std::mutex LoadedHrtfLock; -al::vector LoadedHrtfs; +std::vector LoadedHrtfs; std::mutex EnumeratedHrtfLock; -al::vector EnumeratedHrtfs; +std::vector EnumeratedHrtfs; class databuf final : public std::streambuf { @@ -295,7 +295,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const bool } uint min_delay{HrtfHistoryLength*HrirDelayFracOne}, max_delay{0}; - al::vector impres; impres.reserve(AmbiPoints.size()); + std::vector impres; impres.reserve(AmbiPoints.size()); auto calc_res = [Hrtf,&max_delay,&min_delay](const AngularPoint &pt) -> ImpulseResponse { auto &field = Hrtf->mFields[0]; @@ -331,7 +331,7 @@ void DirectHrtfState::build(const HrtfStore *Hrtf, const uint irSize, const bool TRACE("Min delay: %.2f, max delay: %.2f, FIR length: %u\n", min_delay/double{HrirDelayFracOne}, max_delay/double{HrirDelayFracOne}, irSize); - auto tmpres = al::vector>(mChannels.size()); + auto tmpres = std::vector>(mChannels.size()); max_delay = 0; for(size_t c{0u};c < AmbiPoints.size();++c) { @@ -529,7 +529,7 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) return nullptr; } - auto elevs = al::vector(evCount); + auto elevs = std::vector(evCount); for(auto &elev : elevs) elev.irOffset = readle(data); if(!data || data.eof()) @@ -571,8 +571,8 @@ std::unique_ptr LoadHrtf00(std::istream &data, const char *filename) return nullptr; } - auto coeffs = al::vector(irCount, HrirArray{}); - auto delays = al::vector(irCount); + auto coeffs = std::vector(irCount, HrirArray{}); + auto delays = std::vector(irCount); for(auto &hrir : coeffs) { for(auto &val : al::span{hrir.data(), irSize}) @@ -626,7 +626,7 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) return nullptr; } - auto elevs = al::vector(evCount); + auto elevs = std::vector(evCount); for(auto &elev : elevs) elev.azCount = readle(data); if(!data || data.eof()) @@ -649,8 +649,8 @@ std::unique_ptr LoadHrtf01(std::istream &data, const char *filename) elevs[i].irOffset = static_cast(elevs[i-1].irOffset + elevs[i-1].azCount); const ushort irCount{static_cast(elevs.back().irOffset + elevs.back().azCount)}; - auto coeffs = al::vector(irCount, HrirArray{}); - auto delays = al::vector(irCount); + auto coeffs = std::vector(irCount, HrirArray{}); + auto delays = std::vector(irCount); for(auto &hrir : coeffs) { for(auto &val : al::span{hrir.data(), irSize}) @@ -722,8 +722,8 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) return nullptr; } - auto fields = al::vector(fdCount); - auto elevs = al::vector{}; + auto fields = std::vector(fdCount); + auto elevs = std::vector{}; for(size_t f{0};f < fdCount;f++) { const ushort distance{readle(data)}; @@ -787,8 +787,8 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) }); const auto irTotal = static_cast(elevs.back().azCount + elevs.back().irOffset); - auto coeffs = al::vector(irTotal, HrirArray{}); - auto delays = al::vector(irTotal); + auto coeffs = std::vector(irTotal, HrirArray{}); + auto delays = std::vector(irTotal); if(channelType == ChanType_LeftOnly) { if(sampleType == SampleType_S16) @@ -881,10 +881,10 @@ std::unique_ptr LoadHrtf02(std::istream &data, const char *filename) if(fdCount > 1) { - auto fields_ = al::vector(fields.size()); - auto elevs_ = al::vector(elevs.size()); - auto coeffs_ = al::vector(coeffs.size()); - auto delays_ = al::vector(delays.size()); + auto fields_ = std::vector(fields.size()); + auto elevs_ = std::vector(elevs.size()); + auto coeffs_ = std::vector(coeffs.size()); + auto delays_ = std::vector(delays.size()); /* Simple reverse for the per-field elements. */ std::reverse_copy(fields.cbegin(), fields.cend(), fields_.begin()); @@ -983,8 +983,8 @@ std::unique_ptr LoadHrtf03(std::istream &data, const char *filename) return nullptr; } - auto fields = al::vector(fdCount); - auto elevs = al::vector{}; + auto fields = std::vector(fdCount); + auto elevs = std::vector{}; for(size_t f{0};f < fdCount;f++) { const ushort distance{readle(data)}; @@ -1048,8 +1048,8 @@ std::unique_ptr LoadHrtf03(std::istream &data, const char *filename) }); const auto irTotal = static_cast(elevs.back().azCount + elevs.back().irOffset); - auto coeffs = al::vector(irTotal, HrirArray{}); - auto delays = al::vector(irTotal); + auto coeffs = std::vector(irTotal, HrirArray{}); + auto delays = std::vector(irTotal); if(channelType == ChanType_LeftOnly) { for(auto &hrir : coeffs) @@ -1221,7 +1221,7 @@ al::span GetResource(int name) } // namespace -al::vector EnumerateHrtf(std::optional pathopt) +std::vector EnumerateHrtf(std::optional pathopt) { std::lock_guard _{EnumeratedHrtfLock}; EnumeratedHrtfs.clear(); @@ -1270,7 +1270,7 @@ al::vector EnumerateHrtf(std::optional pathopt) AddBuiltInEntry("Built-In HRTF", IDR_DEFAULT_HRTF_MHR); } - al::vector list; + std::vector list; list.reserve(EnumeratedHrtfs.size()); for(auto &entry : EnumeratedHrtfs) list.emplace_back(entry.mDispName); @@ -1394,7 +1394,7 @@ HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate) /* Scale the delays for the new sample rate. */ float max_delay{0.0f}; - auto new_delays = al::vector(irCount); + auto new_delays = std::vector(irCount); const float rate_scale{static_cast(devrate)/static_cast(hrtf->mSampleRate)}; for(size_t i{0};i < irCount;++i) { diff --git a/core/hrtf.h b/core/hrtf.h index 7215711b..5e6e09a8 100644 --- a/core/hrtf.h +++ b/core/hrtf.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "almalloc.h" #include "alspan.h" @@ -14,7 +15,6 @@ #include "bufferline.h" #include "mixer/hrtfdefs.h" #include "intrusive_ptr.h" -#include "vector.h" struct HrtfStore { @@ -83,7 +83,7 @@ struct DirectHrtfState { }; -al::vector EnumerateHrtf(std::optional pathopt); +std::vector EnumerateHrtf(std::optional pathopt); HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate); #endif /* CORE_HRTF_H */ diff --git a/core/logging.cpp b/core/logging.cpp index 8e0116ea..34385cf4 100644 --- a/core/logging.cpp +++ b/core/logging.cpp @@ -6,10 +6,10 @@ #include #include #include +#include #include "alspan.h" #include "strutils.h" -#include "vector.h" #if defined(_WIN32) @@ -34,7 +34,7 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) case LogLevel::Trace: prefix = al::span{"[ALSOFT] (II) "}.first<14>(); break; } - al::vector dynmsg; + std::vector dynmsg; std::array stcmsg{}; char *str{stcmsg.data()}; -- cgit v1.2.3 From c200eb73a7cf47dbd1a4a3785be471adfb3513d8 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 1 Jun 2023 17:31:31 -0700 Subject: Move althrd_setname to its own source --- CMakeLists.txt | 2 ++ alc/backends/alsa.cpp | 2 +- alc/backends/dsound.cpp | 2 +- alc/backends/jack.cpp | 1 + alc/backends/null.cpp | 4 +-- alc/backends/opensl.cpp | 1 + alc/backends/oss.cpp | 2 +- alc/backends/sndio.cpp | 2 +- alc/backends/solaris.cpp | 2 +- alc/backends/wasapi.cpp | 2 +- alc/backends/wave.cpp | 2 +- alc/backends/winmm.cpp | 1 + common/althrd_setname.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++ common/althrd_setname.h | 6 ++++ common/threads.cpp | 66 ---------------------------------------- common/threads.h | 2 -- 16 files changed, 96 insertions(+), 77 deletions(-) create mode 100644 common/althrd_setname.cpp create mode 100644 common/althrd_setname.h (limited to 'alc/backends/oss.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index e4d3776d..63a213c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -621,6 +621,8 @@ set(COMMON_OBJS common/alspan.h common/alstring.cpp common/alstring.h + common/althrd_setname.cpp + common/althrd_setname.h common/altraits.h common/atomic.h common/comptr.h diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index ce368f5e..83eef183 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -41,12 +41,12 @@ #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "dynload.h" #include "ringbuffer.h" -#include "threads.h" #include diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 5fc8a1c7..54fac898 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -47,6 +47,7 @@ #include "albit.h" #include "alnumeric.h" #include "alspan.h" +#include "althrd_setname.h" #include "comptr.h" #include "core/device.h" #include "core/helpers.h" @@ -54,7 +55,6 @@ #include "dynload.h" #include "ringbuffer.h" #include "strutils.h" -#include "threads.h" /* MinGW-w64 needs this for some unknown reason now. */ using LPCWAVEFORMATEX = const WAVEFORMATEX*; diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 9e023e21..b8325b05 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -35,6 +35,7 @@ #include "albit.h" #include "alc/alconfig.h" #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index 5a8fc255..73420ad3 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -30,10 +30,10 @@ #include #include -#include "core/device.h" +#include "althrd_setname.h" #include "almalloc.h" +#include "core/device.h" #include "core/helpers.h" -#include "threads.h" namespace { diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index c9053816..a3b70791 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -35,6 +35,7 @@ #include "albit.h" #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index dc18c4c3..554ccc24 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -43,11 +43,11 @@ #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "ringbuffer.h" -#include "threads.h" #include diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 2040dd3a..84c54c62 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -32,11 +32,11 @@ #include #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "ringbuffer.h" -#include "threads.h" #include diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index ae87e7eb..15dcc98f 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -41,10 +41,10 @@ #include #include "alc/alconfig.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" -#include "threads.h" #include diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 32a4334d..2b88aa96 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -61,6 +61,7 @@ #include "alc/events.h" #include "alnumeric.h" #include "alspan.h" +#include "althrd_setname.h" #include "comptr.h" #include "core/converter.h" #include "core/device.h" @@ -68,7 +69,6 @@ #include "core/logging.h" #include "ringbuffer.h" #include "strutils.h" -#include "threads.h" #if defined(ALSOFT_UWP) #include diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 1ee2fe51..40592ee7 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -38,12 +38,12 @@ #include "alc/alconfig.h" #include "almalloc.h" #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" #include "opthelpers.h" #include "strutils.h" -#include "threads.h" namespace { diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 0345fe10..fa5bf22a 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -39,6 +39,7 @@ #include #include "alnumeric.h" +#include "althrd_setname.h" #include "core/device.h" #include "core/helpers.h" #include "core/logging.h" diff --git a/common/althrd_setname.cpp b/common/althrd_setname.cpp new file mode 100644 index 00000000..22d33092 --- /dev/null +++ b/common/althrd_setname.cpp @@ -0,0 +1,76 @@ + +#include "config.h" + +#include "althrd_setname.h" + + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +void althrd_setname(const char *name [[maybe_unused]]) +{ +#if defined(_MSC_VER) && !defined(_M_ARM) + +#define MS_VC_EXCEPTION 0x406D1388 +#pragma pack(push,8) + struct { + DWORD dwType; // Must be 0x1000. + LPCSTR szName; // Pointer to name (in user addr space). + DWORD dwThreadID; // Thread ID (-1=caller thread). + DWORD dwFlags; // Reserved for future use, must be zero. + } info; +#pragma pack(pop) + info.dwType = 0x1000; + info.szName = name; + info.dwThreadID = ~DWORD{0}; + info.dwFlags = 0; + + /* FIXME: How to do this on MinGW? */ + __try { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); + } + __except(EXCEPTION_CONTINUE_EXECUTION) { + } +#undef MS_VC_EXCEPTION +#endif +} + +#else + +#include +#ifdef HAVE_PTHREAD_NP_H +#include +#endif + +namespace { + +using setname_t1 = int(*)(const char*); +using setname_t2 = int(*)(pthread_t, const char*); +using setname_t3 = void(*)(pthread_t, const char*); +using setname_t4 = int(*)(pthread_t, const char*, void*); + +[[maybe_unused]] void setname_caller(setname_t1 func, const char *name) +{ func(name); } + +[[maybe_unused]] void setname_caller(setname_t2 func, const char *name) +{ func(pthread_self(), name); } + +[[maybe_unused]] void setname_caller(setname_t3 func, const char *name) +{ func(pthread_self(), name); } + +[[maybe_unused]] void setname_caller(setname_t4 func, const char *name) +{ func(pthread_self(), "%s", static_cast(const_cast(name))); } + +} // namespace + +void althrd_setname(const char *name [[maybe_unused]]) +{ +#if defined(HAVE_PTHREAD_SET_NAME_NP) + setname_caller(pthread_set_name_np, name); +#elif defined(HAVE_PTHREAD_SETNAME_NP) + setname_caller(pthread_setname_np, name); +#endif +} + +#endif diff --git a/common/althrd_setname.h b/common/althrd_setname.h new file mode 100644 index 00000000..0e22c0a9 --- /dev/null +++ b/common/althrd_setname.h @@ -0,0 +1,6 @@ +#ifndef COMMON_ALTHRD_SETNAME_H +#define COMMON_ALTHRD_SETNAME_H + +void althrd_setname(const char *name); + +#endif /* COMMON_ALTHRD_SETNAME_H */ diff --git a/common/threads.cpp b/common/threads.cpp index c1d9e8b0..c176f5af 100644 --- a/common/threads.cpp +++ b/common/threads.cpp @@ -32,37 +32,6 @@ #include -void althrd_setname(const char *name) -{ -#if defined(_MSC_VER) && !defined(_M_ARM) - -#define MS_VC_EXCEPTION 0x406D1388 -#pragma pack(push,8) - struct { - DWORD dwType; // Must be 0x1000. - LPCSTR szName; // Pointer to name (in user addr space). - DWORD dwThreadID; // Thread ID (-1=caller thread). - DWORD dwFlags; // Reserved for future use, must be zero. - } info; -#pragma pack(pop) - info.dwType = 0x1000; - info.szName = name; - info.dwThreadID = ~DWORD{0}; - info.dwFlags = 0; - - __try { - RaiseException(MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info); - } - __except(EXCEPTION_CONTINUE_EXECUTION) { - } -#undef MS_VC_EXCEPTION - -#else - - (void)name; -#endif -} - namespace al { semaphore::semaphore(unsigned int initial) @@ -93,41 +62,6 @@ bool semaphore::try_wait() noexcept #else -#include -#ifdef HAVE_PTHREAD_NP_H -#include -#endif - -namespace { - -using setname_t1 = int(*)(const char*); -using setname_t2 = int(*)(pthread_t, const char*); -using setname_t3 = void(*)(pthread_t, const char*); -using setname_t4 = int(*)(pthread_t, const char*, void*); - -[[maybe_unused]] void setname_caller(setname_t1 func, const char *name) -{ func(name); } - -[[maybe_unused]] void setname_caller(setname_t2 func, const char *name) -{ func(pthread_self(), name); } - -[[maybe_unused]] void setname_caller(setname_t3 func, const char *name) -{ func(pthread_self(), name); } - -[[maybe_unused]] void setname_caller(setname_t4 func, const char *name) -{ func(pthread_self(), "%s", static_cast(const_cast(name))); } - -} // namespace - -void althrd_setname(const char *name [[maybe_unused]]) -{ -#if defined(HAVE_PTHREAD_SET_NAME_NP) - setname_caller(pthread_set_name_np, name); -#elif defined(HAVE_PTHREAD_SETNAME_NP) - setname_caller(pthread_setname_np, name); -#endif -} - /* Do not try using libdispatch on systems where it is absent. */ #if defined(AL_APPLE_HAVE_DISPATCH) diff --git a/common/threads.h b/common/threads.h index 1ef037bb..703d50d4 100644 --- a/common/threads.h +++ b/common/threads.h @@ -14,8 +14,6 @@ #include #endif -void althrd_setname(const char *name); - namespace al { class semaphore { -- cgit v1.2.3 From 9296af5566afea4ba4cb78b374ef3ee0bf9bc04b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 6 Aug 2023 18:49:42 -0700 Subject: Use a string_view for the backend open method --- alc/alc.cpp | 41 ++++++++++++++++++++++++++++++----- alc/backends/alsa.cpp | 16 +++++++------- alc/backends/base.h | 3 ++- alc/backends/coreaudio.cpp | 36 +++++++++++++++--------------- alc/backends/dsound.cpp | 22 ++++++++++--------- alc/backends/jack.cpp | 18 +++++++-------- alc/backends/loopback.cpp | 4 ++-- alc/backends/null.cpp | 12 +++++----- alc/backends/oboe.cpp | 24 ++++++++++---------- alc/backends/opensl.cpp | 24 ++++++++++---------- alc/backends/oss.cpp | 16 +++++++------- alc/backends/pipewire.cpp | 21 +++++++++--------- alc/backends/portaudio.cpp | 24 ++++++++++---------- alc/backends/pulseaudio.cpp | 16 +++++++------- alc/backends/sdl2.cpp | 27 +++++++++++++++++------ alc/backends/sndio.cpp | 24 ++++++++++---------- alc/backends/solaris.cpp | 12 +++++----- alc/backends/wasapi.cpp | 53 +++++++++++++++++++++++---------------------- alc/backends/wave.cpp | 14 ++++++------ alc/backends/winmm.cpp | 20 ++++++++--------- common/strutils.cpp | 17 ++++++++------- common/strutils.h | 5 +++-- 22 files changed, 249 insertions(+), 200 deletions(-) (limited to 'alc/backends/oss.cpp') diff --git a/alc/alc.cpp b/alc/alc.cpp index 82f3ec4b..45a55793 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2905,9 +2905,26 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) noexcep device->NumAuxSends = DefaultSends; try { + /* We need to ensure the device name isn't too long. The string_view is + * printed using the "%.*s" formatter, which uses an int for the + * precision/length. It wouldn't be a significant problem if larger + * values simply printed fewer characters due to truncation, but + * negative values are ignored, treating it like a normal null- + * terminated string, and string_views don't need to be null- + * terminated. + * + * Other than the annoyance of checking, this shouldn't be a problem. + * Two billion bytes is enough for a device name. + */ + const std::string_view devname{deviceName ? deviceName : ""}; + if(devname.length() >= std::numeric_limits::max()) + throw al::backend_exception{al::backend_error::NoDevice, + "Device name too long (%zu >= %d)", devname.length(), + std::numeric_limits::max()}; + auto backend = PlaybackFactory->createBackend(device.get(), BackendType::Playback); std::lock_guard _{ListLock}; - backend->open(deviceName); + backend->open(devname); device->Backend = std::move(backend); } catch(al::backend_exception &e) { @@ -3024,14 +3041,20 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName, device->UpdateSize = static_cast(samples); device->BufferSize = static_cast(samples); + TRACE("Capture format: %s, %s, %uhz, %u / %u buffer\n", DevFmtChannelsString(device->FmtChans), + DevFmtTypeString(device->FmtType), device->Frequency, device->UpdateSize, + device->BufferSize); + try { - TRACE("Capture format: %s, %s, %uhz, %u / %u buffer\n", - DevFmtChannelsString(device->FmtChans), DevFmtTypeString(device->FmtType), - device->Frequency, device->UpdateSize, device->BufferSize); + const std::string_view devname{deviceName ? deviceName : ""}; + if(devname.length() >= std::numeric_limits::max()) + throw al::backend_exception{al::backend_error::NoDevice, + "Device name too long (%zu >= %d)", devname.length(), + std::numeric_limits::max()}; auto backend = CaptureFactory->createBackend(device.get(), BackendType::Capture); std::lock_guard _{ListLock}; - backend->open(deviceName); + backend->open(devname); device->Backend = std::move(backend); } catch(al::backend_exception &e) { @@ -3393,8 +3416,14 @@ FORCE_ALIGN ALCboolean ALC_APIENTRY alcReopenDeviceSOFT(ALCdevice *device, BackendPtr newbackend; try { + const std::string_view devname{deviceName ? deviceName : ""}; + if(devname.length() >= std::numeric_limits::max()) + throw al::backend_exception{al::backend_error::NoDevice, + "Device name too long (%zu >= %d)", devname.length(), + std::numeric_limits::max()}; + newbackend = PlaybackFactory->createBackend(dev.get(), BackendType::Playback); - newbackend->open(deviceName); + newbackend->open(devname); } catch(al::backend_exception &e) { listlock.unlock(); diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 83eef183..0d9ff30d 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -427,7 +427,7 @@ struct AlsaPlayback final : public BackendBase { int mixerProc(); int mixerNoMMapProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -626,10 +626,10 @@ int AlsaPlayback::mixerNoMMapProc() } -void AlsaPlayback::open(const char *name) +void AlsaPlayback::open(std::string_view name) { std::string driver{"default"}; - if(name) + if(!name.empty()) { if(PlaybackDevices.empty()) PlaybackDevices = probe_devices(SND_PCM_STREAM_PLAYBACK); @@ -638,7 +638,7 @@ void AlsaPlayback::open(const char *name) [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == PlaybackDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; driver = iter->device_name; } else @@ -871,7 +871,7 @@ struct AlsaCapture final : public BackendBase { AlsaCapture(DeviceBase *device) noexcept : BackendBase{device} { } ~AlsaCapture() override; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -898,10 +898,10 @@ AlsaCapture::~AlsaCapture() } -void AlsaCapture::open(const char *name) +void AlsaCapture::open(std::string_view name) { std::string driver{"default"}; - if(name) + if(!name.empty()) { if(CaptureDevices.empty()) CaptureDevices = probe_devices(SND_PCM_STREAM_CAPTURE); @@ -910,7 +910,7 @@ void AlsaCapture::open(const char *name) [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == CaptureDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; driver = iter->device_name; } else diff --git a/alc/backends/base.h b/alc/backends/base.h index 07b430e0..a4079fe4 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "core/device.h" #include "core/except.h" @@ -20,7 +21,7 @@ struct ClockLatency { }; struct BackendBase { - virtual void open(const char *name) = 0; + virtual void open(std::string_view name) = 0; virtual bool reset(); virtual void start() = 0; diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 12c667ac..1684545b 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -329,7 +329,7 @@ struct CoreAudioPlayback final : public BackendBase { const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -362,11 +362,11 @@ OSStatus CoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags*, const AudioTi } -void CoreAudioPlayback::open(const char *name) +void CoreAudioPlayback::open(std::string_view name) { #if CAN_ENUMERATE AudioDeviceID audioDevice{kAudioDeviceUnknown}; - if(!name) + if(name.empty()) GetHwProperty(kAudioHardwarePropertyDefaultOutputDevice, sizeof(audioDevice), &audioDevice); else @@ -379,16 +379,16 @@ void CoreAudioPlayback::open(const char *name) auto devmatch = std::find_if(PlaybackList.cbegin(), PlaybackList.cend(), find_name); if(devmatch == PlaybackList.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; audioDevice = devmatch->mId; } #else - if(!name) + if(name.empty()) name = ca_device; - else if(strcmp(name, ca_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != ca_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; #endif /* open the default output unit */ @@ -436,7 +436,7 @@ void CoreAudioPlayback::open(const char *name) mAudioUnit = audioUnit; #if CAN_ENUMERATE - if(name) + if(!name.empty()) mDevice->DeviceName = name; else { @@ -608,7 +608,7 @@ struct CoreAudioCapture final : public BackendBase { const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -663,11 +663,11 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags *ioActionFlags, } -void CoreAudioCapture::open(const char *name) +void CoreAudioCapture::open(std::string_view name) { #if CAN_ENUMERATE AudioDeviceID audioDevice{kAudioDeviceUnknown}; - if(!name) + if(name.empty()) GetHwProperty(kAudioHardwarePropertyDefaultInputDevice, sizeof(audioDevice), &audioDevice); else @@ -680,16 +680,16 @@ void CoreAudioCapture::open(const char *name) auto devmatch = std::find_if(CaptureList.cbegin(), CaptureList.cend(), find_name); if(devmatch == CaptureList.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; audioDevice = devmatch->mId; } #else - if(!name) + if(name.empty()) name = ca_device; - else if(strcmp(name, ca_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != ca_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; #endif AudioComponentDescription desc{}; @@ -887,7 +887,7 @@ void CoreAudioCapture::open(const char *name) mDevice->Frequency, Resampler::FastBSinc24); #if CAN_ENUMERATE - if(name) + if(!name.empty()) mDevice->DeviceName = name; else { diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 54fac898..b5596f1c 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -178,7 +178,7 @@ struct DSoundPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -301,7 +301,7 @@ FORCE_ALIGN int DSoundPlayback::mixerProc() return 0; } -void DSoundPlayback::open(const char *name) +void DSoundPlayback::open(std::string_view name) { HRESULT hr; if(PlaybackDevices.empty()) @@ -316,9 +316,9 @@ void DSoundPlayback::open(const char *name) } const GUID *guid{nullptr}; - if(!name && !PlaybackDevices.empty()) + if(name.empty() && !PlaybackDevices.empty()) { - name = PlaybackDevices[0].name.c_str(); + name = PlaybackDevices[0].name; guid = &PlaybackDevices[0].guid; } else @@ -334,7 +334,8 @@ void DSoundPlayback::open(const char *name) [&id](const DevMap &entry) -> bool { return entry.guid == id; }); if(iter == PlaybackDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), + name.data()}; } guid = &iter->guid; } @@ -549,7 +550,7 @@ struct DSoundCapture final : public BackendBase { DSoundCapture(DeviceBase *device) noexcept : BackendBase{device} { } ~DSoundCapture() override; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -576,7 +577,7 @@ DSoundCapture::~DSoundCapture() } -void DSoundCapture::open(const char *name) +void DSoundCapture::open(std::string_view name) { HRESULT hr; if(CaptureDevices.empty()) @@ -591,9 +592,9 @@ void DSoundCapture::open(const char *name) } const GUID *guid{nullptr}; - if(!name && !CaptureDevices.empty()) + if(name.empty() && !CaptureDevices.empty()) { - name = CaptureDevices[0].name.c_str(); + name = CaptureDevices[0].name; guid = &CaptureDevices[0].guid; } else @@ -609,7 +610,8 @@ void DSoundCapture::open(const char *name) [&id](const DevMap &entry) -> bool { return entry.guid == id; }); if(iter == CaptureDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), + name.data()}; } guid = &iter->guid; } diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 66fc0877..a0a5c440 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -298,7 +298,7 @@ struct JackPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -460,7 +460,7 @@ int JackPlayback::mixerProc() } -void JackPlayback::open(const char *name) +void JackPlayback::open(std::string_view name) { if(!mClient) { @@ -484,9 +484,9 @@ void JackPlayback::open(const char *name) if(PlaybackList.empty()) EnumerateDevices(mClient, PlaybackList); - if(!name && !PlaybackList.empty()) + if(name.empty() && !PlaybackList.empty()) { - name = PlaybackList[0].mName.c_str(); + name = PlaybackList[0].mName; mPortPattern = PlaybackList[0].mPattern; } else @@ -496,14 +496,10 @@ void JackPlayback::open(const char *name) auto iter = std::find_if(PlaybackList.cbegin(), PlaybackList.cend(), check_name); if(iter == PlaybackList.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name?name:""}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; mPortPattern = iter->mPattern; } - mRTMixing = GetConfigValueBool(name, "jack", "rt-mix", true); - jack_set_process_callback(mClient, - mRTMixing ? &JackPlayback::processRtC : &JackPlayback::processC, this); - mDevice->DeviceName = name; } @@ -514,6 +510,10 @@ bool JackPlayback::reset() std::for_each(mPort.begin(), mPort.end(), unregister_port); mPort.fill(nullptr); + mRTMixing = GetConfigValueBool(mDevice->DeviceName.c_str(), "jack", "rt-mix", true); + jack_set_process_callback(mClient, + mRTMixing ? &JackPlayback::processRtC : &JackPlayback::processC, this); + /* Ignore the requested buffer metrics and just keep one JACK-sized buffer * ready for when requested. */ diff --git a/alc/backends/loopback.cpp b/alc/backends/loopback.cpp index bf4ab246..2972fc01 100644 --- a/alc/backends/loopback.cpp +++ b/alc/backends/loopback.cpp @@ -30,7 +30,7 @@ namespace { struct LoopbackBackend final : public BackendBase { LoopbackBackend(DeviceBase *device) noexcept : BackendBase{device} { } - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -39,7 +39,7 @@ struct LoopbackBackend final : public BackendBase { }; -void LoopbackBackend::open(const char *name) +void LoopbackBackend::open(std::string_view name) { mDevice->DeviceName = name; } diff --git a/alc/backends/null.cpp b/alc/backends/null.cpp index 73420ad3..3c68e4ce 100644 --- a/alc/backends/null.cpp +++ b/alc/backends/null.cpp @@ -50,7 +50,7 @@ struct NullBackend final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -105,13 +105,13 @@ int NullBackend::mixerProc() } -void NullBackend::open(const char *name) +void NullBackend::open(std::string_view name) { - if(!name) + if(name.empty()) name = nullDevice; - else if(strcmp(name, nullDevice) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != nullDevice) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; mDevice->DeviceName = name; } diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp index cc44b867..b7bab19a 100644 --- a/alc/backends/oboe.cpp +++ b/alc/backends/oboe.cpp @@ -30,7 +30,7 @@ struct OboePlayback final : public BackendBase, public oboe::AudioStreamCallback void onErrorAfterClose(oboe::AudioStream* /* audioStream */, oboe::Result /* error */) override; - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -56,13 +56,13 @@ void OboePlayback::onErrorAfterClose(oboe::AudioStream* audioStream, oboe::Resul TRACE("Error was %s", oboe::convertToText(error)); } -void OboePlayback::open(const char *name) +void OboePlayback::open(std::string_view name) { - if(!name) + if(name.empty()) name = device_name; - else if(std::strcmp(name, device_name) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != device_name) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; /* Open a basic output stream, just to ensure it can work. */ oboe::ManagedStream stream; @@ -220,7 +220,7 @@ struct OboeCapture final : public BackendBase, public oboe::AudioStreamCallback oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData, int32_t numFrames) override; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -235,13 +235,13 @@ oboe::DataCallbackResult OboeCapture::onAudioReady(oboe::AudioStream*, void *aud } -void OboeCapture::open(const char *name) +void OboeCapture::open(std::string_view name) { - if(!name) + if(name.empty()) name = device_name; - else if(std::strcmp(name, device_name) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != device_name) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; oboe::AudioStreamBuilder builder; builder.setDirection(oboe::Direction::Input) diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 35c57d77..61e3c9a7 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -164,7 +164,7 @@ struct OpenSLPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -312,13 +312,13 @@ int OpenSLPlayback::mixerProc() } -void OpenSLPlayback::open(const char *name) +void OpenSLPlayback::open(std::string_view name) { - if(!name) + if(name.empty()) name = opensl_device; - else if(strcmp(name, opensl_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != opensl_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; /* There's only one device, so if it's already open, there's nothing to do. */ if(mEngineObj) return; @@ -645,7 +645,7 @@ struct OpenSLCapture final : public BackendBase { void process(SLAndroidSimpleBufferQueueItf bq) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -686,13 +686,13 @@ void OpenSLCapture::process(SLAndroidSimpleBufferQueueItf) noexcept } -void OpenSLCapture::open(const char* name) +void OpenSLCapture::open(std::string_view name) { - if(!name) + if(name.empty()) name = opensl_device; - else if(strcmp(name, opensl_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != opensl_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; SLresult result{slCreateEngine(&mEngineObj, 0, nullptr, 0, nullptr, nullptr)}; PrintErr(result, "slCreateEngine"); diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 554ccc24..87d3ba35 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -227,7 +227,7 @@ struct OSSPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -304,10 +304,10 @@ int OSSPlayback::mixerProc() } -void OSSPlayback::open(const char *name) +void OSSPlayback::open(std::string_view name) { const char *devname{DefaultPlayback.c_str()}; - if(!name) + if(name.empty()) name = DefaultName; else { @@ -320,7 +320,7 @@ void OSSPlayback::open(const char *name) ); if(iter == PlaybackDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; devname = iter->device_name.c_str(); } @@ -443,7 +443,7 @@ struct OSScapture final : public BackendBase { int recordProc(); - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -512,10 +512,10 @@ int OSScapture::recordProc() } -void OSScapture::open(const char *name) +void OSScapture::open(std::string_view name) { const char *devname{DefaultCapture.c_str()}; - if(!name) + if(name.empty()) name = DefaultName; else { @@ -528,7 +528,7 @@ void OSScapture::open(const char *name) ); if(iter == CaptureDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; devname = iter->device_name.c_str(); } diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 902d6374..9a63d2f4 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -1325,7 +1325,7 @@ class PipeWirePlayback final : public BackendBase { void ioChangedCallback(uint32_t id, void *area, uint32_t size) noexcept; void outputCallback() noexcept; - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -1428,14 +1428,14 @@ void PipeWirePlayback::outputCallback() noexcept } -void PipeWirePlayback::open(const char *name) +void PipeWirePlayback::open(std::string_view name) { static std::atomic OpenCount{0}; uint64_t targetid{PwIdAny}; std::string devname{}; gEventHandler.waitForInit(); - if(!name) + if(name.empty()) { EventWatcherLockGuard _{gEventHandler}; auto&& devlist = DeviceNode::GetList(); @@ -1470,7 +1470,7 @@ void PipeWirePlayback::open(const char *name) auto match = std::find_if(devlist.cbegin(), devlist.cend(), match_name); if(match == devlist.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; targetid = match->mSerial; devname = match->mName; @@ -1823,7 +1823,7 @@ class PipeWireCapture final : public BackendBase { void stateChangedCallback(pw_stream_state old, pw_stream_state state, const char *error) noexcept; void inputCallback() noexcept; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -1875,14 +1875,14 @@ void PipeWireCapture::inputCallback() noexcept } -void PipeWireCapture::open(const char *name) +void PipeWireCapture::open(std::string_view name) { static std::atomic OpenCount{0}; uint64_t targetid{PwIdAny}; std::string devname{}; gEventHandler.waitForInit(); - if(!name) + if(name.empty()) { EventWatcherLockGuard _{gEventHandler}; auto&& devlist = DeviceNode::GetList(); @@ -1920,16 +1920,17 @@ void PipeWireCapture::open(const char *name) auto match_name = [name](const DeviceNode &n) -> bool { return n.mType != NodeType::Sink && n.mName == name; }; auto match = std::find_if(devlist.cbegin(), devlist.cend(), match_name); - if(match == devlist.cend() && std::strncmp(name, MonitorPrefix, MonitorPrefixLen) == 0) + if(match == devlist.cend() && name.length() >= MonitorPrefixLen + && std::strncmp(name.data(), MonitorPrefix, MonitorPrefixLen) == 0) { - const char *sinkname{name + MonitorPrefixLen}; + const std::string_view sinkname{name.substr(MonitorPrefixLen)}; auto match_sinkname = [sinkname](const DeviceNode &n) -> bool { return n.mType == NodeType::Sink && n.mName == sinkname; }; match = std::find_if(devlist.cbegin(), devlist.cend(), match_sinkname); } if(match == devlist.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; targetid = match->mSerial; devname = name; diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 2551f448..979a54d6 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -86,7 +86,7 @@ struct PortPlayback final : public BackendBase { framesPerBuffer, timeInfo, statusFlags); } - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -116,13 +116,13 @@ int PortPlayback::writeCallback(const void*, void *outputBuffer, unsigned long f } -void PortPlayback::open(const char *name) +void PortPlayback::open(std::string_view name) { - if(!name) + if(name.empty()) name = pa_device; - else if(strcmp(name, pa_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != pa_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; PaStreamParameters params{}; auto devidopt = ConfigValueInt(nullptr, "port", "device"); @@ -245,7 +245,7 @@ struct PortCapture final : public BackendBase { framesPerBuffer, timeInfo, statusFlags); } - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -276,13 +276,13 @@ int PortCapture::readCallback(const void *inputBuffer, void*, unsigned long fram } -void PortCapture::open(const char *name) +void PortCapture::open(std::string_view name) { - if(!name) + if(name.empty()) name = pa_device; - else if(strcmp(name, pa_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != pa_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; uint samples{mDevice->BufferSize}; samples = maxu(samples, 100 * mDevice->Frequency / 1000); diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 8c6cc4d3..e2cea8a8 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -647,7 +647,7 @@ struct PulsePlayback final : public BackendBase { void sinkNameCallback(pa_context *context, const pa_sink_info *info, int eol) noexcept; void streamMovedCallback(pa_stream *stream) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -782,14 +782,14 @@ void PulsePlayback::streamMovedCallback(pa_stream *stream) noexcept } -void PulsePlayback::open(const char *name) +void PulsePlayback::open(std::string_view name) { mMainloop = PulseMainloop::Create(); mMainloop.start(); const char *pulse_name{nullptr}; const char *dev_name{nullptr}; - if(name) + if(!name.empty()) { if(PlaybackDevices.empty()) mMainloop.probePlaybackDevices(); @@ -798,7 +798,7 @@ void PulsePlayback::open(const char *name) [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == PlaybackDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; pulse_name = iter->device_name.c_str(); dev_name = iter->name.c_str(); } @@ -1066,7 +1066,7 @@ struct PulseCapture final : public BackendBase { void sourceNameCallback(pa_context *context, const pa_source_info *info, int eol) noexcept; void streamMovedCallback(pa_stream *stream) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -1123,7 +1123,7 @@ void PulseCapture::streamMovedCallback(pa_stream *stream) noexcept } -void PulseCapture::open(const char *name) +void PulseCapture::open(std::string_view name) { if(!mMainloop) { @@ -1132,7 +1132,7 @@ void PulseCapture::open(const char *name) } const char *pulse_name{nullptr}; - if(name) + if(!name.empty()) { if(CaptureDevices.empty()) mMainloop.probeCaptureDevices(); @@ -1141,7 +1141,7 @@ void PulseCapture::open(const char *name) [name](const DevMap &entry) -> bool { return entry.name == name; }); if(iter == CaptureDevices.cend()) throw al::backend_exception{al::backend_error::NoDevice, - "Device name \"%s\" not found", name}; + "Device name \"%.*s\" not found", static_cast(name.length()), name.data()}; pulse_name = iter->device_name.c_str(); mDevice->DeviceName = iter->name; } diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index e1e40e27..f5ed4316 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -54,7 +54,7 @@ struct Sdl2Backend final : public BackendBase { void audioCallback(Uint8 *stream, int len) noexcept; - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -84,7 +84,7 @@ void Sdl2Backend::audioCallback(Uint8 *stream, int len) noexcept mDevice->renderSamples(stream, ulen / mFrameSize, mDevice->channelsFromFmt()); } -void Sdl2Backend::open(const char *name) +void Sdl2Backend::open(std::string_view name) { SDL_AudioSpec want{}, have{}; @@ -109,16 +109,29 @@ void Sdl2Backend::open(const char *name) * necessarily the first in the list. */ SDL_AudioDeviceID devid; - if(!name || strcmp(name, defaultDeviceName) == 0) + if(name.empty() || name == defaultDeviceName) + { + name = defaultDeviceName; devid = SDL_OpenAudioDevice(nullptr, SDL_FALSE, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE); + } else { const size_t prefix_len = strlen(DEVNAME_PREFIX); - if(strncmp(name, DEVNAME_PREFIX, prefix_len) == 0) - devid = SDL_OpenAudioDevice(name+prefix_len, SDL_FALSE, &want, &have, + if(name.length() >= prefix_len && strncmp(name.data(), DEVNAME_PREFIX, prefix_len) == 0) + { + /* Copy the string_view to a string to ensure it's null terminated + * for this call. + */ + const std::string devname{name.substr(prefix_len)}; + devid = SDL_OpenAudioDevice(devname.c_str(), SDL_FALSE, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE); + } else - devid = SDL_OpenAudioDevice(name, SDL_FALSE, &want, &have, SDL_AUDIO_ALLOW_ANY_CHANGE); + { + const std::string devname{name}; + devid = SDL_OpenAudioDevice(devname.c_str(), SDL_FALSE, &want, &have, + SDL_AUDIO_ALLOW_ANY_CHANGE); + } } if(!devid) throw al::backend_exception{al::backend_error::NoDevice, "%s", SDL_GetError()}; @@ -160,7 +173,7 @@ void Sdl2Backend::open(const char *name) mFmtType = devtype; mUpdateSize = have.samples; - mDevice->DeviceName = name ? name : defaultDeviceName; + mDevice->DeviceName = name; } bool Sdl2Backend::reset() diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 8daa928c..d54c337b 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -57,7 +57,7 @@ struct SndioPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -112,13 +112,13 @@ int SndioPlayback::mixerProc() } -void SndioPlayback::open(const char *name) +void SndioPlayback::open(std::string_view name) { - if(!name) + if(name.empty()) name = sndio_device; - else if(strcmp(name, sndio_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != sndio_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; sio_hdl *sndHandle{sio_open(nullptr, SIO_PLAY, 0)}; if(!sndHandle) @@ -280,7 +280,7 @@ struct SndioCapture final : public BackendBase { int recordProc(); - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -382,13 +382,13 @@ int SndioCapture::recordProc() } -void SndioCapture::open(const char *name) +void SndioCapture::open(std::string_view name) { - if(!name) + if(name.empty()) name = sndio_device; - else if(strcmp(name, sndio_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != sndio_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; mSndHandle = sio_open(nullptr, SIO_REC, true); if(mSndHandle == nullptr) diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 15dcc98f..38f9db19 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -62,7 +62,7 @@ struct SolarisBackend final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -139,13 +139,13 @@ int SolarisBackend::mixerProc() } -void SolarisBackend::open(const char *name) +void SolarisBackend::open(std::string_view name) { - if(!name) + if(name.empty()) name = solaris_device; - else if(strcmp(name, solaris_device) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != solaris_device) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; int fd{::open(solaris_driver.c_str(), O_WRONLY)}; if(fd == -1) diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index dccbeba2..96c56fa8 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -868,7 +868,7 @@ constexpr char MessageStr[static_cast(MsgType::Count)][16]{ struct WasapiProxy { virtual ~WasapiProxy() = default; - virtual HRESULT openProxy(const char *name) = 0; + virtual HRESULT openProxy(std::string_view name) = 0; virtual void closeProxy() = 0; virtual HRESULT resetProxy() = 0; @@ -878,7 +878,7 @@ struct WasapiProxy { struct Msg { MsgType mType; WasapiProxy *mProxy; - const char *mParam; + std::string_view mParam; std::promise mPromise; explicit operator bool() const noexcept { return mType != MsgType::QuitThread; } @@ -889,7 +889,7 @@ struct WasapiProxy { static std::optional sDeviceHelper; - std::future pushMessage(MsgType type, const char *param=nullptr) + std::future pushMessage(MsgType type, std::string_view param={}) { std::promise promise; std::future future{promise.get_future()}; @@ -907,7 +907,7 @@ struct WasapiProxy { std::future future{promise.get_future()}; { std::lock_guard _{mMsgQueueLock}; - mMsgQueue.emplace_back(Msg{type, nullptr, nullptr, std::move(promise)}); + mMsgQueue.emplace_back(Msg{type, nullptr, {}, std::move(promise)}); } mMsgQueueCond.notify_one(); return future; @@ -958,9 +958,10 @@ int WasapiProxy::messageHandler(std::promise *promise) TRACE("Starting message loop\n"); while(Msg msg{popMessage()}) { - TRACE("Got message \"%s\" (0x%04x, this=%p, param=%p)\n", + TRACE("Got message \"%s\" (0x%04x, this=%p, param={%p,%zu})\n", MessageStr[static_cast(msg.mType)], static_cast(msg.mType), - static_cast(msg.mProxy), static_cast(msg.mParam)); + static_cast(msg.mProxy), static_cast(msg.mParam.data()), + msg.mParam.length()); switch(msg.mType) { @@ -1010,8 +1011,8 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { int mixerProc(); - void open(const char *name) override; - HRESULT openProxy(const char *name) override; + void open(std::string_view name) override; + HRESULT openProxy(std::string_view name) override; void closeProxy() override; bool reset() override; @@ -1147,7 +1148,7 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() } -void WasapiPlayback::open(const char *name) +void WasapiPlayback::open(std::string_view name) { if(SUCCEEDED(mOpenStatus)) throw al::backend_exception{al::backend_error::DeviceError, @@ -1161,11 +1162,10 @@ void WasapiPlayback::open(const char *name) "Failed to create notify events"}; } - if(name && std::strncmp(name, DevNameHead, DevNameHeadLen) == 0) + if(name.length() >= DevNameHeadLen + && std::strncmp(name.data(), DevNameHead, DevNameHeadLen) == 0) { - name += DevNameHeadLen; - if(*name == '\0') - name = nullptr; + name = name.substr(DevNameHeadLen); } mOpenStatus = pushMessage(MsgType::OpenDevice, name).get(); @@ -1174,11 +1174,11 @@ void WasapiPlayback::open(const char *name) mOpenStatus}; } -HRESULT WasapiPlayback::openProxy(const char *name) +HRESULT WasapiPlayback::openProxy(std::string_view name) { std::string devname; std::wstring devid; - if(name) + if(!name.empty()) { auto devlock = DeviceListLock{gDeviceList}; auto list = al::span{devlock.getPlaybackList()}; @@ -1194,7 +1194,8 @@ HRESULT WasapiPlayback::openProxy(const char *name) } if(iter == list.cend()) { - WARN("Failed to find device name matching \"%s\"\n", name); + WARN("Failed to find device name matching \"%.*s\"\n", static_cast(name.length()), + name.data()); return E_FAIL; } devname = iter->name; @@ -1654,8 +1655,8 @@ struct WasapiCapture final : public BackendBase, WasapiProxy { int recordProc(); - void open(const char *name) override; - HRESULT openProxy(const char *name) override; + void open(std::string_view name) override; + HRESULT openProxy(std::string_view name) override; void closeProxy() override; HRESULT resetProxy() override; @@ -1787,7 +1788,7 @@ FORCE_ALIGN int WasapiCapture::recordProc() } -void WasapiCapture::open(const char *name) +void WasapiCapture::open(std::string_view name) { if(SUCCEEDED(mOpenStatus)) throw al::backend_exception{al::backend_error::DeviceError, @@ -1801,11 +1802,10 @@ void WasapiCapture::open(const char *name) "Failed to create notify events"}; } - if(name && std::strncmp(name, DevNameHead, DevNameHeadLen) == 0) + if(name.length() >= DevNameHeadLen + && std::strncmp(name.data(), DevNameHead, DevNameHeadLen) == 0) { - name += DevNameHeadLen; - if(*name == '\0') - name = nullptr; + name = name.substr(DevNameHeadLen); } mOpenStatus = pushMessage(MsgType::OpenDevice, name).get(); @@ -1822,11 +1822,11 @@ void WasapiCapture::open(const char *name) } } -HRESULT WasapiCapture::openProxy(const char *name) +HRESULT WasapiCapture::openProxy(std::string_view name) { std::string devname; std::wstring devid; - if(name) + if(!name.empty()) { auto devlock = DeviceListLock{gDeviceList}; auto devlist = al::span{devlock.getCaptureList()}; @@ -1842,7 +1842,8 @@ HRESULT WasapiCapture::openProxy(const char *name) } if(iter == devlist.cend()) { - WARN("Failed to find device name matching \"%s\"\n", name); + WARN("Failed to find device name matching \"%.*s\"\n", static_cast(name.length()), + name.data()); return E_FAIL; } devname = iter->name; diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 40592ee7..1078c654 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -96,7 +96,7 @@ struct WaveBackend final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -194,24 +194,24 @@ int WaveBackend::mixerProc() return 0; } -void WaveBackend::open(const char *name) +void WaveBackend::open(std::string_view name) { auto fname = ConfigValueStr(nullptr, "wave", "file"); if(!fname) throw al::backend_exception{al::backend_error::NoDevice, "No wave output filename"}; - if(!name) + if(name.empty()) name = waveDevice; - else if(strcmp(name, waveDevice) != 0) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + else if(name != waveDevice) + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; /* There's only one "device", so if it's already open, we're done. */ if(mFile) return; #ifdef _WIN32 { - std::wstring wname{utf8_to_wstr(fname->c_str())}; + std::wstring wname{utf8_to_wstr(fname.value())}; mFile = _wfopen(wname.c_str(), L"wb"); } #else diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index c22f1c4d..f0fb0a1c 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -135,7 +135,7 @@ struct WinMMPlayback final : public BackendBase { int mixerProc(); - void open(const char *name) override; + void open(std::string_view name) override; bool reset() override; void start() override; void stop() override; @@ -208,18 +208,18 @@ FORCE_ALIGN int WinMMPlayback::mixerProc() } -void WinMMPlayback::open(const char *name) +void WinMMPlayback::open(std::string_view name) { if(PlaybackDevices.empty()) ProbePlaybackDevices(); // Find the Device ID matching the deviceName if valid - auto iter = name ? + auto iter = !name.empty() ? std::find(PlaybackDevices.cbegin(), PlaybackDevices.cend(), name) : PlaybackDevices.cbegin(); if(iter == PlaybackDevices.cend()) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; auto DeviceID = static_cast(std::distance(PlaybackDevices.cbegin(), iter)); DevFmtType fmttype{mDevice->FmtType}; @@ -370,7 +370,7 @@ struct WinMMCapture final : public BackendBase { int captureProc(); - void open(const char *name) override; + void open(std::string_view name) override; void start() override; void stop() override; void captureSamples(std::byte *buffer, uint samples) override; @@ -446,18 +446,18 @@ int WinMMCapture::captureProc() } -void WinMMCapture::open(const char *name) +void WinMMCapture::open(std::string_view name) { if(CaptureDevices.empty()) ProbeCaptureDevices(); // Find the Device ID matching the deviceName if valid - auto iter = name ? + auto iter = !name.empty() ? std::find(CaptureDevices.cbegin(), CaptureDevices.cend(), name) : CaptureDevices.cbegin(); if(iter == CaptureDevices.cend()) - throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%s\" not found", - name}; + throw al::backend_exception{al::backend_error::NoDevice, "Device name \"%.*s\" not found", + static_cast(name.length()), name.data()}; auto DeviceID = static_cast(std::distance(CaptureDevices.cbegin(), iter)); switch(mDevice->FmtChans) diff --git a/common/strutils.cpp b/common/strutils.cpp index 355cd030..f7868e2e 100644 --- a/common/strutils.cpp +++ b/common/strutils.cpp @@ -10,31 +10,32 @@ #define WIN32_LEAN_AND_MEAN #include -std::string wstr_to_utf8(const WCHAR *wstr) +std::string wstr_to_utf8(std::wstring_view wstr) { std::string ret; - int len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); + int len{WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.length()), nullptr, + 0, nullptr, nullptr)}; if(len > 0) { ret.resize(len); - WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &ret[0], len, nullptr, nullptr); - ret.pop_back(); + WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast(wstr.length()), &ret[0], len, + nullptr, nullptr); } return ret; } -std::wstring utf8_to_wstr(const char *str) +std::wstring utf8_to_wstr(std::string_view str) { std::wstring ret; - int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0); + int len{MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.length()), nullptr, + 0)}; if(len > 0) { ret.resize(len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len); - ret.pop_back(); + MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.length()), &ret[0], len); } return ret; diff --git a/common/strutils.h b/common/strutils.h index 67f057a7..7eee0c1d 100644 --- a/common/strutils.h +++ b/common/strutils.h @@ -5,10 +5,11 @@ #include #ifdef _WIN32 +#include #include -std::string wstr_to_utf8(const wchar_t *wstr); -std::wstring utf8_to_wstr(const char *str); +std::string wstr_to_utf8(std::wstring_view wstr); +std::wstring utf8_to_wstr(std::string_view str); #endif namespace al { -- cgit v1.2.3