diff options
-rw-r--r-- | Alc/alc.cpp | 82 | ||||
-rw-r--r-- | Alc/backends/alsa.cpp | 2 | ||||
-rw-r--r-- | Alc/backends/dsound.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/opensl.cpp | 2 | ||||
-rw-r--r-- | Alc/backends/pulseaudio.cpp | 4 | ||||
-rw-r--r-- | Alc/backends/wasapi.cpp | 4 | ||||
-rw-r--r-- | common/albyte.h | 32 |
7 files changed, 71 insertions, 59 deletions
diff --git a/Alc/alc.cpp b/Alc/alc.cpp index dfd4ef23..0724f0ce 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -1617,9 +1617,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) /* If a context is already running on the device, stop playback so * the device attributes can be updated. */ - if(device->Flags.get(DeviceRunning)) + if(device->Flags.get<DeviceRunning>()) device->Backend->stop(); - device->Flags.unset(DeviceRunning); + device->Flags.unset<DeviceRunning>(); } auto numMono = static_cast<ALsizei>(device->NumMonoSources); @@ -1734,9 +1734,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) } } - if(device->Flags.get(DeviceRunning)) + if(device->Flags.get<DeviceRunning>()) device->Backend->stop(); - device->Flags.unset(DeviceRunning); + device->Flags.unset<DeviceRunning>(); UpdateClockBase(device); @@ -1748,7 +1748,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) ConfigValueUInt(devname, nullptr, "frequency", &freq); if(freq < 1) - device->Flags.unset(FrequencyRequest); + device->Flags.unset<FrequencyRequest>(); else { freq = maxi(freq, MIN_OUTPUT_RATE); @@ -1759,7 +1759,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) device->Frequency; device->Frequency = freq; - device->Flags.set(FrequencyRequest); + device->Flags.set<FrequencyRequest>(); } ConfigValueUInt(devname, nullptr, "period_size", &device->UpdateSize); @@ -1807,7 +1807,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) new_sends = numSends; } - if(device->Flags.get(DeviceRunning)) + if(device->Flags.get<DeviceRunning>()) return ALC_NO_ERROR; device->Uhj_Encoder = nullptr; @@ -1862,7 +1862,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) { device->FmtChans = DevFmtStereo; device->Frequency = hrtf->sampleRate; - device->Flags.set(ChannelsRequest, FrequencyRequest); + device->Flags.set<ChannelsRequest, FrequencyRequest>(); if(HrtfEntry *oldhrtf{device->mHrtf}) oldhrtf->DecRef(); device->mHrtf = hrtf; @@ -1881,9 +1881,9 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) oldType = device->FmtType; TRACE("Pre-reset: %s%s, %s%s, %s%uhz, %u / %u buffer\n", - device->Flags.get(ChannelsRequest)?"*":"", DevFmtChannelsString(device->FmtChans), - device->Flags.get(SampleTypeRequest)?"*":"", DevFmtTypeString(device->FmtType), - device->Flags.get(FrequencyRequest)?"*":"", device->Frequency, + device->Flags.get<ChannelsRequest>()?"*":"", DevFmtChannelsString(device->FmtChans), + device->Flags.get<SampleTypeRequest>()?"*":"", DevFmtTypeString(device->FmtType), + device->Flags.get<FrequencyRequest>()?"*":"", device->Frequency, device->UpdateSize, device->BufferSize); try { @@ -1895,22 +1895,22 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) return ALC_INVALID_DEVICE; } - if(device->FmtChans != oldChans && device->Flags.get(ChannelsRequest)) + if(device->FmtChans != oldChans && device->Flags.get<ChannelsRequest>()) { ERR("Failed to set %s, got %s instead\n", DevFmtChannelsString(oldChans), DevFmtChannelsString(device->FmtChans)); - device->Flags.unset(ChannelsRequest); + device->Flags.unset<ChannelsRequest>(); } - if(device->FmtType != oldType && device->Flags.get(SampleTypeRequest)) + if(device->FmtType != oldType && device->Flags.get<SampleTypeRequest>()) { ERR("Failed to set %s, got %s instead\n", DevFmtTypeString(oldType), DevFmtTypeString(device->FmtType)); - device->Flags.unset(SampleTypeRequest); + device->Flags.unset<SampleTypeRequest>(); } - if(device->Frequency != oldFreq && device->Flags.get(FrequencyRequest)) + if(device->Frequency != oldFreq && device->Flags.get<FrequencyRequest>()) { ERR("Failed to set %uhz, got %uhz instead\n", oldFreq, device->Frequency); - device->Flags.unset(FrequencyRequest); + device->Flags.unset<FrequencyRequest>(); } if((device->UpdateSize&3) != 0) @@ -2181,11 +2181,11 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) if(update_failed) return ALC_INVALID_DEVICE; - if(!device->Flags.get(DevicePaused)) + if(!device->Flags.get<DevicePaused>()) { if(device->Backend->start() == ALC_FALSE) return ALC_INVALID_DEVICE; - device->Flags.set(DeviceRunning); + device->Flags.set<DeviceRunning>(); } return ALC_NO_ERROR; @@ -3525,10 +3525,10 @@ START_API_FUNC if(ALCdevice *Device{ctx->Device}) { std::lock_guard<std::mutex> _{Device->StateLock}; - if(!ReleaseContext(ctx.get(), Device) && Device->Flags.get(DeviceRunning)) + if(!ReleaseContext(ctx.get(), Device) && Device->Flags.get<DeviceRunning>()) { Device->Backend->stop(); - Device->Flags.unset(DeviceRunning); + Device->Flags.unset<DeviceRunning>(); } } listlock.unlock(); @@ -3731,7 +3731,7 @@ START_API_FUNC { device->FmtChans = iter->chans; device->mAmbiOrder = iter->order; - device->Flags.set(ChannelsRequest); + device->Flags.set<ChannelsRequest>(); } } if(ConfigValueStr(deviceName, nullptr, "sample-type", &fmt)) @@ -3758,7 +3758,7 @@ START_API_FUNC else { device->FmtType = iter->type; - device->Flags.set(SampleTypeRequest); + device->Flags.set<SampleTypeRequest>(); } } @@ -3773,7 +3773,7 @@ START_API_FUNC device->UpdateSize = (device->UpdateSize*freq + device->Frequency/2) / device->Frequency; device->BufferSize = (device->BufferSize*freq + device->Frequency/2) / device->Frequency; device->Frequency = freq; - device->Flags.set(FrequencyRequest); + device->Flags.set<FrequencyRequest>(); } ConfigValueUInt(deviceName, nullptr, "period_size", &device->UpdateSize); @@ -3887,9 +3887,9 @@ START_API_FUNC ReleaseContext(ctx, device); ctx = next; } - if(device->Flags.get(DeviceRunning)) + if(device->Flags.get<DeviceRunning>()) device->Backend->stop(); - device->Flags.unset(DeviceRunning); + device->Flags.unset<DeviceRunning>(); statelock.unlock(); ALCdevice_DecRef(device); @@ -3930,7 +3930,7 @@ START_API_FUNC alcSetError(nullptr, ALC_INVALID_ENUM); return nullptr; } - device->Flags.set(FrequencyRequest, ChannelsRequest, SampleTypeRequest); + device->Flags.set<FrequencyRequest, ChannelsRequest, SampleTypeRequest>(); device->UpdateSize = samples; device->BufferSize = samples; @@ -3987,9 +3987,9 @@ START_API_FUNC listlock.unlock(); { std::lock_guard<std::mutex> _{device->StateLock}; - if(device->Flags.get(DeviceRunning)) + if(device->Flags.get<DeviceRunning>()) device->Backend->stop(); - device->Flags.unset(DeviceRunning); + device->Flags.unset<DeviceRunning>(); } ALCdevice_DecRef(device); @@ -4011,10 +4011,10 @@ START_API_FUNC std::lock_guard<std::mutex> _{dev->StateLock}; if(!dev->Connected.load(std::memory_order_acquire)) alcSetError(dev.get(), ALC_INVALID_DEVICE); - else if(!dev->Flags.get(DeviceRunning)) + else if(!dev->Flags.get<DeviceRunning>()) { if(dev->Backend->start()) - dev->Flags.set(DeviceRunning); + dev->Flags.set<DeviceRunning>(); else { aluHandleDisconnect(dev.get(), "Device start failure"); @@ -4033,9 +4033,9 @@ START_API_FUNC else { std::lock_guard<std::mutex> _{dev->StateLock}; - if(dev->Flags.get(DeviceRunning)) + if(dev->Flags.get<DeviceRunning>()) dev->Backend->stop(); - dev->Flags.unset(DeviceRunning); + dev->Flags.unset<DeviceRunning>(); } } END_API_FUNC @@ -4197,10 +4197,10 @@ START_API_FUNC else { std::lock_guard<std::mutex> _{dev->StateLock}; - if(dev->Flags.get(DeviceRunning)) + if(dev->Flags.get<DeviceRunning>()) dev->Backend->stop(); - dev->Flags.unset(DeviceRunning); - dev->Flags.set(DevicePaused); + dev->Flags.unset<DeviceRunning>(); + dev->Flags.set<DevicePaused>(); } } END_API_FUNC @@ -4220,9 +4220,9 @@ START_API_FUNC } std::lock_guard<std::mutex> _{dev->StateLock}; - if(!dev->Flags.get(DevicePaused)) + if(!dev->Flags.get<DevicePaused>()) return; - dev->Flags.unset(DevicePaused); + dev->Flags.unset<DevicePaused>(); if(dev->ContextList.load() == nullptr) return; @@ -4232,7 +4232,7 @@ START_API_FUNC alcSetError(dev.get(), ALC_INVALID_DEVICE); return; } - dev->Flags.set(DeviceRunning); + dev->Flags.set<DeviceRunning>(); } END_API_FUNC @@ -4289,9 +4289,9 @@ START_API_FUNC /* Force the backend to stop mixing first since we're resetting. Also reset * the connected state so lost devices can attempt recover. */ - if(dev->Flags.get(DeviceRunning)) + if(dev->Flags.get<DeviceRunning>()) dev->Backend->stop(); - dev->Flags.unset(DeviceRunning); + dev->Flags.unset<DeviceRunning>(); device->Connected.store(true); ALCenum err{UpdateDeviceParams(dev.get(), attribs)}; diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index 1c0d7489..ebdc6129 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -725,7 +725,7 @@ ALCboolean AlsaPlayback::reset() CHECK(snd_pcm_hw_params_set_channels(mPcmHandle, hp, mDevice->channelsFromFmt())); /* set rate (implicitly constrains period/buffer parameters) */ if(!GetConfigValueBool(mDevice->DeviceName.c_str(), "alsa", "allow-resampler", 0) || - !mDevice->Flags.get(FrequencyRequest)) + !mDevice->Flags.get<FrequencyRequest>()) { if(snd_pcm_hw_params_set_rate_resample(mPcmHandle, hp, 0) < 0) ERR("Failed to disable ALSA resampler\n"); diff --git a/Alc/backends/dsound.cpp b/Alc/backends/dsound.cpp index 480d9a18..93de3135 100644 --- a/Alc/backends/dsound.cpp +++ b/Alc/backends/dsound.cpp @@ -359,7 +359,7 @@ ALCboolean DSoundPlayback::reset() mDevice->FmtType = DevFmtUByte; break; case DevFmtFloat: - if(mDevice->Flags.get(SampleTypeRequest)) + if(mDevice->Flags.get<SampleTypeRequest>()) break; /* fall-through */ case DevFmtUShort: @@ -380,7 +380,7 @@ ALCboolean DSoundPlayback::reset() if(SUCCEEDED(hr)) { speakers = DSSPEAKER_CONFIG(speakers); - if(!mDevice->Flags.get(ChannelsRequest)) + if(!mDevice->Flags.get<ChannelsRequest>()) { if(speakers == DSSPEAKER_MONO) mDevice->FmtChans = DevFmtMono; diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 37495abe..be483338 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -361,7 +361,7 @@ ALCboolean OpenSLPlayback::reset() mRing = nullptr; #if 0 - if(!mDevice->Flags.get(FrequencyRequest)) + if(!mDevice->Flags.get<FrequencyRequest>()) { /* FIXME: Disabled until I figure out how to get the Context needed for * the getSystemService call. diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index 0b7257d1..6d4f387c 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -779,7 +779,7 @@ void PulsePlayback::sinkInfoCallback(pa_context* UNUSED(context), const pa_sink_ ); if(chanmap != chanmaps.cend()) { - if(!mDevice->Flags.get(ChannelsRequest)) + if(!mDevice->Flags.get<ChannelsRequest>()) mDevice->FmtChans = chanmap->chans; } else @@ -910,7 +910,7 @@ ALCboolean PulsePlayback::reset() flags |= PA_STREAM_ADJUST_LATENCY; } if(GetConfigValueBool(mDevice->DeviceName.c_str(), "pulse", "fix-rate", 0) || - !mDevice->Flags.get(FrequencyRequest)) + !mDevice->Flags.get<FrequencyRequest>()) flags |= PA_STREAM_FIX_RATE; pa_channel_map chanmap{}; diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index 6c3dc6e6..84e85fe6 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -787,9 +787,9 @@ HRESULT WasapiPlayback::resetProxy() const REFERENCE_TIME per_time{mDevice->UpdateSize * REFTIME_PER_SEC / mDevice->Frequency}; const REFERENCE_TIME buf_time{mDevice->BufferSize * REFTIME_PER_SEC / mDevice->Frequency}; - if(!mDevice->Flags.get(FrequencyRequest)) + if(!mDevice->Flags.get<FrequencyRequest>()) mDevice->Frequency = OutputType.Format.nSamplesPerSec; - if(!mDevice->Flags.get(ChannelsRequest)) + if(!mDevice->Flags.get<ChannelsRequest>()) { if(OutputType.Format.nChannels == 1 && OutputType.dwChannelMask == MONO) mDevice->FmtChans = DevFmtMono; diff --git a/common/albyte.h b/common/albyte.h index 8257560e..f95b92d7 100644 --- a/common/albyte.h +++ b/common/albyte.h @@ -73,18 +73,30 @@ class bitfield { byte vals[NumElems]{}; public: - void set(size_t b) noexcept { vals[b/bits_per_byte] |= 1 << (b%bits_per_byte); } - void unset(size_t b) noexcept { vals[b/bits_per_byte] &= ~(1 << (b%bits_per_byte)); } - bool get(size_t b) const noexcept - { return (vals[b/bits_per_byte] & (1 << (b%bits_per_byte))) != byte{}; } + template<size_t b> + inline void set() noexcept + { + static_assert(b < N, "Bit index out of range"); + vals[b/bits_per_byte] |= 1 << (b%bits_per_byte); + } + template<size_t b> + inline void unset() noexcept + { + static_assert(b < N, "Bit index out of range"); + vals[b/bits_per_byte] &= ~(1 << (b%bits_per_byte)); + } + template<size_t b> + inline bool get() const noexcept + { + static_assert(b < N, "Bit index out of range"); + return (vals[b/bits_per_byte] & (1 << (b%bits_per_byte))) != byte{}; + } - template<typename ...Args, REQUIRES(sizeof...(Args) > 0)> - void set(size_t b, Args ...args) noexcept + template<size_t b, size_t ...args, REQUIRES(sizeof...(args) > 0)> + void set() noexcept { - set(b); - /* Trick for calling set() on each element of the parameter pack. */ - using CharArray = char[sizeof...(Args)]; - (void)(CharArray{ (set(args),'\0')... }); + set<b>(); + set<args...>(); } }; |