From fcf850c1dd54dcf5de5bc7afc723ffac51e5c0c9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 16 Sep 2019 07:32:13 -0700 Subject: Clean up some more conversion warnings --- alc/backends/opensl.cpp | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'alc/backends') diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index ec32c295..50ea884d 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -146,7 +146,8 @@ struct OpenSLPlayback final : public BackendBase { OpenSLPlayback(ALCdevice *device) noexcept : BackendBase{device} { } ~OpenSLPlayback() override; - static void processC(SLAndroidSimpleBufferQueueItf bq, void *context); + static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) + { static_cast(context)->process(bq); } void process(SLAndroidSimpleBufferQueueItf bq); int mixerProc(); @@ -196,9 +197,6 @@ OpenSLPlayback::~OpenSLPlayback() /* this callback handler is called every time a buffer finishes playing */ -void OpenSLPlayback::processC(SLAndroidSimpleBufferQueueItf bq, void *context) -{ static_cast(context)->process(bq); } - void OpenSLPlayback::process(SLAndroidSimpleBufferQueueItf) { /* A note on the ringbuffer usage: The buffer queue seems to hold on to the @@ -264,9 +262,11 @@ int OpenSLPlayback::mixerProc() } auto data = mRing->getWriteVector(); - aluMixData(mDevice, data.first.buf, data.first.len*mDevice->UpdateSize); + aluMixData(mDevice, data.first.buf, + static_cast(data.first.len*mDevice->UpdateSize)); if(data.second.len > 0) - aluMixData(mDevice, data.second.buf, data.second.len*mDevice->UpdateSize); + aluMixData(mDevice, data.second.buf, + static_cast(data.second.len*mDevice->UpdateSize)); size_t todo{data.first.len + data.second.len}; mRing->writeAdvance(todo); @@ -631,7 +631,8 @@ struct OpenSLCapture final : public BackendBase { OpenSLCapture(ALCdevice *device) noexcept : BackendBase{device} { } ~OpenSLCapture() override; - static void processC(SLAndroidSimpleBufferQueueItf bq, void *context); + static void processC(SLAndroidSimpleBufferQueueItf bq, void *context) + { static_cast(context)->process(bq); } void process(SLAndroidSimpleBufferQueueItf bq); ALCenum open(const ALCchar *name) override; @@ -668,9 +669,6 @@ OpenSLCapture::~OpenSLCapture() } -void OpenSLCapture::processC(SLAndroidSimpleBufferQueueItf bq, void *context) -{ static_cast(context)->process(bq); } - void OpenSLCapture::process(SLAndroidSimpleBufferQueueItf) { /* A new chunk has been written into the ring buffer, advance it. */ @@ -711,7 +709,7 @@ ALCenum OpenSLCapture::open(const ALCchar* name) mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false); mDevice->UpdateSize = update_len; - mDevice->BufferSize = mRing->writeSpace() * update_len; + mDevice->BufferSize = static_cast(mRing->writeSpace() * update_len); } catch(std::exception& e) { ERR("Failed to allocate ring buffer: %s\n", e.what()); @@ -886,25 +884,24 @@ void OpenSLCapture::stop() ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) { - ALuint chunk_size{mDevice->UpdateSize * mFrameSize}; SLAndroidSimpleBufferQueueItf bufferQueue; - SLresult result; - ALCuint i; - - result = VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue); + SLresult result{VCALL(mRecordObj,GetInterface)(SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bufferQueue)}; PRINTERR(result, "recordObj->GetInterface"); + const ALuint update_size{mDevice->UpdateSize}; + const ALuint chunk_size{update_size * mFrameSize}; + /* Read the desired samples from the ring buffer then advance its read * pointer. */ auto data = mRing->getReadVector(); - for(i = 0;i < samples;) + for(ALCuint i{0};i < samples;) { - ALCuint rem{minu(samples - i, mDevice->UpdateSize - mSplOffset)}; - memcpy(buffer + i*mFrameSize, data.first.buf + mSplOffset*mFrameSize, rem*mFrameSize); + const ALCuint rem{minu(samples - i, update_size - mSplOffset)}; + std::copy_n(data.first.buf + mSplOffset*mFrameSize, rem*mFrameSize, buffer + i*mFrameSize); mSplOffset += rem; - if(mSplOffset == mDevice->UpdateSize) + if(mSplOffset == update_size) { /* Finished a chunk, reset the offset and advance the read pointer. */ mSplOffset = 0; @@ -924,7 +921,7 @@ ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) i += rem; } - if(SL_RESULT_SUCCESS != result) + if UNLIKELY(SL_RESULT_SUCCESS != result) { aluHandleDisconnect(mDevice, "Failed to update capture buffer: 0x%08x", result); return ALC_INVALID_DEVICE; @@ -934,7 +931,7 @@ ALCenum OpenSLCapture::captureSamples(al::byte *buffer, ALCuint samples) } ALCuint OpenSLCapture::availableSamples() -{ return mRing->readSpace()*mDevice->UpdateSize - mSplOffset; } +{ return static_cast(mRing->readSpace()*mDevice->UpdateSize - mSplOffset); } } // namespace -- cgit v1.2.3