aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/portaudio.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-27 23:37:24 -0800
committerChris Robinson <[email protected]>2018-12-27 23:37:24 -0800
commitaff58265cb458b2ac2c42fef96383e9751d094d1 (patch)
tree04b66022abdad34fe8bbad8de222206b09dce176 /Alc/backends/portaudio.cpp
parent28308226e76f8378dc74db12b085d50bb97b11cb (diff)
Make more methods into member functions
Diffstat (limited to 'Alc/backends/portaudio.cpp')
-rw-r--r--Alc/backends/portaudio.cpp88
1 files changed, 54 insertions, 34 deletions
diff --git a/Alc/backends/portaudio.cpp b/Alc/backends/portaudio.cpp
index 10c9079b..44ffd9bd 100644
--- a/Alc/backends/portaudio.cpp
+++ b/Alc/backends/portaudio.cpp
@@ -131,17 +131,20 @@ bool pa_load(void)
struct ALCportPlayback final : public ALCbackend {
+ ALCportPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~ALCportPlayback() override;
+
+ static int writeCallbackC(const void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
+ const PaStreamCallbackFlags statusFlags, void *userData);
+ int writeCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
+ const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags);
+
PaStream *mStream{nullptr};
PaStreamParameters mParams{};
ALuint mUpdateSize{0u};
-
- ALCportPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
};
-int ALCportPlayback_WriteCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
- const PaStreamCallbackFlags statusFlags, void *userData);
-
void ALCportPlayback_Construct(ALCportPlayback *self, ALCdevice *device);
void ALCportPlayback_Destruct(ALCportPlayback *self);
ALCenum ALCportPlayback_open(ALCportPlayback *self, const ALCchar *name);
@@ -165,25 +168,32 @@ void ALCportPlayback_Construct(ALCportPlayback *self, ALCdevice *device)
}
void ALCportPlayback_Destruct(ALCportPlayback *self)
+{ self->~ALCportPlayback(); }
+
+ALCportPlayback::~ALCportPlayback()
{
- PaError err = self->mStream ? Pa_CloseStream(self->mStream) : paNoError;
+ PaError err{mStream ? Pa_CloseStream(mStream) : paNoError};
if(err != paNoError)
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
- self->mStream = nullptr;
-
- self->~ALCportPlayback();
+ mStream = nullptr;
}
-int ALCportPlayback_WriteCallback(const void *UNUSED(inputBuffer), void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *UNUSED(timeInfo),
- const PaStreamCallbackFlags UNUSED(statusFlags), void *userData)
+int ALCportPlayback::writeCallbackC(const void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
+ const PaStreamCallbackFlags statusFlags, void *userData)
{
- auto self = static_cast<ALCportPlayback*>(userData);
+ return static_cast<ALCportPlayback*>(userData)->writeCallback(inputBuffer, outputBuffer,
+ framesPerBuffer, timeInfo, statusFlags);
+}
- ALCportPlayback_lock(self);
- aluMixData(self->mDevice, outputBuffer, framesPerBuffer);
- ALCportPlayback_unlock(self);
+int ALCportPlayback::writeCallback(const void* UNUSED(inputBuffer), void *outputBuffer,
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo* UNUSED(timeInfo),
+ const PaStreamCallbackFlags UNUSED(statusFlags))
+{
+ ALCportPlayback_lock(this);
+ aluMixData(mDevice, outputBuffer, framesPerBuffer);
+ ALCportPlayback_unlock(this);
return 0;
}
@@ -236,7 +246,7 @@ ALCenum ALCportPlayback_open(ALCportPlayback *self, const ALCchar *name)
retry_open:
err = Pa_OpenStream(&self->mStream, nullptr, &self->mParams,
device->Frequency, device->UpdateSize, paNoFlag,
- ALCportPlayback_WriteCallback, self
+ &ALCportPlayback::writeCallbackC, self
);
if(err != paNoError)
{
@@ -312,18 +322,21 @@ void ALCportPlayback_stop(ALCportPlayback *self)
struct ALCportCapture final : public ALCbackend {
+ ALCportCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+ ~ALCportCapture() override;
+
+ static int readCallbackC(const void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
+ const PaStreamCallbackFlags statusFlags, void *userData);
+ int readCallback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
+ const PaStreamCallbackTimeInfo *timeInfo, const PaStreamCallbackFlags statusFlags);
+
PaStream *mStream{nullptr};
PaStreamParameters mParams;
RingBufferPtr mRing{nullptr};
-
- ALCportCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
};
-int ALCportCapture_ReadCallback(const void *inputBuffer, void *outputBuffer,
- unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
- const PaStreamCallbackFlags statusFlags, void *userData);
-
void ALCportCapture_Construct(ALCportCapture *self, ALCdevice *device);
void ALCportCapture_Destruct(ALCportCapture *self);
ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name);
@@ -347,23 +360,30 @@ void ALCportCapture_Construct(ALCportCapture *self, ALCdevice *device)
}
void ALCportCapture_Destruct(ALCportCapture *self)
+{ self->~ALCportCapture(); }
+
+ALCportCapture::~ALCportCapture()
{
- PaError err = self->mStream ? Pa_CloseStream(self->mStream) : paNoError;
+ PaError err{mStream ? Pa_CloseStream(mStream) : paNoError};
if(err != paNoError)
ERR("Error closing stream: %s\n", Pa_GetErrorText(err));
- self->mStream = nullptr;
-
- self->~ALCportCapture();
+ mStream = nullptr;
}
-int ALCportCapture_ReadCallback(const void *inputBuffer, void *UNUSED(outputBuffer),
+int ALCportCapture::readCallbackC(const void *inputBuffer, void *outputBuffer,
+ unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo,
+ const PaStreamCallbackFlags statusFlags, void* userData)
+{
+ return static_cast<ALCportCapture*>(userData)->readCallback(inputBuffer, outputBuffer,
+ framesPerBuffer, timeInfo, statusFlags);
+}
+
+int ALCportCapture::readCallback(const void *inputBuffer, void *UNUSED(outputBuffer),
unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *UNUSED(timeInfo),
- const PaStreamCallbackFlags UNUSED(statusFlags), void *userData)
+ const PaStreamCallbackFlags UNUSED(statusFlags))
{
- auto self = static_cast<ALCportCapture*>(userData);
- RingBuffer *ring{self->mRing.get()};
- ring->write(inputBuffer, framesPerBuffer);
+ mRing->write(inputBuffer, framesPerBuffer);
return 0;
}
@@ -419,7 +439,7 @@ ALCenum ALCportCapture_open(ALCportCapture *self, const ALCchar *name)
err = Pa_OpenStream(&self->mStream, &self->mParams, nullptr,
device->Frequency, paFramesPerBufferUnspecified, paNoFlag,
- ALCportCapture_ReadCallback, self
+ &ALCportCapture::readCallbackC, self
);
if(err != paNoError)
{