aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-27 19:38:02 -0800
committerChris Robinson <[email protected]>2018-12-27 19:38:02 -0800
commit015a4b060b2f0461f412e519c2a219ed1e7465c2 (patch)
tree8299c6f1d8f1ed11d4948105f8d77e4f8dcf65fc /Alc/backends
parent0f3645902886b52102ffec51636c2fd8f1e7c3c5 (diff)
Make some ancillary methods into member functions
Diffstat (limited to 'Alc/backends')
-rw-r--r--Alc/backends/alsa.cpp123
-rw-r--r--Alc/backends/coreaudio.cpp125
2 files changed, 131 insertions, 117 deletions
diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp
index f0838d25..f363fc4e 100644
--- a/Alc/backends/alsa.cpp
+++ b/Alc/backends/alsa.cpp
@@ -423,19 +423,19 @@ int verify_state(snd_pcm_t *handle)
struct ALCplaybackAlsa final : public ALCbackend {
+ ALCplaybackAlsa(ALCdevice *device) noexcept : ALCbackend{device} { }
+
+ int mixerProc();
+ int mixerNoMMapProc();
+
snd_pcm_t *mPcmHandle{nullptr};
al::vector<char> mBuffer;
std::atomic<ALenum> mKillNow{AL_TRUE};
std::thread mThread;
-
- ALCplaybackAlsa(ALCdevice *device) noexcept : ALCbackend{device} { }
};
-int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self);
-int ALCplaybackAlsa_mixerNoMMapProc(ALCplaybackAlsa *self);
-
void ALCplaybackAlsa_Construct(ALCplaybackAlsa *self, ALCdevice *device);
void ALCplaybackAlsa_Destruct(ALCplaybackAlsa *self);
ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name);
@@ -467,28 +467,26 @@ void ALCplaybackAlsa_Destruct(ALCplaybackAlsa *self)
}
-int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self)
+int ALCplaybackAlsa::mixerProc()
{
- ALCdevice *device{self->mDevice};
-
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- snd_pcm_uframes_t update_size{device->UpdateSize};
- snd_pcm_uframes_t num_updates{device->NumUpdates};
- while(!self->mKillNow.load(std::memory_order_acquire))
+ snd_pcm_uframes_t update_size{mDevice->UpdateSize};
+ snd_pcm_uframes_t num_updates{mDevice->NumUpdates};
+ while(!mKillNow.load(std::memory_order_acquire))
{
- int state{verify_state(self->mPcmHandle)};
+ int state{verify_state(mPcmHandle)};
if(state < 0)
{
ERR("Invalid state detected: %s\n", snd_strerror(state));
- ALCplaybackAlsa_lock(self);
- aluHandleDisconnect(device, "Bad state: %s", snd_strerror(state));
- ALCplaybackAlsa_unlock(self);
+ ALCplaybackAlsa_lock(this);
+ aluHandleDisconnect(mDevice, "Bad state: %s", snd_strerror(state));
+ ALCplaybackAlsa_unlock(this);
break;
}
- snd_pcm_sframes_t avail{snd_pcm_avail_update(self->mPcmHandle)};
+ snd_pcm_sframes_t avail{snd_pcm_avail_update(mPcmHandle)};
if(avail < 0)
{
ERR("available update failed: %s\n", snd_strerror(avail));
@@ -498,7 +496,7 @@ int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self)
if((snd_pcm_uframes_t)avail > update_size*(num_updates+1))
{
WARN("available samples exceeds the buffer size\n");
- snd_pcm_reset(self->mPcmHandle);
+ snd_pcm_reset(mPcmHandle);
continue;
}
@@ -507,28 +505,28 @@ int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self)
{
if(state != SND_PCM_STATE_RUNNING)
{
- int err{snd_pcm_start(self->mPcmHandle)};
+ int err{snd_pcm_start(mPcmHandle)};
if(err < 0)
{
ERR("start failed: %s\n", snd_strerror(err));
continue;
}
}
- if(snd_pcm_wait(self->mPcmHandle, 1000) == 0)
+ if(snd_pcm_wait(mPcmHandle, 1000) == 0)
ERR("Wait timeout... buffer size too low?\n");
continue;
}
avail -= avail%update_size;
// it is possible that contiguous areas are smaller, thus we use a loop
- ALCplaybackAlsa_lock(self);
+ ALCplaybackAlsa_lock(this);
while(avail > 0)
{
snd_pcm_uframes_t frames{static_cast<snd_pcm_uframes_t>(avail)};
const snd_pcm_channel_area_t *areas{};
snd_pcm_uframes_t offset{};
- int err{snd_pcm_mmap_begin(self->mPcmHandle, &areas, &offset, &frames)};
+ int err{snd_pcm_mmap_begin(mPcmHandle, &areas, &offset, &frames)};
if(err < 0)
{
ERR("mmap begin error: %s\n", snd_strerror(err));
@@ -536,9 +534,9 @@ int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self)
}
char *WritePtr{(char*)areas->addr + (offset * areas->step / 8)};
- aluMixData(device, WritePtr, frames);
+ aluMixData(mDevice, WritePtr, frames);
- snd_pcm_sframes_t commitres{snd_pcm_mmap_commit(self->mPcmHandle, offset, frames)};
+ snd_pcm_sframes_t commitres{snd_pcm_mmap_commit(mPcmHandle, offset, frames)};
if(commitres < 0 || (commitres-frames) != 0)
{
ERR("mmap commit error: %s\n",
@@ -548,34 +546,32 @@ int ALCplaybackAlsa_mixerProc(ALCplaybackAlsa *self)
avail -= frames;
}
- ALCplaybackAlsa_unlock(self);
+ ALCplaybackAlsa_unlock(this);
}
return 0;
}
-int ALCplaybackAlsa_mixerNoMMapProc(ALCplaybackAlsa *self)
+int ALCplaybackAlsa::mixerNoMMapProc()
{
- ALCdevice *device{self->mDevice};
-
SetRTPriority();
althrd_setname(MIXER_THREAD_NAME);
- snd_pcm_uframes_t update_size{device->UpdateSize};
- snd_pcm_uframes_t num_updates{device->NumUpdates};
- while(!self->mKillNow.load(std::memory_order_acquire))
+ snd_pcm_uframes_t update_size{mDevice->UpdateSize};
+ snd_pcm_uframes_t num_updates{mDevice->NumUpdates};
+ while(!mKillNow.load(std::memory_order_acquire))
{
- int state{verify_state(self->mPcmHandle)};
+ int state{verify_state(mPcmHandle)};
if(state < 0)
{
ERR("Invalid state detected: %s\n", snd_strerror(state));
- ALCplaybackAlsa_lock(self);
- aluHandleDisconnect(device, "Bad state: %s", snd_strerror(state));
- ALCplaybackAlsa_unlock(self);
+ ALCplaybackAlsa_lock(this);
+ aluHandleDisconnect(mDevice, "Bad state: %s", snd_strerror(state));
+ ALCplaybackAlsa_unlock(this);
break;
}
- snd_pcm_sframes_t avail{snd_pcm_avail_update(self->mPcmHandle)};
+ snd_pcm_sframes_t avail{snd_pcm_avail_update(mPcmHandle)};
if(avail < 0)
{
ERR("available update failed: %s\n", snd_strerror(avail));
@@ -585,7 +581,7 @@ int ALCplaybackAlsa_mixerNoMMapProc(ALCplaybackAlsa *self)
if((snd_pcm_uframes_t)avail > update_size*num_updates)
{
WARN("available samples exceeds the buffer size\n");
- snd_pcm_reset(self->mPcmHandle);
+ snd_pcm_reset(mPcmHandle);
continue;
}
@@ -593,26 +589,26 @@ int ALCplaybackAlsa_mixerNoMMapProc(ALCplaybackAlsa *self)
{
if(state != SND_PCM_STATE_RUNNING)
{
- int err{snd_pcm_start(self->mPcmHandle)};
+ int err{snd_pcm_start(mPcmHandle)};
if(err < 0)
{
ERR("start failed: %s\n", snd_strerror(err));
continue;
}
}
- if(snd_pcm_wait(self->mPcmHandle, 1000) == 0)
+ if(snd_pcm_wait(mPcmHandle, 1000) == 0)
ERR("Wait timeout... buffer size too low?\n");
continue;
}
- ALCplaybackAlsa_lock(self);
- char *WritePtr{self->mBuffer.data()};
- avail = snd_pcm_bytes_to_frames(self->mPcmHandle, self->mBuffer.size());
- aluMixData(device, WritePtr, avail);
+ ALCplaybackAlsa_lock(this);
+ char *WritePtr{mBuffer.data()};
+ avail = snd_pcm_bytes_to_frames(mPcmHandle, mBuffer.size());
+ aluMixData(mDevice, WritePtr, avail);
while(avail > 0)
{
- int ret = snd_pcm_writei(self->mPcmHandle, WritePtr, avail);
- switch (ret)
+ snd_pcm_sframes_t ret{snd_pcm_writei(mPcmHandle, WritePtr, avail)};
+ switch(ret)
{
case -EAGAIN:
continue;
@@ -621,26 +617,25 @@ int ALCplaybackAlsa_mixerNoMMapProc(ALCplaybackAlsa *self)
#endif
case -EPIPE:
case -EINTR:
- ret = snd_pcm_recover(self->mPcmHandle, ret, 1);
+ ret = snd_pcm_recover(mPcmHandle, ret, 1);
if(ret < 0)
avail = 0;
break;
default:
- if (ret >= 0)
+ if(ret >= 0)
{
- WritePtr += snd_pcm_frames_to_bytes(self->mPcmHandle, ret);
+ WritePtr += snd_pcm_frames_to_bytes(mPcmHandle, ret);
avail -= ret;
}
break;
}
- if (ret < 0)
+ if(ret < 0)
{
- ret = snd_pcm_prepare(self->mPcmHandle);
- if(ret < 0)
- break;
+ ret = snd_pcm_prepare(mPcmHandle);
+ if(ret < 0) break;
}
}
- ALCplaybackAlsa_unlock(self);
+ ALCplaybackAlsa_unlock(this);
}
return 0;
@@ -841,7 +836,6 @@ error:
ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
{
ALCdevice *device{self->mDevice};
- int (*thread_func)(ALCplaybackAlsa*){};
snd_pcm_hw_params_t *hp{};
snd_pcm_access_t access;
const char *funcerr;
@@ -853,13 +847,21 @@ ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
/* retrieve configuration info */
CHECK(snd_pcm_hw_params_get_access(hp, &access));
#undef CHECK
+ if(0)
+ {
+ error:
+ ERR("%s failed: %s\n", funcerr, snd_strerror(err));
+ if(hp) snd_pcm_hw_params_free(hp);
+ return ALC_FALSE;
+ }
snd_pcm_hw_params_free(hp);
hp = nullptr;
+ int (ALCplaybackAlsa::*thread_func)(){};
if(access == SND_PCM_ACCESS_RW_INTERLEAVED)
{
self->mBuffer.resize(snd_pcm_frames_to_bytes(self->mPcmHandle, device->UpdateSize));
- thread_func = ALCplaybackAlsa_mixerNoMMapProc;
+ thread_func = &ALCplaybackAlsa::mixerNoMMapProc;
}
else
{
@@ -869,12 +871,12 @@ ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
ERR("snd_pcm_prepare(data->mPcmHandle) failed: %s\n", snd_strerror(err));
return ALC_FALSE;
}
- thread_func = ALCplaybackAlsa_mixerProc;
+ thread_func = &ALCplaybackAlsa::mixerProc;
}
try {
self->mKillNow.store(AL_FALSE, std::memory_order_release);
- self->mThread = std::thread(thread_func, self);
+ self->mThread = std::thread{std::mem_fn(thread_func), self};
return ALC_TRUE;
}
catch(std::exception& e) {
@@ -884,11 +886,6 @@ ALCboolean ALCplaybackAlsa_start(ALCplaybackAlsa *self)
}
self->mBuffer.clear();
return ALC_FALSE;
-
-error:
- ERR("%s failed: %s\n", funcerr, snd_strerror(err));
- if(hp) snd_pcm_hw_params_free(hp);
- return ALC_FALSE;
}
void ALCplaybackAlsa_stop(ALCplaybackAlsa *self)
@@ -924,6 +921,8 @@ ClockLatency ALCplaybackAlsa_getClockLatency(ALCplaybackAlsa *self)
struct ALCcaptureAlsa final : public ALCbackend {
+ ALCcaptureAlsa(ALCdevice *device) noexcept : ALCbackend{device} { }
+
snd_pcm_t *mPcmHandle{nullptr};
al::vector<char> mBuffer;
@@ -932,8 +931,6 @@ struct ALCcaptureAlsa final : public ALCbackend {
RingBufferPtr mRing{nullptr};
snd_pcm_sframes_t mLastAvail{0};
-
- ALCcaptureAlsa(ALCdevice *device) noexcept : ALCbackend{device} { }
};
void ALCcaptureAlsa_Construct(ALCcaptureAlsa *self, ALCdevice *device);
diff --git a/Alc/backends/coreaudio.cpp b/Alc/backends/coreaudio.cpp
index 62a88da1..9af370ca 100644
--- a/Alc/backends/coreaudio.cpp
+++ b/Alc/backends/coreaudio.cpp
@@ -36,16 +36,25 @@
#include <AudioToolbox/AudioToolbox.h>
+namespace {
+
static const ALCchar ca_device[] = "CoreAudio Default";
struct ALCcoreAudioPlayback final : public ALCbackend {
+ ALCcoreAudioPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
+
+ static OSStatus MixerProcC(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames,
+ AudioBufferList *ioData);
+ OSStatus MixerProc(AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames,
+ AudioBufferList *ioData);
+
AudioUnit mAudioUnit;
ALuint mFrameSize{0u};
AudioStreamBasicDescription mFormat{}; // This is the OpenAL format as a CoreAudio ASBD
-
- ALCcoreAudioPlayback(ALCdevice *device) noexcept : ALCbackend{device} { }
};
static void ALCcoreAudioPlayback_Construct(ALCcoreAudioPlayback *self, ALCdevice *device);
@@ -79,34 +88,34 @@ static void ALCcoreAudioPlayback_Destruct(ALCcoreAudioPlayback *self)
}
-static OSStatus ALCcoreAudioPlayback_MixerProc(void *inRefCon,
- AudioUnitRenderActionFlags* UNUSED(ioActionFlags), const AudioTimeStamp* UNUSED(inTimeStamp),
- UInt32 UNUSED(inBusNumber), UInt32 UNUSED(inNumberFrames), AudioBufferList *ioData)
+OSStatus ALCcoreAudioPlayback::MixerProcC(void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
{
- auto self = static_cast<ALCcoreAudioPlayback*>(inRefCon);
-
- ALCcoreAudioPlayback_lock(self);
- aluMixData(self->mDevice, ioData->mBuffers[0].mData,
- ioData->mBuffers[0].mDataByteSize / self->mFrameSize);
- ALCcoreAudioPlayback_unlock(self);
+ return static_cast<ALCcoreAudioPlayback*>(inRefCon)->MixerProc(ioActionFlags, inTimeStamp,
+ inBusNumber, inNumberFrames, ioData);
+}
+OSStatus ALCcoreAudioPlayback::MixerProc(AudioUnitRenderActionFlags* UNUSED(ioActionFlags),
+ const AudioTimeStamp* UNUSED(inTimeStamp), UInt32 UNUSED(inBusNumber),
+ UInt32 UNUSED(inNumberFrames), AudioBufferList *ioData)
+{
+ ALCcoreAudioPlayback_lock(this);
+ aluMixData(mDevice, ioData->mBuffers[0].mData, ioData->mBuffers[0].mDataByteSize/mFrameSize);
+ ALCcoreAudioPlayback_unlock(this);
return noErr;
}
static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCchar *name)
{
- ALCdevice *device{self->mDevice};
- AudioComponentDescription desc;
- AudioComponent comp;
- OSStatus err;
-
if(!name)
name = ca_device;
else if(strcmp(name, ca_device) != 0)
return ALC_INVALID_VALUE;
/* open the default output unit */
+ AudioComponentDescription desc{};
desc.componentType = kAudioUnitType_Output;
#if TARGET_OS_IOS
desc.componentSubType = kAudioUnitSubType_RemoteIO;
@@ -117,14 +126,14 @@ static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCch
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
- comp = AudioComponentFindNext(NULL, &desc);
- if(comp == NULL)
+ AudioComponent comp{AudioComponentFindNext(NULL, &desc)};
+ if(comp == nullptr)
{
ERR("AudioComponentFindNext failed\n");
return ALC_INVALID_VALUE;
}
- err = AudioComponentInstanceNew(comp, &self->mAudioUnit);
+ OSStatus err{AudioComponentInstanceNew(comp, &self->mAudioUnit)};
if(err != noErr)
{
ERR("AudioComponentInstanceNew failed\n");
@@ -140,6 +149,7 @@ static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCch
return ALC_INVALID_VALUE;
}
+ ALCdevice *device{self->mDevice};
device->DeviceName = name;
return ALC_NO_ERROR;
}
@@ -147,17 +157,14 @@ static ALCenum ALCcoreAudioPlayback_open(ALCcoreAudioPlayback *self, const ALCch
static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self)
{
ALCdevice *device{self->mDevice};
- AudioStreamBasicDescription streamFormat;
- AURenderCallbackStruct input;
- OSStatus err;
- UInt32 size;
- err = AudioUnitUninitialize(self->mAudioUnit);
+ OSStatus err{AudioUnitUninitialize(self->mAudioUnit)};
if(err != noErr)
ERR("-- AudioUnitUninitialize failed.\n");
/* retrieve default output unit's properties (output side) */
- size = sizeof(AudioStreamBasicDescription);
+ AudioStreamBasicDescription streamFormat{};
+ auto size = static_cast<UInt32>(sizeof(AudioStreamBasicDescription));
err = AudioUnitGetProperty(self->mAudioUnit, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output, 0, &streamFormat, &size);
if(err != noErr || size != sizeof(AudioStreamBasicDescription))
@@ -187,9 +194,8 @@ static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self)
if(device->Frequency != streamFormat.mSampleRate)
{
- device->NumUpdates = (ALuint)((ALuint64)device->NumUpdates *
- streamFormat.mSampleRate /
- device->Frequency);
+ device->NumUpdates = static_cast<ALuint>(
+ (ALuint64)device->NumUpdates*streamFormat.mSampleRate/device->Frequency);
device->Frequency = streamFormat.mSampleRate;
}
@@ -272,7 +278,8 @@ static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self)
/* setup callback */
self->mFrameSize = device->frameSizeFromFmt();
- input.inputProc = ALCcoreAudioPlayback_MixerProc;
+ AURenderCallbackStruct input{};
+ input.inputProc = ALCcoreAudioPlayback::MixerProcC;
input.inputProcRefCon = self;
err = AudioUnitSetProperty(self->mAudioUnit, kAudioUnitProperty_SetRenderCallback,
@@ -296,25 +303,33 @@ static ALCboolean ALCcoreAudioPlayback_reset(ALCcoreAudioPlayback *self)
static ALCboolean ALCcoreAudioPlayback_start(ALCcoreAudioPlayback *self)
{
- OSStatus err = AudioOutputUnitStart(self->mAudioUnit);
+ OSStatus err{AudioOutputUnitStart(self->mAudioUnit)};
if(err != noErr)
{
ERR("AudioOutputUnitStart failed\n");
return ALC_FALSE;
}
-
return ALC_TRUE;
}
static void ALCcoreAudioPlayback_stop(ALCcoreAudioPlayback *self)
{
- OSStatus err = AudioOutputUnitStop(self->mAudioUnit);
+ OSStatus err{AudioOutputUnitStop(self->mAudioUnit)};
if(err != noErr)
ERR("AudioOutputUnitStop failed\n");
}
struct ALCcoreAudioCapture final : public ALCbackend {
+ ALCcoreAudioCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
+
+ static OSStatus RecordProcC(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames,
+ AudioBufferList *ioData);
+ OSStatus RecordProc(AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber,
+ UInt32 inNumberFrames, AudioBufferList *ioData);
+
AudioUnit mAudioUnit{0};
ALuint mFrameSize{0u};
@@ -323,8 +338,6 @@ struct ALCcoreAudioCapture final : public ALCbackend {
SampleConverterPtr mConverter;
RingBufferPtr mRing{nullptr};
-
- ALCcoreAudioCapture(ALCdevice *device) noexcept : ALCbackend{device} { }
};
static void ALCcoreAudioCapture_Construct(ALCcoreAudioCapture *self, ALCdevice *device);
@@ -359,30 +372,34 @@ static void ALCcoreAudioCapture_Destruct(ALCcoreAudioCapture *self)
}
-static OSStatus ALCcoreAudioCapture_RecordProc(void *inRefCon,
- AudioUnitRenderActionFlags* UNUSED(ioActionFlags),
- const AudioTimeStamp *inTimeStamp, UInt32 UNUSED(inBusNumber),
- UInt32 inNumberFrames, AudioBufferList* UNUSED(ioData))
+OSStatus ALCcoreAudioCapture::RecordProcC(void *inRefCon,
+ AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp,
+ UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData)
+{
+ return static_cast<ALCcoreAudioCapture*>(inRefCon)->RecordProc(ioActionFlags, inTimeStamp,
+ inBusNumber, inNumberFrames, ioData);
+}
+
+OSStatus ALCcoreAudioCapture::RecordProc(AudioUnitRenderActionFlags *ioActionFlags,
+ const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumberFrames,
+ AudioBufferList *ioData)
{
- auto self = static_cast<ALCcoreAudioCapture*>(inRefCon);
- RingBuffer *ring{self->mRing.get()};
AudioUnitRenderActionFlags flags = 0;
union {
ALbyte _[sizeof(AudioBufferList) + sizeof(AudioBuffer)];
AudioBufferList list;
} audiobuf = { { 0 } };
- OSStatus err;
- auto rec_vec = ring->getWriteVector();
+ auto rec_vec = mRing->getWriteVector();
// Fill the ringbuffer's first segment with data from the input device
size_t total_read{minz(rec_vec.first.len, inNumberFrames)};
audiobuf.list.mNumberBuffers = 1;
- audiobuf.list.mBuffers[0].mNumberChannels = self->mFormat.mChannelsPerFrame;
+ audiobuf.list.mBuffers[0].mNumberChannels = mFormat.mChannelsPerFrame;
audiobuf.list.mBuffers[0].mData = rec_vec.first.buf;
- audiobuf.list.mBuffers[0].mDataByteSize = total_read * self->mFormat.mBytesPerFrame;
- err = AudioUnitRender(self->mAudioUnit, &flags, inTimeStamp, 1, inNumberFrames,
- &audiobuf.list);
+ audiobuf.list.mBuffers[0].mDataByteSize = total_read * mFormat.mBytesPerFrame;
+ OSStatus err{AudioUnitRender(mAudioUnit, &flags, inTimeStamp, 1, inNumberFrames,
+ &audiobuf.list)};
if(err == noErr && inNumberFrames > rec_vec.first.len && rec_vec.second.len > 0)
{
/* If there's still more to get and there's space in the ringbuffer's
@@ -393,11 +410,10 @@ static OSStatus ALCcoreAudioCapture_RecordProc(void *inRefCon,
total_read += toread;
audiobuf.list.mNumberBuffers = 1;
- audiobuf.list.mBuffers[0].mNumberChannels = self->mFormat.mChannelsPerFrame;
+ audiobuf.list.mBuffers[0].mNumberChannels = mFormat.mChannelsPerFrame;
audiobuf.list.mBuffers[0].mData = rec_vec.second.buf;
- audiobuf.list.mBuffers[0].mDataByteSize = toread * self->mFormat.mBytesPerFrame;
- err = AudioUnitRender(self->mAudioUnit, &flags, inTimeStamp, 1, inNumberFrames,
- &audiobuf.list);
+ audiobuf.list.mBuffers[0].mDataByteSize = toread * mFormat.mBytesPerFrame;
+ err = AudioUnitRender(mAudioUnit, &flags, inTimeStamp, 1, inNumberFrames, &audiobuf.list);
}
if(err != noErr)
{
@@ -405,7 +421,7 @@ static OSStatus ALCcoreAudioCapture_RecordProc(void *inRefCon,
return err;
}
- ring->writeAdvance(total_read);
+ mRing->writeAdvance(total_read);
return noErr;
}
@@ -510,7 +526,7 @@ static ALCenum ALCcoreAudioCapture_open(ALCcoreAudioCapture *self, const ALCchar
#endif
// set capture callback
- input.inputProc = ALCcoreAudioCapture_RecordProc;
+ input.inputProc = ALCcoreAudioCapture::RecordProcC;
input.inputProcRefCon = self;
err = AudioUnitSetProperty(self->mAudioUnit, kAudioOutputUnitProperty_SetInputCallback,
@@ -646,7 +662,7 @@ static ALCenum ALCcoreAudioCapture_open(ALCcoreAudioCapture *self, const ALCchar
static ALCboolean ALCcoreAudioCapture_start(ALCcoreAudioCapture *self)
{
- OSStatus err = AudioOutputUnitStart(self->mAudioUnit);
+ OSStatus err{AudioOutputUnitStart(self->mAudioUnit)};
if(err != noErr)
{
ERR("AudioOutputUnitStart failed\n");
@@ -657,7 +673,7 @@ static ALCboolean ALCcoreAudioCapture_start(ALCcoreAudioCapture *self)
static void ALCcoreAudioCapture_stop(ALCcoreAudioCapture *self)
{
- OSStatus err = AudioOutputUnitStop(self->mAudioUnit);
+ OSStatus err{AudioOutputUnitStop(self->mAudioUnit)};
if(err != noErr)
ERR("AudioOutputUnitStop failed\n");
}
@@ -699,6 +715,7 @@ static ALCuint ALCcoreAudioCapture_availableSamples(ALCcoreAudioCapture *self)
return SampleConverterAvailableOut(self->mConverter.get(), ring->readSpace());
}
+} // namespace
BackendFactory &CoreAudioBackendFactory::getFactory()
{