diff options
author | Chris Robinson <[email protected]> | 2023-12-11 18:59:54 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-12-11 18:59:54 -0800 |
commit | 60aa22f20d63a3da9f06b9398a2a8656ebbd0342 (patch) | |
tree | c6067ff97fd013906309d2fafd5e41a5447fee29 /alc/backends | |
parent | e79e5a978df22a5e5967169cf62cf46f3456d833 (diff) |
Mostly finish cleanup for backends
Except CoreAudio and Solaris backends
Diffstat (limited to 'alc/backends')
-rw-r--r-- | alc/backends/alsa.cpp | 20 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 4 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 3 | ||||
-rw-r--r-- | alc/backends/oboe.cpp | 8 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 3 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 4 | ||||
-rw-r--r-- | alc/backends/pulseaudio.cpp | 29 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 21 | ||||
-rw-r--r-- | alc/backends/solaris.cpp | 16 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 48 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 35 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 8 |
12 files changed, 110 insertions, 89 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 47c6385e..fa34e4f9 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -53,6 +53,7 @@ namespace { +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char alsaDevice[] = "ALSA Default"; @@ -715,17 +716,18 @@ bool AlsaPlayback::reset() /* test and set format (implicitly sets sample bits) */ if(snd_pcm_hw_params_test_format(mPcmHandle, hp.get(), format) < 0) { - static const struct { + struct FormatMap { snd_pcm_format_t format; DevFmtType fmttype; - } formatlist[] = { - { SND_PCM_FORMAT_FLOAT, DevFmtFloat }, - { SND_PCM_FORMAT_S32, DevFmtInt }, - { SND_PCM_FORMAT_U32, DevFmtUInt }, - { SND_PCM_FORMAT_S16, DevFmtShort }, - { SND_PCM_FORMAT_U16, DevFmtUShort }, - { SND_PCM_FORMAT_S8, DevFmtByte }, - { SND_PCM_FORMAT_U8, DevFmtUByte }, + }; + static constexpr std::array formatlist{ + FormatMap{SND_PCM_FORMAT_FLOAT, DevFmtFloat }, + FormatMap{SND_PCM_FORMAT_S32, DevFmtInt }, + FormatMap{SND_PCM_FORMAT_U32, DevFmtUInt }, + FormatMap{SND_PCM_FORMAT_S16, DevFmtShort }, + FormatMap{SND_PCM_FORMAT_U16, DevFmtUShort}, + FormatMap{SND_PCM_FORMAT_S8, DevFmtByte }, + FormatMap{SND_PCM_FORMAT_U8, DevFmtUByte }, }; for(const auto &fmt : formatlist) diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 12196f74..08c849e9 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -35,11 +35,11 @@ #include <algorithm> #include <atomic> #include <cassert> +#include <cstdio> +#include <cstdlib> #include <functional> #include <memory.h> #include <mutex> -#include <stdlib.h> -#include <stdio.h> #include <string> #include <thread> #include <vector> diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index ca862276..1a53da17 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -102,6 +102,7 @@ decltype(jack_error_callback) * pjack_error_callback; #endif +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char JackDefaultAudioType[] = JACK_DEFAULT_AUDIO_TYPE; jack_options_t ClientOptions = JackNullOption; @@ -158,7 +159,7 @@ bool jack_load() struct JackDeleter { void operator()(void *ptr) { jack_free(ptr); } }; -using JackPortsPtr = std::unique_ptr<const char*[],JackDeleter>; +using JackPortsPtr = std::unique_ptr<const char*[],JackDeleter>; /* NOLINT(*-avoid-c-arrays) */ struct DeviceEntry { std::string mName; diff --git a/alc/backends/oboe.cpp b/alc/backends/oboe.cpp index 9666063a..1076bc8d 100644 --- a/alc/backends/oboe.cpp +++ b/alc/backends/oboe.cpp @@ -4,8 +4,8 @@ #include "oboe.h" #include <cassert> +#include <cstdint> #include <cstring> -#include <stdint.h> #include "alnumeric.h" #include "core/device.h" @@ -17,6 +17,7 @@ namespace { +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char device_name[] = "Oboe Default"; @@ -48,11 +49,10 @@ oboe::DataCallbackResult OboePlayback::onAudioReady(oboe::AudioStream *oboeStrea return oboe::DataCallbackResult::Continue; } -void OboePlayback::onErrorAfterClose(oboe::AudioStream* audioStream, oboe::Result error) +void OboePlayback::onErrorAfterClose(oboe::AudioStream*, oboe::Result error) { - if (error == oboe::Result::ErrorDisconnected) { + if(error == oboe::Result::ErrorDisconnected) mDevice->handleDisconnect("Oboe AudioStream was disconnected: %s", oboe::convertToText(error)); - } TRACE("Error was %s", oboe::convertToText(error)); } diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 3d99e93f..75b6e30d 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -23,10 +23,10 @@ #include "opensl.h" -#include <stdlib.h> #include <jni.h> #include <array> +#include <cstdlib> #include <cstring> #include <mutex> #include <new> @@ -56,6 +56,7 @@ namespace { #define VCALL0(obj, func) ((*(obj))->func((obj) EXTRACT_VCALL_ARGS +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char opensl_device[] = "OpenSL"; diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index 010b0749..e6cebec4 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -79,7 +79,9 @@ namespace { +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char DefaultName[] = "OSS Default"; + std::string DefaultPlayback{"/dev/dsp"}; std::string DefaultCapture{"/dev/dsp"}; @@ -379,7 +381,7 @@ bool OSSPlayback::reset() CHECKERR(ioctl(mFd, SNDCTL_DSP_CHANNELS, &numChannels)); CHECKERR(ioctl(mFd, SNDCTL_DSP_SPEED, &ossSpeed)); CHECKERR(ioctl(mFd, SNDCTL_DSP_GETOSPACE, &info)); - if(0) + if(false) { err: ERR("%s failed: %s\n", err, strerror(errno)); diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 2f0e7a84..b6f0f95d 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -28,12 +28,12 @@ #include <atomic> #include <bitset> #include <chrono> +#include <cstdint> +#include <cstdlib> #include <cstring> #include <limits> #include <mutex> #include <optional> -#include <stdint.h> -#include <stdlib.h> #include <string> #include <sys/types.h> #include <utility> @@ -320,11 +320,12 @@ public: explicit operator bool() const noexcept { return mLoop != nullptr; } + [[nodiscard]] auto start() const { return pa_threaded_mainloop_start(mLoop); } auto stop() const { return pa_threaded_mainloop_stop(mLoop); } - auto getApi() const { return pa_threaded_mainloop_get_api(mLoop); } - auto getContext() const noexcept { return mContext; } + [[nodiscard]] auto getApi() const { return pa_threaded_mainloop_get_api(mLoop); } + [[nodiscard]] auto getContext() const noexcept { return mContext; } auto lock() const { return pa_threaded_mainloop_lock(mLoop); } auto unlock() const { return pa_threaded_mainloop_unlock(mLoop); } @@ -753,9 +754,9 @@ void PulsePlayback::sinkInfoCallback(pa_context*, const pa_sink_info *info, int else { mIs51Rear = false; - char chanmap_str[PA_CHANNEL_MAP_SNPRINT_MAX]{}; - pa_channel_map_snprint(chanmap_str, sizeof(chanmap_str), &info->channel_map); - WARN("Failed to find format for channel map:\n %s\n", chanmap_str); + std::array<char,PA_CHANNEL_MAP_SNPRINT_MAX> chanmap_str{}; + pa_channel_map_snprint(chanmap_str.data(), chanmap_str.size(), &info->channel_map); + WARN("Failed to find format for channel map:\n %s\n", chanmap_str.data()); } if(info->active_port) @@ -784,7 +785,9 @@ void PulsePlayback::streamMovedCallback(pa_stream *stream) noexcept void PulsePlayback::open(std::string_view name) { mMainloop = PulseMainloop::Create(); - mMainloop.start(); + if(mMainloop.start() != 0) + throw al::backend_exception{al::backend_error::DeviceError, + "Failed to start device mainloop"}; const char *pulse_name{nullptr}; const char *dev_name{nullptr}; @@ -1127,7 +1130,9 @@ void PulseCapture::open(std::string_view name) if(!mMainloop) { mMainloop = PulseMainloop::Create(); - mMainloop.start(); + if(mMainloop.start() != 0) + throw al::backend_exception{al::backend_error::DeviceError, + "Failed to start device mainloop"}; } const char *pulse_name{nullptr}; @@ -1432,7 +1437,11 @@ bool PulseBackendFactory::init() if(!gGlobalMainloop) { gGlobalMainloop = PulseMainloop::Create(); - gGlobalMainloop.start(); + if(gGlobalMainloop.start() != 0) + { + gGlobalMainloop = nullptr; + return false; + } } MainloopUniqueLock plock{gGlobalMainloop}; diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 8bf63a59..d05db2e8 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -23,11 +23,11 @@ #include "sndio.h" #include <cinttypes> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <functional> #include <poll.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <thread> #include <vector> @@ -43,7 +43,8 @@ namespace { -static const char sndio_device[] = "SndIO Default"; +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ +constexpr char sndio_device[] = "SndIO Default"; struct SioPar : public sio_par { SioPar() { sio_initpar(this); } @@ -317,19 +318,19 @@ int SndioCapture::recordProc() return 1; } - auto fds = std::make_unique<pollfd[]>(static_cast<uint>(nfds_pre)); + auto fds = std::vector<pollfd>(static_cast<uint>(nfds_pre)); while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) { /* Wait until there's some samples to read. */ - const int nfds{sio_pollfd(mSndHandle, fds.get(), POLLIN)}; + const int nfds{sio_pollfd(mSndHandle, fds.data(), POLLIN)}; if(nfds <= 0) { mDevice->handleDisconnect("Failed to get polling fds: %d", nfds); break; } - int pollres{::poll(fds.get(), static_cast<uint>(nfds), 2000)}; + int pollres{::poll(fds.data(), fds.size(), 2000)}; if(pollres < 0) { if(errno == EINTR) continue; @@ -339,7 +340,7 @@ int SndioCapture::recordProc() if(pollres == 0) continue; - const int revents{sio_revents(mSndHandle, fds.get())}; + const int revents{sio_revents(mSndHandle, fds.data())}; if((revents&POLLHUP)) { mDevice->handleDisconnect("Got POLLHUP from poll events"); @@ -373,8 +374,8 @@ int SndioCapture::recordProc() if(buffer.empty()) { /* Got samples to read, but no place to store it. Drop it. */ - static char junk[4096]; - sio_read(mSndHandle, junk, sizeof(junk) - (sizeof(junk)%frameSize)); + static std::array<char,4096> junk; + sio_read(mSndHandle, junk.data(), junk.size() - (junk.size()%frameSize)); } } diff --git a/alc/backends/solaris.cpp b/alc/backends/solaris.cpp index 38f9db19..2c4a97fd 100644 --- a/alc/backends/solaris.cpp +++ b/alc/backends/solaris.cpp @@ -51,6 +51,7 @@ namespace { +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char solaris_device[] = "Solaris Default"; std::string solaris_driver{"/dev/audio"}; @@ -91,7 +92,7 @@ int SolarisBackend::mixerProc() althrd_setname(MIXER_THREAD_NAME); const size_t frame_step{mDevice->channelsFromFmt()}; - const uint frame_size{mDevice->frameSizeFromFmt()}; + const size_t frame_size{mDevice->frameSizeFromFmt()}; while(!mKillNow.load(std::memory_order_acquire) && mDevice->Connected.load(std::memory_order_acquire)) @@ -115,12 +116,12 @@ int SolarisBackend::mixerProc() continue; } - std::byte *write_ptr{mBuffer.data()}; - size_t to_write{mBuffer.size()}; - mDevice->renderSamples(write_ptr, static_cast<uint>(to_write/frame_size), frame_step); - while(to_write > 0 && !mKillNow.load(std::memory_order_acquire)) + al::span<std::byte> buffer{mBuffer}; + mDevice->renderSamples(buffer.data(), static_cast<uint>(buffer.size()/frame_size), + frame_step); + while(!buffer.empty() && !mKillNow.load(std::memory_order_acquire)) { - ssize_t wrote{write(mFd, write_ptr, to_write)}; + ssize_t wrote{write(mFd, buffer.data(), buffer.size())}; if(wrote < 0) { if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) @@ -130,8 +131,7 @@ int SolarisBackend::mixerProc() break; } - to_write -= static_cast<size_t>(wrote); - write_ptr += wrote; + buffer = buffer.subspan(static_cast<size_t>(wrote)); } } diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 139fa696..3e9632e0 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -25,8 +25,8 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> -#include <stdlib.h> -#include <stdio.h> +#include <cstdio> +#include <cstdlib> #include <memory.h> #include <wtypes.h> @@ -171,7 +171,7 @@ constexpr AudioObjectType ChannelMask_X714{AudioObjectType_FrontLeft | AudioObje | AudioObjectType_TopFrontLeft | AudioObjectType_TopFrontRight | AudioObjectType_TopBackLeft | AudioObjectType_TopBackRight}; - +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char DevNameHead[] = "OpenAL Soft on "; constexpr size_t DevNameHeadLen{std::size(DevNameHead) - 1}; @@ -201,16 +201,16 @@ constexpr uint RefTime2Samples(const ReferenceTime &val, T srate) noexcept class GuidPrinter { - char mMsg[64]; + std::array<char,64> mMsg; public: GuidPrinter(const GUID &guid) { - std::snprintf(mMsg, std::size(mMsg), "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + std::snprintf(mMsg.data(), mMsg.size(), "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", DWORD{guid.Data1}, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); } - const char *c_str() const { return mMsg; } + [[nodiscard]] auto c_str() const -> const char* { return mMsg.data(); } }; struct PropVariant { @@ -270,13 +270,13 @@ private: struct DeviceListLock : public std::unique_lock<DeviceList> { using std::unique_lock<DeviceList>::unique_lock; - auto& getPlaybackList() const noexcept { return mutex()->mPlayback; } - auto& getCaptureList() const noexcept { return mutex()->mCapture; } + [[nodiscard]] auto& getPlaybackList() const noexcept { return mutex()->mPlayback; } + [[nodiscard]] auto& getCaptureList() const noexcept { return mutex()->mCapture; } void setPlaybackDefaultId(std::wstring_view devid) const { mutex()->mPlaybackDefaultId = devid; } - std::wstring_view getPlaybackDefaultId() const noexcept { return mutex()->mPlaybackDefaultId; } + [[nodiscard]] auto getPlaybackDefaultId() const noexcept -> std::wstring_view { return mutex()->mPlaybackDefaultId; } void setCaptureDefaultId(std::wstring_view devid) const { mutex()->mCaptureDefaultId = devid; } - std::wstring_view getCaptureDefaultId() const noexcept { return mutex()->mCaptureDefaultId; } + [[nodiscard]] auto getCaptureDefaultId() const noexcept -> std::wstring_view { return mutex()->mCaptureDefaultId; } }; DeviceList gDeviceList; @@ -302,8 +302,10 @@ using DeviceHandle = ComPtr<IMMDevice>; using NameGUIDPair = std::pair<std::string,std::string>; static NameGUIDPair GetDeviceNameAndGuid(const DeviceHandle &device) { + /* NOLINTBEGIN(*-avoid-c-arrays) */ static constexpr char UnknownName[]{"Unknown Device Name"}; static constexpr char UnknownGuid[]{"Unknown Device GUID"}; + /* NOLINTEND(*-avoid-c-arrays) */ #if !defined(ALSOFT_UWP) std::string name, guid; @@ -384,9 +386,9 @@ struct DeviceHelper final : public IActivateAudioInterfaceCompletionHandler struct DeviceHelper final : private IMMNotificationClient #endif { +#if defined(ALSOFT_UWP) DeviceHelper() { -#if defined(ALSOFT_UWP) /* TODO: UWP also needs to watch for device added/removed events and * dynamically add/remove devices from the lists. */ @@ -411,8 +413,10 @@ struct DeviceHelper final : private IMMNotificationClient msg); } }); -#endif } +#else + DeviceHelper() = default; +#endif ~DeviceHelper() { #if defined(ALSOFT_UWP) @@ -1071,7 +1075,7 @@ struct WasapiPlayback final : public BackendBase, WasapiProxy { HANDLE mNotifyEvent{nullptr}; UINT32 mOrigBufferSize{}, mOrigUpdateSize{}; - std::unique_ptr<char[]> mResampleBuffer{}; + std::vector<char> mResampleBuffer{}; uint mBufferFilled{0}; SampleConverterPtr mResampler; @@ -1151,9 +1155,9 @@ FORCE_ALIGN int WasapiPlayback::mixerProc() { if(mBufferFilled == 0) { - mDevice->renderSamples(mResampleBuffer.get(), mDevice->UpdateSize, + mDevice->renderSamples(mResampleBuffer.data(), mDevice->UpdateSize, mFormat.Format.nChannels); - resbufferptr = mResampleBuffer.get(); + resbufferptr = mResampleBuffer.data(); mBufferFilled = mDevice->UpdateSize; } @@ -1249,7 +1253,7 @@ FORCE_ALIGN int WasapiPlayback::mixerSpatialProc() tmpbuffers.resize(buffers.size()); resbuffers.resize(buffers.size()); for(size_t i{0};i < tmpbuffers.size();++i) - resbuffers[i] = reinterpret_cast<float*>(mResampleBuffer.get()) + + resbuffers[i] = reinterpret_cast<float*>(mResampleBuffer.data()) + mDevice->UpdateSize*i; } } @@ -1819,7 +1823,8 @@ HRESULT WasapiPlayback::resetProxy() mDevice->BufferSize = mDevice->UpdateSize*2; mResampler = nullptr; - mResampleBuffer = nullptr; + mResampleBuffer.clear(); + mResampleBuffer.shrink_to_fit(); mBufferFilled = 0; if(mDevice->Frequency != mFormat.Format.nSamplesPerSec) { @@ -1828,7 +1833,7 @@ HRESULT WasapiPlayback::resetProxy() mResampler = SampleConverter::Create(mDevice->FmtType, mDevice->FmtType, channelCount, mDevice->Frequency, mFormat.Format.nSamplesPerSec, Resampler::FastBSinc24); - mResampleBuffer = std::make_unique<char[]>(size_t{mDevice->UpdateSize} * channelCount * + mResampleBuffer.resize(size_t{mDevice->UpdateSize} * channelCount * mFormat.Format.wBitsPerSample / 8); TRACE("Created converter for %s/%s format, dst: %luhz (%u), src: %uhz (%u)\n", @@ -1950,15 +1955,16 @@ no_spatial: mDevice->BufferSize/2); mResampler = nullptr; - mResampleBuffer = nullptr; + mResampleBuffer.clear(); + mResampleBuffer.shrink_to_fit(); mBufferFilled = 0; if(mDevice->Frequency != mFormat.Format.nSamplesPerSec) { mResampler = SampleConverter::Create(mDevice->FmtType, mDevice->FmtType, mFormat.Format.nChannels, mDevice->Frequency, mFormat.Format.nSamplesPerSec, Resampler::FastBSinc24); - mResampleBuffer = std::make_unique<char[]>(size_t{mDevice->UpdateSize} * - mFormat.Format.nChannels * mFormat.Format.wBitsPerSample / 8); + mResampleBuffer.resize(size_t{mDevice->UpdateSize} * mFormat.Format.nChannels * + mFormat.Format.wBitsPerSample / 8); TRACE("Created converter for %s/%s format, dst: %luhz (%u), src: %uhz (%u)\n", DevFmtChannelsString(mDevice->FmtChans), DevFmtTypeString(mDevice->FmtType), diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 794d5cb8..f3261ed4 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -55,38 +55,39 @@ using std::chrono::nanoseconds; using ubyte = unsigned char; using ushort = unsigned short; +/* NOLINTNEXTLINE(*-avoid-c-arrays) */ constexpr char waveDevice[] = "Wave File Writer"; -constexpr ubyte SUBTYPE_PCM[]{ +constexpr std::array<ubyte,16> SUBTYPE_PCM{{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 -}; -constexpr ubyte SUBTYPE_FLOAT[]{ +}}; +constexpr std::array<ubyte,16> SUBTYPE_FLOAT{{ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 -}; +}}; -constexpr ubyte SUBTYPE_BFORMAT_PCM[]{ +constexpr std::array<ubyte,16> SUBTYPE_BFORMAT_PCM{{ 0x01, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11, 0x86, 0x44, 0xc8, 0xc1, 0xca, 0x00, 0x00, 0x00 -}; +}}; -constexpr ubyte SUBTYPE_BFORMAT_FLOAT[]{ +constexpr std::array<ubyte,16> SUBTYPE_BFORMAT_FLOAT{{ 0x03, 0x00, 0x00, 0x00, 0x21, 0x07, 0xd3, 0x11, 0x86, 0x44, 0xc8, 0xc1, 0xca, 0x00, 0x00, 0x00 -}; +}}; void fwrite16le(ushort val, FILE *f) { - ubyte data[2]{ static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff) }; - fwrite(data, 1, 2, f); + std::array data{static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff)}; + fwrite(data.data(), 1, data.size(), f); } void fwrite32le(uint val, FILE *f) { - ubyte data[4]{ static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff), - static_cast<ubyte>((val>>16)&0xff), static_cast<ubyte>((val>>24)&0xff) }; - fwrite(data, 1, 4, f); + std::array data{static_cast<ubyte>(val&0xff), static_cast<ubyte>((val>>8)&0xff), + static_cast<ubyte>((val>>16)&0xff), static_cast<ubyte>((val>>24)&0xff)}; + fwrite(data.data(), 1, data.size(), f); } @@ -228,7 +229,6 @@ bool WaveBackend::reset() { uint channels{0}, bytes{0}, chanmask{0}; bool isbformat{false}; - size_t val; fseek(mFile, 0, SEEK_SET); clearerr(mFile); @@ -311,10 +311,9 @@ bool WaveBackend::reset() // 32-bit val, channel mask fwrite32le(chanmask, mFile); // 16 byte GUID, sub-type format - val = fwrite((mDevice->FmtType == DevFmtFloat) ? - (isbformat ? SUBTYPE_BFORMAT_FLOAT : SUBTYPE_FLOAT) : - (isbformat ? SUBTYPE_BFORMAT_PCM : SUBTYPE_PCM), 1, 16, mFile); - (void)val; + std::ignore = fwrite((mDevice->FmtType == DevFmtFloat) ? + (isbformat ? SUBTYPE_BFORMAT_FLOAT.data() : SUBTYPE_FLOAT.data()) : + (isbformat ? SUBTYPE_BFORMAT_PCM.data() : SUBTYPE_PCM.data()), 1, 16, mFile); fputs("data", mFile); fwrite32le(0xFFFFFFFF, mFile); // 'data' header len; filled in at close diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 15776d17..696f7f37 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -22,8 +22,8 @@ #include "winmm.h" -#include <stdlib.h> -#include <stdio.h> +#include <cstdlib> +#include <cstdio> #include <memory.h> #include <windows.h> @@ -62,7 +62,7 @@ std::vector<std::string> CaptureDevices; bool checkName(const std::vector<std::string> &list, const std::string &name) { return std::find(list.cbegin(), list.cend(), name) != list.cend(); } -void ProbePlaybackDevices(void) +void ProbePlaybackDevices() { PlaybackDevices.clear(); @@ -93,7 +93,7 @@ void ProbePlaybackDevices(void) } } -void ProbeCaptureDevices(void) +void ProbeCaptureDevices() { CaptureDevices.clear(); |