aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-28 15:09:51 -0800
committerChris Robinson <[email protected]>2018-12-28 15:09:51 -0800
commit01ed98c99bc66f4df589d73c3ec9e97c9387d4f7 (patch)
treedb4e497011724285f4802ccb1df2df4e7b9b1601 /Alc
parentb7f5166d59bc3782cc804eb2019f028fd6cdd4e7 (diff)
Finish turning ancillary backend methods into member functions
Diffstat (limited to 'Alc')
-rw-r--r--Alc/backends/wasapi.cpp313
-rw-r--r--Alc/backends/winmm.cpp293
2 files changed, 301 insertions, 305 deletions
diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp
index 1c760b4e..11bc06e4 100644
--- a/Alc/backends/wasapi.cpp
+++ b/Alc/backends/wasapi.cpp
@@ -345,9 +345,13 @@ struct WasapiProxy {
virtual HRESULT resetProxy() = 0;
virtual HRESULT startProxy() = 0;
virtual void stopProxy() = 0;
+
+ static DWORD CALLBACK messageHandler(void *ptr);
+
+ static constexpr inline const char *CurrentPrefix() noexcept { return "WasapiProxy::"; }
};
-DWORD CALLBACK WasapiProxy_messageHandler(void *ptr)
+DWORD WasapiProxy::messageHandler(void *ptr)
{
auto req = reinterpret_cast<ThreadRequest*>(ptr);
@@ -490,8 +494,11 @@ DWORD CALLBACK WasapiProxy_messageHandler(void *ptr)
}
-struct ALCwasapiPlayback final : public ALCbackend, WasapiProxy {
- ALCwasapiPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+struct WasapiPlayback final : public ALCbackend, WasapiProxy {
+ WasapiPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~WasapiPlayback() override;
+
+ int mixerProc();
HRESULT openProxy() override;
void closeProxy() override;
@@ -513,96 +520,91 @@ struct ALCwasapiPlayback final : public ALCbackend, WasapiProxy {
std::atomic<ALenum> mKillNow{AL_TRUE};
std::thread mThread;
-};
-
-int ALCwasapiPlayback_mixerProc(ALCwasapiPlayback *self);
-
-void ALCwasapiPlayback_Construct(ALCwasapiPlayback *self, ALCdevice *device);
-void ALCwasapiPlayback_Destruct(ALCwasapiPlayback *self);
-ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *name);
-ALCboolean ALCwasapiPlayback_reset(ALCwasapiPlayback *self);
-ALCboolean ALCwasapiPlayback_start(ALCwasapiPlayback *self);
-void ALCwasapiPlayback_stop(ALCwasapiPlayback *self);
-DECLARE_FORWARD2(ALCwasapiPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
-DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, ALCuint, availableSamples)
-ClockLatency ALCwasapiPlayback_getClockLatency(ALCwasapiPlayback *self);
-DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, void, lock)
-DECLARE_FORWARD(ALCwasapiPlayback, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCwasapiPlayback)
-
-DEFINE_ALCBACKEND_VTABLE(ALCwasapiPlayback);
+ static constexpr inline const char *CurrentPrefix() noexcept { return "WasapiPlayback::"; }
+};
-void ALCwasapiPlayback_Construct(ALCwasapiPlayback *self, ALCdevice *device)
+void WasapiPlayback_Construct(WasapiPlayback *self, ALCdevice *device);
+void WasapiPlayback_Destruct(WasapiPlayback *self);
+ALCenum WasapiPlayback_open(WasapiPlayback *self, const ALCchar *name);
+ALCboolean WasapiPlayback_reset(WasapiPlayback *self);
+ALCboolean WasapiPlayback_start(WasapiPlayback *self);
+void WasapiPlayback_stop(WasapiPlayback *self);
+DECLARE_FORWARD2(WasapiPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
+DECLARE_FORWARD(WasapiPlayback, ALCbackend, ALCuint, availableSamples)
+ClockLatency WasapiPlayback_getClockLatency(WasapiPlayback *self);
+DECLARE_FORWARD(WasapiPlayback, ALCbackend, void, lock)
+DECLARE_FORWARD(WasapiPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(WasapiPlayback)
+
+DEFINE_ALCBACKEND_VTABLE(WasapiPlayback);
+
+void WasapiPlayback_Construct(WasapiPlayback *self, ALCdevice *device)
{
- new (self) ALCwasapiPlayback{device};
- SET_VTABLE2(ALCwasapiPlayback, ALCbackend, self);
+ new (self) WasapiPlayback{device};
+ SET_VTABLE2(WasapiPlayback, ALCbackend, self);
}
-void ALCwasapiPlayback_Destruct(ALCwasapiPlayback *self)
+void WasapiPlayback_Destruct(WasapiPlayback *self)
+{ self->~WasapiPlayback(); }
+
+WasapiPlayback::~WasapiPlayback()
{
- if(self->mMsgEvent)
+ if(mMsgEvent)
{
- ThreadRequest req = { self->mMsgEvent, 0 };
- auto proxy = static_cast<WasapiProxy*>(self);
+ ThreadRequest req{ mMsgEvent, 0 };
+ auto proxy = static_cast<WasapiProxy*>(this);
if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)proxy))
(void)WaitForResponse(&req);
- CloseHandle(self->mMsgEvent);
- self->mMsgEvent = nullptr;
+ CloseHandle(mMsgEvent);
+ mMsgEvent = nullptr;
}
- if(self->mNotifyEvent != nullptr)
- CloseHandle(self->mNotifyEvent);
- self->mNotifyEvent = nullptr;
- if(self->mMsgEvent != nullptr)
- CloseHandle(self->mMsgEvent);
- self->mMsgEvent = nullptr;
-
- self->~ALCwasapiPlayback();
+ if(mNotifyEvent != nullptr)
+ CloseHandle(mNotifyEvent);
+ mNotifyEvent = nullptr;
+ if(mMsgEvent != nullptr)
+ CloseHandle(mMsgEvent);
+ mMsgEvent = nullptr;
}
-FORCE_ALIGN int ALCwasapiPlayback_mixerProc(ALCwasapiPlayback *self)
+FORCE_ALIGN int WasapiPlayback::mixerProc()
{
- ALCdevice *device{self->mDevice};
- IAudioClient *client{self->mClient};
- IAudioRenderClient *render{self->mRender};
-
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if(FAILED(hr))
{
ERR("CoInitializeEx(nullptr, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr);
- ALCwasapiPlayback_lock(self);
- aluHandleDisconnect(device, "COM init failed: 0x%08lx", hr);
- ALCwasapiPlayback_unlock(self);
+ WasapiPlayback_lock(this);
+ aluHandleDisconnect(mDevice, "COM init failed: 0x%08lx", hr);
+ WasapiPlayback_unlock(this);
return 1;
}
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- ALuint update_size{device->UpdateSize};
- UINT32 buffer_len{update_size * device->NumUpdates};
- while(!self->mKillNow.load(std::memory_order_relaxed))
+ const ALuint update_size{mDevice->UpdateSize};
+ const UINT32 buffer_len{update_size * mDevice->NumUpdates};
+ while(!mKillNow.load(std::memory_order_relaxed))
{
UINT32 written;
- hr = client->GetCurrentPadding(&written);
+ hr = mClient->GetCurrentPadding(&written);
if(FAILED(hr))
{
ERR("Failed to get padding: 0x%08lx\n", hr);
- ALCwasapiPlayback_lock(self);
- aluHandleDisconnect(device, "Failed to retrieve buffer padding: 0x%08lx", hr);
- ALCwasapiPlayback_unlock(self);
+ WasapiPlayback_lock(this);
+ aluHandleDisconnect(mDevice, "Failed to retrieve buffer padding: 0x%08lx", hr);
+ WasapiPlayback_unlock(this);
break;
}
- self->mPadding.store(written, std::memory_order_relaxed);
+ mPadding.store(written, std::memory_order_relaxed);
ALuint len{buffer_len - written};
if(len < update_size)
{
- DWORD res;
- res = WaitForSingleObjectEx(self->mNotifyEvent, 2000, FALSE);
+ DWORD res{WaitForSingleObjectEx(mNotifyEvent, 2000, FALSE)};
if(res != WAIT_OBJECT_0)
ERR("WaitForSingleObjectEx error: 0x%lx\n", res);
continue;
@@ -610,25 +612,25 @@ FORCE_ALIGN int ALCwasapiPlayback_mixerProc(ALCwasapiPlayback *self)
len -= len%update_size;
BYTE *buffer;
- hr = render->GetBuffer(len, &buffer);
+ hr = mRender->GetBuffer(len, &buffer);
if(SUCCEEDED(hr))
{
- ALCwasapiPlayback_lock(self);
- aluMixData(device, buffer, len);
- self->mPadding.store(written + len, std::memory_order_relaxed);
- ALCwasapiPlayback_unlock(self);
- hr = render->ReleaseBuffer(len, 0);
+ WasapiPlayback_lock(this);
+ aluMixData(mDevice, buffer, len);
+ mPadding.store(written + len, std::memory_order_relaxed);
+ WasapiPlayback_unlock(this);
+ hr = mRender->ReleaseBuffer(len, 0);
}
if(FAILED(hr))
{
ERR("Failed to buffer data: 0x%08lx\n", hr);
- ALCwasapiPlayback_lock(self);
- aluHandleDisconnect(device, "Failed to send playback samples: 0x%08lx", hr);
- ALCwasapiPlayback_unlock(self);
+ WasapiPlayback_lock(this);
+ aluHandleDisconnect(mDevice, "Failed to send playback samples: 0x%08lx", hr);
+ WasapiPlayback_unlock(this);
break;
}
}
- self->mPadding.store(0u, std::memory_order_release);
+ mPadding.store(0u, std::memory_order_release);
CoUninitialize();
return 0;
@@ -674,7 +676,7 @@ ALCboolean MakeExtensible(WAVEFORMATEXTENSIBLE *out, const WAVEFORMATEX *in)
return ALC_TRUE;
}
-ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *deviceName)
+ALCenum WasapiPlayback_open(WasapiPlayback *self, const ALCchar *deviceName)
{
HRESULT hr = S_OK;
@@ -752,7 +754,7 @@ ALCenum ALCwasapiPlayback_open(ALCwasapiPlayback *self, const ALCchar *deviceNam
return ALC_NO_ERROR;
}
-HRESULT ALCwasapiPlayback::openProxy()
+HRESULT WasapiPlayback::openProxy()
{
void *ptr;
HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator, &ptr);
@@ -784,7 +786,7 @@ HRESULT ALCwasapiPlayback::openProxy()
return hr;
}
-void ALCwasapiPlayback::closeProxy()
+void WasapiPlayback::closeProxy()
{
if(mClient)
mClient->Release();
@@ -796,7 +798,7 @@ void ALCwasapiPlayback::closeProxy()
}
-ALCboolean ALCwasapiPlayback_reset(ALCwasapiPlayback *self)
+ALCboolean WasapiPlayback_reset(WasapiPlayback *self)
{
ThreadRequest req{ self->mMsgEvent, 0 };
HRESULT hr{E_FAIL};
@@ -808,7 +810,7 @@ ALCboolean ALCwasapiPlayback_reset(ALCwasapiPlayback *self)
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-HRESULT ALCwasapiPlayback::resetProxy()
+HRESULT WasapiPlayback::resetProxy()
{
if(mClient)
mClient->Release();
@@ -1064,7 +1066,7 @@ HRESULT ALCwasapiPlayback::resetProxy()
}
-ALCboolean ALCwasapiPlayback_start(ALCwasapiPlayback *self)
+ALCboolean WasapiPlayback_start(WasapiPlayback *self)
{
ThreadRequest req{ self->mMsgEvent, 0 };
HRESULT hr{E_FAIL};
@@ -1076,7 +1078,7 @@ ALCboolean ALCwasapiPlayback_start(ALCwasapiPlayback *self)
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-HRESULT ALCwasapiPlayback::startProxy()
+HRESULT WasapiPlayback::startProxy()
{
ResetEvent(mNotifyEvent);
@@ -1094,7 +1096,7 @@ HRESULT ALCwasapiPlayback::startProxy()
mRender = reinterpret_cast<IAudioRenderClient*>(ptr);
try {
mKillNow.store(AL_FALSE, std::memory_order_release);
- mThread = std::thread(ALCwasapiPlayback_mixerProc, this);
+ mThread = std::thread{std::mem_fn(&WasapiPlayback::mixerProc), this};
}
catch(...) {
mRender->Release();
@@ -1111,7 +1113,7 @@ HRESULT ALCwasapiPlayback::startProxy()
}
-void ALCwasapiPlayback_stop(ALCwasapiPlayback *self)
+void WasapiPlayback_stop(WasapiPlayback *self)
{
ThreadRequest req{ self->mMsgEvent, 0 };
auto proxy = static_cast<WasapiProxy*>(self);
@@ -1119,7 +1121,7 @@ void ALCwasapiPlayback_stop(ALCwasapiPlayback *self)
(void)WaitForResponse(&req);
}
-void ALCwasapiPlayback::stopProxy()
+void WasapiPlayback::stopProxy()
{
if(!mRender || !mThread.joinable())
return;
@@ -1133,23 +1135,26 @@ void ALCwasapiPlayback::stopProxy()
}
-ClockLatency ALCwasapiPlayback_getClockLatency(ALCwasapiPlayback *self)
+ClockLatency WasapiPlayback_getClockLatency(WasapiPlayback *self)
{
ClockLatency ret;
- ALCwasapiPlayback_lock(self);
+ WasapiPlayback_lock(self);
ALCdevice *device{self->mDevice};
ret.ClockTime = GetDeviceClockTime(device);
ret.Latency = std::chrono::seconds{self->mPadding.load(std::memory_order_relaxed)};
ret.Latency /= device->Frequency;
- ALCwasapiPlayback_unlock(self);
+ WasapiPlayback_unlock(self);
return ret;
}
-struct ALCwasapiCapture final : public ALCbackend, WasapiProxy {
- ALCwasapiCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+struct WasapiCapture final : public ALCbackend, WasapiProxy {
+ WasapiCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~WasapiCapture() override;
+
+ int recordProc();
HRESULT openProxy() override;
void closeProxy() override;
@@ -1173,78 +1178,73 @@ struct ALCwasapiCapture final : public ALCbackend, WasapiProxy {
std::atomic<int> mKillNow{AL_TRUE};
std::thread mThread;
-};
-int ALCwasapiCapture_recordProc(ALCwasapiCapture *self);
+ static constexpr inline const char *CurrentPrefix() noexcept { return "WasapiCapture::"; }
+};
-void ALCwasapiCapture_Construct(ALCwasapiCapture *self, ALCdevice *device);
-void ALCwasapiCapture_Destruct(ALCwasapiCapture *self);
-ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *name);
-DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, ALCboolean, reset)
-ALCboolean ALCwasapiCapture_start(ALCwasapiCapture *self);
-void ALCwasapiCapture_stop(ALCwasapiCapture *self);
-ALCenum ALCwasapiCapture_captureSamples(ALCwasapiCapture *self, ALCvoid *buffer, ALCuint samples);
-ALuint ALCwasapiCapture_availableSamples(ALCwasapiCapture *self);
-DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, ClockLatency, getClockLatency)
-DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, void, lock)
-DECLARE_FORWARD(ALCwasapiCapture, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCwasapiCapture)
+void WasapiCapture_Construct(WasapiCapture *self, ALCdevice *device);
+void WasapiCapture_Destruct(WasapiCapture *self);
+ALCenum WasapiCapture_open(WasapiCapture *self, const ALCchar *name);
+DECLARE_FORWARD(WasapiCapture, ALCbackend, ALCboolean, reset)
+ALCboolean WasapiCapture_start(WasapiCapture *self);
+void WasapiCapture_stop(WasapiCapture *self);
+ALCenum WasapiCapture_captureSamples(WasapiCapture *self, ALCvoid *buffer, ALCuint samples);
+ALuint WasapiCapture_availableSamples(WasapiCapture *self);
+DECLARE_FORWARD(WasapiCapture, ALCbackend, ClockLatency, getClockLatency)
+DECLARE_FORWARD(WasapiCapture, ALCbackend, void, lock)
+DECLARE_FORWARD(WasapiCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(WasapiCapture)
-DEFINE_ALCBACKEND_VTABLE(ALCwasapiCapture);
+DEFINE_ALCBACKEND_VTABLE(WasapiCapture);
-void ALCwasapiCapture_Construct(ALCwasapiCapture *self, ALCdevice *device)
+void WasapiCapture_Construct(WasapiCapture *self, ALCdevice *device)
{
- new (self) ALCwasapiCapture{device};
- SET_VTABLE2(ALCwasapiCapture, ALCbackend, self);
+ new (self) WasapiCapture{device};
+ SET_VTABLE2(WasapiCapture, ALCbackend, self);
}
-void ALCwasapiCapture_Destruct(ALCwasapiCapture *self)
+void WasapiCapture_Destruct(WasapiCapture *self)
+{ self->~WasapiCapture(); }
+
+WasapiCapture::~WasapiCapture()
{
- if(self->mMsgEvent)
+ if(mMsgEvent)
{
- ThreadRequest req{ self->mMsgEvent, 0 };
- auto proxy = static_cast<WasapiProxy*>(self);
+ ThreadRequest req{ mMsgEvent, 0 };
+ auto proxy = static_cast<WasapiProxy*>(this);
if(PostThreadMessage(ThreadID, WM_USER_CloseDevice, (WPARAM)&req, (LPARAM)proxy))
(void)WaitForResponse(&req);
- CloseHandle(self->mMsgEvent);
- self->mMsgEvent = nullptr;
+ CloseHandle(mMsgEvent);
+ mMsgEvent = nullptr;
}
- if(self->mNotifyEvent != nullptr)
- CloseHandle(self->mNotifyEvent);
- self->mNotifyEvent = nullptr;
-
- self->~ALCwasapiCapture();
+ if(mNotifyEvent != nullptr)
+ CloseHandle(mNotifyEvent);
+ mNotifyEvent = nullptr;
}
-FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self)
+FORCE_ALIGN int WasapiCapture::recordProc()
{
- ALCdevice *device{self->mDevice};
- RingBuffer *ring{self->mRing.get()};
- IAudioCaptureClient *capture{self->mCapture};
-
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if(FAILED(hr))
{
ERR("CoInitializeEx(nullptr, COINIT_MULTITHREADED) failed: 0x%08lx\n", hr);
- ALCwasapiCapture_lock(self);
- aluHandleDisconnect(device, "COM init failed: 0x%08lx", hr);
- ALCwasapiCapture_unlock(self);
+ WasapiCapture_lock(this);
+ aluHandleDisconnect(mDevice, "COM init failed: 0x%08lx", hr);
+ WasapiCapture_unlock(this);
return 1;
}
althrd_setname(RECORD_THREAD_NAME);
al::vector<float> samples;
- while(!self->mKillNow.load(std::memory_order_relaxed))
+ while(!mKillNow.load(std::memory_order_relaxed))
{
UINT32 avail;
- DWORD res;
-
- hr = capture->GetNextPacketSize(&avail);
+ hr = mCapture->GetNextPacketSize(&avail);
if(FAILED(hr))
ERR("Failed to get next packet size: 0x%08lx\n", hr);
else if(avail > 0)
@@ -1253,41 +1253,41 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self)
DWORD flags;
BYTE *rdata;
- hr = capture->GetBuffer(&rdata, &numsamples, &flags, nullptr, nullptr);
+ hr = mCapture->GetBuffer(&rdata, &numsamples, &flags, nullptr, nullptr);
if(FAILED(hr))
ERR("Failed to get capture buffer: 0x%08lx\n", hr);
else
{
- if(ChannelConverter *conv{self->mChannelConv.get()})
+ if(mChannelConv)
{
samples.resize(numsamples*2);
- ChannelConverterInput(conv, rdata, samples.data(), numsamples);
+ ChannelConverterInput(mChannelConv.get(), rdata, samples.data(), numsamples);
rdata = reinterpret_cast<BYTE*>(samples.data());
}
- auto data = ring->getWriteVector();
+ auto data = mRing->getWriteVector();
size_t dstframes;
- if(SampleConverter *conv{self->mSampleConv.get()})
+ if(mSampleConv)
{
- const ALvoid *srcdata = rdata;
- ALsizei srcframes = numsamples;
+ const ALvoid *srcdata{rdata};
+ auto srcframes = static_cast<ALsizei>(numsamples);
- dstframes = SampleConverterInput(conv, &srcdata, &srcframes, data.first.buf,
- (ALsizei)minz(data.first.len, INT_MAX));
+ dstframes = SampleConverterInput(mSampleConv.get(), &srcdata, &srcframes,
+ data.first.buf, (ALsizei)minz(data.first.len, INT_MAX));
if(srcframes > 0 && dstframes == data.first.len && data.second.len > 0)
{
/* If some source samples remain, all of the first dest
* block was filled, and there's space in the second
* dest block, do another run for the second block.
*/
- dstframes += SampleConverterInput(conv, &srcdata, &srcframes,
+ dstframes += SampleConverterInput(mSampleConv.get(), &srcdata, &srcframes,
data.second.buf, (ALsizei)minz(data.second.len, INT_MAX));
}
}
else
{
- const auto framesize = static_cast<ALuint>(device->frameSizeFromFmt());
+ const auto framesize = static_cast<ALuint>(mDevice->frameSizeFromFmt());
size_t len1 = minz(data.first.len, numsamples);
size_t len2 = minz(data.second.len, numsamples-len1);
@@ -1297,22 +1297,22 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self)
dstframes = len1 + len2;
}
- ring->writeAdvance(dstframes);
+ mRing->writeAdvance(dstframes);
- hr = capture->ReleaseBuffer(numsamples);
+ hr = mCapture->ReleaseBuffer(numsamples);
if(FAILED(hr)) ERR("Failed to release capture buffer: 0x%08lx\n", hr);
}
}
if(FAILED(hr))
{
- ALCwasapiCapture_lock(self);
- aluHandleDisconnect(device, "Failed to capture samples: 0x%08lx", hr);
- ALCwasapiCapture_unlock(self);
+ WasapiCapture_lock(this);
+ aluHandleDisconnect(mDevice, "Failed to capture samples: 0x%08lx", hr);
+ WasapiCapture_unlock(this);
break;
}
- res = WaitForSingleObjectEx(self->mNotifyEvent, 2000, FALSE);
+ DWORD res{WaitForSingleObjectEx(mNotifyEvent, 2000, FALSE)};
if(res != WAIT_OBJECT_0)
ERR("WaitForSingleObjectEx error: 0x%lx\n", res);
}
@@ -1322,7 +1322,7 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self)
}
-ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *deviceName)
+ALCenum WasapiCapture_open(WasapiCapture *self, const ALCchar *deviceName)
{
HRESULT hr{S_OK};
@@ -1418,7 +1418,7 @@ ALCenum ALCwasapiCapture_open(ALCwasapiCapture *self, const ALCchar *deviceName)
return ALC_NO_ERROR;
}
-HRESULT ALCwasapiCapture::openProxy()
+HRESULT WasapiCapture::openProxy()
{
void *ptr;
HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_INPROC_SERVER,
@@ -1451,7 +1451,7 @@ HRESULT ALCwasapiCapture::openProxy()
return hr;
}
-void ALCwasapiCapture::closeProxy()
+void WasapiCapture::closeProxy()
{
if(mClient)
mClient->Release();
@@ -1462,7 +1462,7 @@ void ALCwasapiCapture::closeProxy()
mMMDev = nullptr;
}
-HRESULT ALCwasapiCapture::resetProxy()
+HRESULT WasapiCapture::resetProxy()
{
if(mClient)
mClient->Release();
@@ -1694,7 +1694,7 @@ HRESULT ALCwasapiCapture::resetProxy()
}
-ALCboolean ALCwasapiCapture_start(ALCwasapiCapture *self)
+ALCboolean WasapiCapture_start(WasapiCapture *self)
{
ThreadRequest req{ self->mMsgEvent, 0 };
HRESULT hr{E_FAIL};
@@ -1706,7 +1706,7 @@ ALCboolean ALCwasapiCapture_start(ALCwasapiCapture *self)
return SUCCEEDED(hr) ? ALC_TRUE : ALC_FALSE;
}
-HRESULT ALCwasapiCapture::startProxy()
+HRESULT WasapiCapture::startProxy()
{
ResetEvent(mNotifyEvent);
@@ -1724,7 +1724,7 @@ HRESULT ALCwasapiCapture::startProxy()
mCapture = reinterpret_cast<IAudioCaptureClient*>(ptr);
try {
mKillNow.store(AL_FALSE, std::memory_order_release);
- mThread = std::thread(ALCwasapiCapture_recordProc, this);
+ mThread = std::thread{std::mem_fn(&WasapiCapture::recordProc), this};
}
catch(...) {
mCapture->Release();
@@ -1744,7 +1744,7 @@ HRESULT ALCwasapiCapture::startProxy()
}
-void ALCwasapiCapture_stop(ALCwasapiCapture *self)
+void WasapiCapture_stop(WasapiCapture *self)
{
ThreadRequest req{ self->mMsgEvent, 0 };
auto proxy = static_cast<WasapiProxy*>(self);
@@ -1752,7 +1752,7 @@ void ALCwasapiCapture_stop(ALCwasapiCapture *self)
(void)WaitForResponse(&req);
}
-void ALCwasapiCapture::stopProxy()
+void WasapiCapture::stopProxy()
{
if(!mCapture || !mThread.joinable())
return;
@@ -1767,13 +1767,13 @@ void ALCwasapiCapture::stopProxy()
}
-ALuint ALCwasapiCapture_availableSamples(ALCwasapiCapture *self)
+ALuint WasapiCapture_availableSamples(WasapiCapture *self)
{
RingBuffer *ring{self->mRing.get()};
return (ALuint)ring->readSpace();
}
-ALCenum ALCwasapiCapture_captureSamples(ALCwasapiCapture *self, ALCvoid *buffer, ALCuint samples)
+ALCenum WasapiCapture_captureSamples(WasapiCapture *self, ALCvoid *buffer, ALCuint samples)
{
RingBuffer *ring{self->mRing.get()};
ring->read(buffer, samples);
@@ -1797,9 +1797,8 @@ bool WasapiBackendFactory::init()
ERR("Failed to create event: %lu\n", GetLastError());
else
{
- ThreadHdl = CreateThread(nullptr, 0, WasapiProxy_messageHandler, &req, 0, &ThreadID);
- if(ThreadHdl != nullptr)
- InitResult = WaitForResponse(&req);
+ ThreadHdl = CreateThread(nullptr, 0, &WasapiProxy::messageHandler, &req, 0, &ThreadID);
+ if(ThreadHdl != nullptr) InitResult = WaitForResponse(&req);
CloseHandle(req.FinishedEvt);
}
}
@@ -1862,14 +1861,14 @@ ALCbackend *WasapiBackendFactory::createBackend(ALCdevice *device, ALCbackend_Ty
{
if(type == ALCbackend_Playback)
{
- ALCwasapiPlayback *backend;
- NEW_OBJ(backend, ALCwasapiPlayback)(device);
+ WasapiPlayback *backend;
+ NEW_OBJ(backend, WasapiPlayback)(device);
return backend;
}
if(type == ALCbackend_Capture)
{
- ALCwasapiCapture *backend;
- NEW_OBJ(backend, ALCwasapiCapture)(device);
+ WasapiCapture *backend;
+ NEW_OBJ(backend, WasapiCapture)(device);
return backend;
}
diff --git a/Alc/backends/winmm.cpp b/Alc/backends/winmm.cpp
index 1258b6a2..09b7a2e2 100644
--- a/Alc/backends/winmm.cpp
+++ b/Alc/backends/winmm.cpp
@@ -120,11 +120,19 @@ void ProbeCaptureDevices(void)
}
-struct ALCwinmmPlayback final : public ALCbackend {
+struct WinMMPlayback final : public ALCbackend {
+ WinMMPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~WinMMPlayback() override;
+
+ static void CALLBACK waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
+ void CALLBACK waveOutProc(HWAVEOUT device, UINT msg, DWORD_PTR param1, DWORD_PTR param2);
+
+ int mixerProc();
+
std::atomic<ALuint> mWritable{0u};
al::semaphore mSem;
int mIdx{0};
- std::array<WAVEHDR,4> mWaveBuffer;
+ std::array<WAVEHDR,4> mWaveBuffer{};
HWAVEOUT mOutHdl{nullptr};
@@ -133,105 +141,96 @@ struct ALCwinmmPlayback final : public ALCbackend {
std::atomic<ALenum> mKillNow{AL_TRUE};
std::thread mThread;
- ALCwinmmPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+ static constexpr inline const char *CurrentPrefix() noexcept { return "WinMMPlayback::"; }
};
-void ALCwinmmPlayback_Construct(ALCwinmmPlayback *self, ALCdevice *device);
-void ALCwinmmPlayback_Destruct(ALCwinmmPlayback *self);
-
-void CALLBACK ALCwinmmPlayback_waveOutProc(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
-int ALCwinmmPlayback_mixerProc(ALCwinmmPlayback *self);
-
-ALCenum ALCwinmmPlayback_open(ALCwinmmPlayback *self, const ALCchar *name);
-ALCboolean ALCwinmmPlayback_reset(ALCwinmmPlayback *self);
-ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self);
-void ALCwinmmPlayback_stop(ALCwinmmPlayback *self);
-DECLARE_FORWARD2(ALCwinmmPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
-DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, ALCuint, availableSamples)
-DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, ClockLatency, getClockLatency)
-DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, void, lock)
-DECLARE_FORWARD(ALCwinmmPlayback, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCwinmmPlayback)
-
-DEFINE_ALCBACKEND_VTABLE(ALCwinmmPlayback);
-
-
-void ALCwinmmPlayback_Construct(ALCwinmmPlayback *self, ALCdevice *device)
+void WinMMPlayback_Construct(WinMMPlayback *self, ALCdevice *device);
+void WinMMPlayback_Destruct(WinMMPlayback *self);
+ALCenum WinMMPlayback_open(WinMMPlayback *self, const ALCchar *name);
+ALCboolean WinMMPlayback_reset(WinMMPlayback *self);
+ALCboolean WinMMPlayback_start(WinMMPlayback *self);
+void WinMMPlayback_stop(WinMMPlayback *self);
+DECLARE_FORWARD2(WinMMPlayback, ALCbackend, ALCenum, captureSamples, ALCvoid*, ALCuint)
+DECLARE_FORWARD(WinMMPlayback, ALCbackend, ALCuint, availableSamples)
+DECLARE_FORWARD(WinMMPlayback, ALCbackend, ClockLatency, getClockLatency)
+DECLARE_FORWARD(WinMMPlayback, ALCbackend, void, lock)
+DECLARE_FORWARD(WinMMPlayback, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(WinMMPlayback)
+
+DEFINE_ALCBACKEND_VTABLE(WinMMPlayback);
+
+void WinMMPlayback_Construct(WinMMPlayback *self, ALCdevice *device)
{
- new (self) ALCwinmmPlayback{device};
- SET_VTABLE2(ALCwinmmPlayback, ALCbackend, self);
-
- std::fill(self->mWaveBuffer.begin(), self->mWaveBuffer.end(), WAVEHDR{});
+ new (self) WinMMPlayback{device};
+ SET_VTABLE2(WinMMPlayback, ALCbackend, self);
}
-void ALCwinmmPlayback_Destruct(ALCwinmmPlayback *self)
-{
- if(self->mOutHdl)
- waveOutClose(self->mOutHdl);
- self->mOutHdl = nullptr;
+void WinMMPlayback_Destruct(WinMMPlayback *self)
+{ self->~WinMMPlayback(); }
- al_free(self->mWaveBuffer[0].lpData);
- std::fill(self->mWaveBuffer.begin(), self->mWaveBuffer.end(), WAVEHDR{});
+WinMMPlayback::~WinMMPlayback()
+{
+ if(mOutHdl)
+ waveOutClose(mOutHdl);
+ mOutHdl = nullptr;
- self->~ALCwinmmPlayback();
+ al_free(mWaveBuffer[0].lpData);
+ std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
}
-/* ALCwinmmPlayback_waveOutProc
+void CALLBACK WinMMPlayback::waveOutProcC(HWAVEOUT device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
+{ reinterpret_cast<WinMMPlayback*>(instance)->waveOutProc(device, msg, param1, param2); }
+
+/* WinMMPlayback::waveOutProc
*
- * Posts a message to 'ALCwinmmPlayback_mixerProc' everytime a WaveOut Buffer
- * is completed and returns to the application (for more data)
+ * Posts a message to 'WinMMPlayback::mixerProc' everytime a WaveOut Buffer is
+ * completed and returns to the application (for more data)
*/
-void CALLBACK ALCwinmmPlayback_waveOutProc(HWAVEOUT UNUSED(device), UINT msg,
- DWORD_PTR instance, DWORD_PTR UNUSED(param1),
- DWORD_PTR UNUSED(param2))
+void CALLBACK WinMMPlayback::waveOutProc(HWAVEOUT UNUSED(device), UINT msg,
+ DWORD_PTR UNUSED(param1), DWORD_PTR UNUSED(param2))
{
- if(msg != WOM_DONE)
- return;
-
- auto self = reinterpret_cast<ALCwinmmPlayback*>(instance);
- self->mWritable.fetch_add(1, std::memory_order_acq_rel);
- self->mSem.post();
+ if(msg != WOM_DONE) return;
+ mWritable.fetch_add(1, std::memory_order_acq_rel);
+ mSem.post();
}
-FORCE_ALIGN int ALCwinmmPlayback_mixerProc(ALCwinmmPlayback *self)
+FORCE_ALIGN int WinMMPlayback::mixerProc()
{
- ALCdevice *device{self->mDevice};
-
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- ALCwinmmPlayback_lock(self);
- while(!self->mKillNow.load(std::memory_order_acquire) &&
- device->Connected.load(std::memory_order_acquire))
+ WinMMPlayback_lock(this);
+ while(!mKillNow.load(std::memory_order_acquire) &&
+ mDevice->Connected.load(std::memory_order_acquire))
{
- ALsizei todo = self->mWritable.load(std::memory_order_acquire);
+ ALsizei todo = mWritable.load(std::memory_order_acquire);
if(todo < 1)
{
- ALCwinmmPlayback_unlock(self);
- self->mSem.wait();
- ALCwinmmPlayback_lock(self);
+ WinMMPlayback_unlock(this);
+ mSem.wait();
+ WinMMPlayback_lock(this);
continue;
}
- int widx{self->mIdx};
+ int widx{mIdx};
do {
- WAVEHDR &waveHdr = self->mWaveBuffer[widx];
- widx = (widx+1) % self->mWaveBuffer.size();
+ WAVEHDR &waveHdr = mWaveBuffer[widx];
+ widx = (widx+1) % mWaveBuffer.size();
- aluMixData(device, waveHdr.lpData, device->UpdateSize);
- self->mWritable.fetch_sub(1, std::memory_order_acq_rel);
- waveOutWrite(self->mOutHdl, &waveHdr, sizeof(WAVEHDR));
+ aluMixData(mDevice, waveHdr.lpData, mDevice->UpdateSize);
+ mWritable.fetch_sub(1, std::memory_order_acq_rel);
+ waveOutWrite(mOutHdl, &waveHdr, sizeof(WAVEHDR));
} while(--todo);
- self->mIdx = widx;
+ mIdx = widx;
}
- ALCwinmmPlayback_unlock(self);
+ WinMMPlayback_unlock(this);
return 0;
}
-ALCenum ALCwinmmPlayback_open(ALCwinmmPlayback *self, const ALCchar *deviceName)
+ALCenum WinMMPlayback_open(WinMMPlayback *self, const ALCchar *deviceName)
{
ALCdevice *device{self->mDevice};
@@ -269,8 +268,7 @@ retry_open:
self->mFormat.cbSize = 0;
MMRESULT res{waveOutOpen(&self->mOutHdl, DeviceID, &self->mFormat,
- (DWORD_PTR)&ALCwinmmPlayback_waveOutProc, (DWORD_PTR)self, CALLBACK_FUNCTION
- )};
+ (DWORD_PTR)&WinMMPlayback::waveOutProcC, (DWORD_PTR)self, CALLBACK_FUNCTION)};
if(res != MMSYSERR_NOERROR)
{
if(device->FmtType == DevFmtFloat)
@@ -286,7 +284,7 @@ retry_open:
return ALC_NO_ERROR;
}
-ALCboolean ALCwinmmPlayback_reset(ALCwinmmPlayback *self)
+ALCboolean WinMMPlayback_reset(WinMMPlayback *self)
{
ALCdevice *device{self->mDevice};
@@ -354,7 +352,7 @@ ALCboolean ALCwinmmPlayback_reset(ALCwinmmPlayback *self)
return ALC_TRUE;
}
-ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self)
+ALCboolean WinMMPlayback_start(WinMMPlayback *self)
{
try {
std::for_each(self->mWaveBuffer.begin(), self->mWaveBuffer.end(),
@@ -365,7 +363,7 @@ ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self)
std::memory_order_release);
self->mKillNow.store(AL_FALSE, std::memory_order_release);
- self->mThread = std::thread(ALCwinmmPlayback_mixerProc, self);
+ self->mThread = std::thread{std::mem_fn(&WinMMPlayback::mixerProc), self};
return ALC_TRUE;
}
catch(std::exception& e) {
@@ -376,7 +374,7 @@ ALCboolean ALCwinmmPlayback_start(ALCwinmmPlayback *self)
return ALC_FALSE;
}
-void ALCwinmmPlayback_stop(ALCwinmmPlayback *self)
+void WinMMPlayback_stop(WinMMPlayback *self)
{
if(self->mKillNow.exchange(AL_TRUE, std::memory_order_acq_rel) || !self->mThread.joinable())
return;
@@ -392,7 +390,15 @@ void ALCwinmmPlayback_stop(ALCwinmmPlayback *self)
}
-struct ALCwinmmCapture final : public ALCbackend {
+struct WinMMCapture final : public ALCbackend {
+ WinMMCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~WinMMCapture() override;
+
+ static void CALLBACK waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
+ void CALLBACK waveInProc(HWAVEIN device, UINT msg, DWORD_PTR param1, DWORD_PTR param2);
+
+ int captureProc();
+
std::atomic<ALuint> mReadable{0u};
al::semaphore mSem;
int mIdx{0};
@@ -407,104 +413,95 @@ struct ALCwinmmCapture final : public ALCbackend {
std::atomic<ALenum> mKillNow{AL_TRUE};
std::thread mThread;
- ALCwinmmCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+ static constexpr inline const char *CurrentPrefix() noexcept { return "WinMMCapture::"; }
};
-void ALCwinmmCapture_Construct(ALCwinmmCapture *self, ALCdevice *device);
-void ALCwinmmCapture_Destruct(ALCwinmmCapture *self);
-
-void CALLBACK ALCwinmmCapture_waveInProc(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2);
-int ALCwinmmCapture_captureProc(ALCwinmmCapture *self);
-
-ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *deviceName);
-DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, ALCboolean, reset)
-ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self);
-void ALCwinmmCapture_stop(ALCwinmmCapture *self);
-ALCenum ALCwinmmCapture_captureSamples(ALCwinmmCapture *self, ALCvoid *buffer, ALCuint samples);
-ALCuint ALCwinmmCapture_availableSamples(ALCwinmmCapture *self);
-DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, ClockLatency, getClockLatency)
-DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, void, lock)
-DECLARE_FORWARD(ALCwinmmCapture, ALCbackend, void, unlock)
-DECLARE_DEFAULT_ALLOCATORS(ALCwinmmCapture)
-
-DEFINE_ALCBACKEND_VTABLE(ALCwinmmCapture);
-
-
-void ALCwinmmCapture_Construct(ALCwinmmCapture *self, ALCdevice *device)
+void WinMMCapture_Construct(WinMMCapture *self, ALCdevice *device);
+void WinMMCapture_Destruct(WinMMCapture *self);
+ALCenum WinMMCapture_open(WinMMCapture *self, const ALCchar *deviceName);
+DECLARE_FORWARD(WinMMCapture, ALCbackend, ALCboolean, reset)
+ALCboolean WinMMCapture_start(WinMMCapture *self);
+void WinMMCapture_stop(WinMMCapture *self);
+ALCenum WinMMCapture_captureSamples(WinMMCapture *self, ALCvoid *buffer, ALCuint samples);
+ALCuint WinMMCapture_availableSamples(WinMMCapture *self);
+DECLARE_FORWARD(WinMMCapture, ALCbackend, ClockLatency, getClockLatency)
+DECLARE_FORWARD(WinMMCapture, ALCbackend, void, lock)
+DECLARE_FORWARD(WinMMCapture, ALCbackend, void, unlock)
+DECLARE_DEFAULT_ALLOCATORS(WinMMCapture)
+
+DEFINE_ALCBACKEND_VTABLE(WinMMCapture);
+
+void WinMMCapture_Construct(WinMMCapture *self, ALCdevice *device)
{
- new (self) ALCwinmmCapture{device};
- SET_VTABLE2(ALCwinmmCapture, ALCbackend, self);
+ new (self) WinMMCapture{device};
+ SET_VTABLE2(WinMMCapture, ALCbackend, self);
}
-void ALCwinmmCapture_Destruct(ALCwinmmCapture *self)
+void WinMMCapture_Destruct(WinMMCapture *self)
+{ self->~WinMMCapture(); }
+
+WinMMCapture::~WinMMCapture()
{
// Close the Wave device
- if(self->mInHdl)
- waveInClose(self->mInHdl);
- self->mInHdl = nullptr;
-
- al_free(self->mWaveBuffer[0].lpData);
- std::fill(self->mWaveBuffer.begin(), self->mWaveBuffer.end(), WAVEHDR{});
+ if(mInHdl)
+ waveInClose(mInHdl);
+ mInHdl = nullptr;
- self->~ALCwinmmCapture();
+ al_free(mWaveBuffer[0].lpData);
+ std::fill(mWaveBuffer.begin(), mWaveBuffer.end(), WAVEHDR{});
}
+void CALLBACK WinMMCapture::waveInProcC(HWAVEIN device, UINT msg, DWORD_PTR instance, DWORD_PTR param1, DWORD_PTR param2)
+{ reinterpret_cast<WinMMCapture*>(instance)->waveInProc(device, msg, param1, param2); }
-/* ALCwinmmCapture_waveInProc
+/* WinMMCapture::waveInProc
*
- * Posts a message to 'ALCwinmmCapture_captureProc' everytime a WaveIn Buffer
- * is completed and returns to the application (with more data).
+ * Posts a message to 'WinMMCapture::captureProc' everytime a WaveIn Buffer is
+ * completed and returns to the application (with more data).
*/
-void CALLBACK ALCwinmmCapture_waveInProc(HWAVEIN UNUSED(device), UINT msg,
- DWORD_PTR instance, DWORD_PTR UNUSED(param1),
- DWORD_PTR UNUSED(param2))
+void CALLBACK WinMMCapture::waveInProc(HWAVEIN UNUSED(device), UINT msg,
+ DWORD_PTR UNUSED(param1), DWORD_PTR UNUSED(param2))
{
- if(msg != WIM_DATA)
- return;
-
- auto self = reinterpret_cast<ALCwinmmCapture*>(instance);
- self->mReadable.fetch_add(1, std::memory_order_acq_rel);
- self->mSem.post();
+ if(msg != WIM_DATA) return;
+ mReadable.fetch_add(1, std::memory_order_acq_rel);
+ mSem.post();
}
-int ALCwinmmCapture_captureProc(ALCwinmmCapture *self)
+int WinMMCapture::captureProc()
{
- ALCdevice *device{self->mDevice};
- RingBuffer *ring{self->mRing.get()};
-
althrd_setname(RECORD_THREAD_NAME);
- ALCwinmmCapture_lock(self);
- while(!self->mKillNow.load(std::memory_order_acquire) &&
- device->Connected.load(std::memory_order_acquire))
+ WinMMCapture_lock(this);
+ while(!mKillNow.load(std::memory_order_acquire) &&
+ mDevice->Connected.load(std::memory_order_acquire))
{
- ALuint todo{self->mReadable.load(std::memory_order_acquire)};
+ ALuint todo{mReadable.load(std::memory_order_acquire)};
if(todo < 1)
{
- ALCwinmmCapture_unlock(self);
- self->mSem.wait();
- ALCwinmmCapture_lock(self);
+ WinMMCapture_unlock(this);
+ mSem.wait();
+ WinMMCapture_lock(this);
continue;
}
- int widx{self->mIdx};
+ int widx{mIdx};
do {
- WAVEHDR &waveHdr = self->mWaveBuffer[widx];
- widx = (widx+1) % self->mWaveBuffer.size();
+ WAVEHDR &waveHdr = mWaveBuffer[widx];
+ widx = (widx+1) % mWaveBuffer.size();
- ring->write(waveHdr.lpData, waveHdr.dwBytesRecorded / self->mFormat.nBlockAlign);
- self->mReadable.fetch_sub(1, std::memory_order_acq_rel);
- waveInAddBuffer(self->mInHdl, &waveHdr, sizeof(WAVEHDR));
+ mRing->write(waveHdr.lpData, waveHdr.dwBytesRecorded / mFormat.nBlockAlign);
+ mReadable.fetch_sub(1, std::memory_order_acq_rel);
+ waveInAddBuffer(mInHdl, &waveHdr, sizeof(WAVEHDR));
} while(--todo);
- self->mIdx = widx;
+ mIdx = widx;
}
- ALCwinmmCapture_unlock(self);
+ WinMMCapture_unlock(this);
return 0;
}
-ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *deviceName)
+ALCenum WinMMCapture_open(WinMMCapture *self, const ALCchar *deviceName)
{
ALCdevice *device{self->mDevice};
@@ -560,7 +557,7 @@ ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *deviceName)
self->mFormat.cbSize = 0;
MMRESULT res{waveInOpen(&self->mInHdl, DeviceID, &self->mFormat,
- (DWORD_PTR)&ALCwinmmCapture_waveInProc, (DWORD_PTR)self, CALLBACK_FUNCTION
+ (DWORD_PTR)&WinMMCapture::waveInProcC, (DWORD_PTR)self, CALLBACK_FUNCTION
)};
if(res != MMSYSERR_NOERROR)
{
@@ -597,7 +594,7 @@ ALCenum ALCwinmmCapture_open(ALCwinmmCapture *self, const ALCchar *deviceName)
return ALC_NO_ERROR;
}
-ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self)
+ALCboolean WinMMCapture_start(WinMMCapture *self)
{
try {
for(size_t i{0};i < self->mWaveBuffer.size();++i)
@@ -607,7 +604,7 @@ ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self)
}
self->mKillNow.store(AL_FALSE, std::memory_order_release);
- self->mThread = std::thread(ALCwinmmCapture_captureProc, self);
+ self->mThread = std::thread{std::mem_fn(&WinMMCapture::captureProc), self};
waveInStart(self->mInHdl);
return ALC_TRUE;
@@ -620,7 +617,7 @@ ALCboolean ALCwinmmCapture_start(ALCwinmmCapture *self)
return ALC_FALSE;
}
-void ALCwinmmCapture_stop(ALCwinmmCapture *self)
+void WinMMCapture_stop(WinMMCapture *self)
{
waveInStop(self->mInHdl);
@@ -639,14 +636,14 @@ void ALCwinmmCapture_stop(ALCwinmmCapture *self)
self->mIdx = 0;
}
-ALCenum ALCwinmmCapture_captureSamples(ALCwinmmCapture *self, ALCvoid *buffer, ALCuint samples)
+ALCenum WinMMCapture_captureSamples(WinMMCapture *self, ALCvoid *buffer, ALCuint samples)
{
RingBuffer *ring{self->mRing.get()};
ring->read(buffer, samples);
return ALC_NO_ERROR;
}
-ALCuint ALCwinmmCapture_availableSamples(ALCwinmmCapture *self)
+ALCuint WinMMCapture_availableSamples(WinMMCapture *self)
{
RingBuffer *ring{self->mRing.get()};
return (ALCuint)ring->readSpace();
@@ -695,14 +692,14 @@ ALCbackend *WinMMBackendFactory::createBackend(ALCdevice *device, ALCbackend_Typ
{
if(type == ALCbackend_Playback)
{
- ALCwinmmPlayback *backend;
- NEW_OBJ(backend, ALCwinmmPlayback)(device);
+ WinMMPlayback *backend;
+ NEW_OBJ(backend, WinMMPlayback)(device);
return backend;
}
if(type == ALCbackend_Capture)
{
- ALCwinmmCapture *backend;
- NEW_OBJ(backend, ALCwinmmCapture)(device);
+ WinMMCapture *backend;
+ NEW_OBJ(backend, WinMMCapture)(device);
return backend;
}