diff options
author | Chris Robinson <[email protected]> | 2022-02-22 03:03:44 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-02-22 03:03:44 -0800 |
commit | d06ed618d356a713292de95f0ab2c6017c305e17 (patch) | |
tree | ad84c64155c782cd13158db020d623b3ea5f370b /alc/backends/wave.cpp | |
parent | 72ddb6351e1102b104ab45bdbb3c7cfb9cb49d08 (diff) |
Avoid using an if_constexpr macro
It doesn't actually use if constexpr, and compilers are smart enough to
optimize. Some functions can use templates instead.
Diffstat (limited to 'alc/backends/wave.cpp')
-rw-r--r-- | alc/backends/wave.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index db3d1151..6360166c 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -149,29 +149,23 @@ int WaveBackend::mixerProc() mDevice->renderSamples(mBuffer.data(), mDevice->UpdateSize, frameStep); done += mDevice->UpdateSize; - if_constexpr(al::endian::native != al::endian::little) + if(al::endian::native != al::endian::little) { const uint bytesize{mDevice->bytesFromFmt()}; if(bytesize == 2) { - ushort *samples = reinterpret_cast<ushort*>(mBuffer.data()); - const size_t len{mBuffer.size() / 2}; - for(size_t i{0};i < len;i++) - { - const ushort samp{samples[i]}; - samples[i] = static_cast<ushort>((samp>>8) | (samp<<8)); - } + const size_t len{mBuffer.size() & ~size_t{1}}; + for(size_t i{0};i < len;i+=2) + std::swap(mBuffer[i], mBuffer[i+1]); } else if(bytesize == 4) { - uint *samples = reinterpret_cast<uint*>(mBuffer.data()); - const size_t len{mBuffer.size() / 4}; - for(size_t i{0};i < len;i++) + const size_t len{mBuffer.size() & ~size_t{3}}; + for(size_t i{0};i < len;i+=4) { - const uint samp{samples[i]}; - samples[i] = (samp>>24) | ((samp>>8)&0x0000ff00) | - ((samp<<8)&0x00ff0000) | (samp<<24); + std::swap(mBuffer[i ], mBuffer[i+3]); + std::swap(mBuffer[i+1], mBuffer[i+2]); } } } |