diff options
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alc.cpp | 2 | ||||
-rw-r--r-- | alc/backends/alsa.cpp | 2 | ||||
-rw-r--r-- | alc/backends/coreaudio.cpp | 2 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 2 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 4 | ||||
-rw-r--r-- | alc/backends/opensl.cpp | 4 | ||||
-rw-r--r-- | alc/backends/oss.cpp | 2 | ||||
-rw-r--r-- | alc/backends/portaudio.cpp | 2 | ||||
-rw-r--r-- | alc/backends/sndio.cpp | 2 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 2 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 4 | ||||
-rw-r--r-- | alc/ringbuffer.cpp | 2 | ||||
-rw-r--r-- | alc/ringbuffer.h | 18 |
13 files changed, 25 insertions, 23 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index a8a34b8d..b077e796 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2560,7 +2560,7 @@ void ALCcontext::init() mListener.Params.mDistanceModel = mDistanceModel; - mAsyncEvents = CreateRingBuffer(511, sizeof(AsyncEvent), false); + mAsyncEvents = RingBuffer::Create(511, sizeof(AsyncEvent), false); StartEventThrd(this); diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 236e7a2f..a011d720 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -987,7 +987,7 @@ void AlsaCapture::open(const ALCchar *name) hp = nullptr; if(needring) - mRing = CreateRingBuffer(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false); + mRing = RingBuffer::Create(mDevice->BufferSize, mDevice->frameSizeFromFmt(), false); mDevice->DeviceName = name; } diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index a8527bed..9948d11c 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -570,7 +570,7 @@ void CoreAudioCapture::open(const ALCchar *name) mFormat.mChannelsPerFrame, static_cast<ALuint>(hardwareFormat.mSampleRate), mDevice->Frequency, Resampler::FastBSinc24); - mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false); + mRing = RingBuffer::Create(outputFrameCount, mFrameSize, false); mDevice->DeviceName = name; } diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index 69fb5fb0..cee5a20a 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -743,7 +743,7 @@ void DSoundCapture::open(const ALCchar *name) if(SUCCEEDED(hr)) mDSC->CreateCaptureBuffer(&DSCBDescription, &mDSCbuffer, nullptr); if(SUCCEEDED(hr)) - mRing = CreateRingBuffer(mDevice->BufferSize, InputType.Format.nBlockAlign, false); + mRing = RingBuffer::Create(mDevice->BufferSize, InputType.Format.nBlockAlign, false); if(FAILED(hr)) { diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index 2be52e35..4d28731c 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -211,7 +211,7 @@ int JackPlayback::bufferSizeNotify(jack_nframes_t numframes) noexcept TRACE("%u / %u buffer\n", mDevice->UpdateSize, mDevice->BufferSize); mRing = nullptr; - mRing = CreateRingBuffer(bufsize, mDevice->frameSizeFromFmt(), true); + mRing = RingBuffer::Create(bufsize, mDevice->frameSizeFromFmt(), true); return 0; } @@ -404,7 +404,7 @@ bool JackPlayback::reset() } mRing = nullptr; - mRing = CreateRingBuffer(bufsize, mDevice->frameSizeFromFmt(), true); + mRing = RingBuffer::Create(bufsize, mDevice->frameSizeFromFmt(), true); SetDefaultChannelOrder(mDevice); diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index ab2b8c2c..aafba2c8 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -523,7 +523,7 @@ bool OpenSLPlayback::reset() if(SL_RESULT_SUCCESS == result) { const ALuint num_updates{mDevice->BufferSize / mDevice->UpdateSize}; - mRing = CreateRingBuffer(num_updates, mFrameSize*mDevice->UpdateSize, true); + mRing = RingBuffer::Create(num_updates, mFrameSize*mDevice->UpdateSize, true); } if(SL_RESULT_SUCCESS != result) @@ -698,7 +698,7 @@ void OpenSLCapture::open(const ALCchar* name) mDevice->Frequency/100*5)}; ALuint num_updates{(length+update_len-1) / update_len}; - mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false); + mRing = RingBuffer::Create(num_updates, update_len*mFrameSize, false); mDevice->UpdateSize = update_len; mDevice->BufferSize = static_cast<ALuint>(mRing->writeSpace() * update_len); diff --git a/alc/backends/oss.cpp b/alc/backends/oss.cpp index b3f8936a..74bdbb11 100644 --- a/alc/backends/oss.cpp +++ b/alc/backends/oss.cpp @@ -612,7 +612,7 @@ void OSScapture::open(const ALCchar *name) "Failed to set %s samples, got OSS format %#x", DevFmtTypeString(mDevice->FmtType), ossFormat}; - mRing = CreateRingBuffer(mDevice->BufferSize, frameSize, false); + mRing = RingBuffer::Create(mDevice->BufferSize, frameSize, false); mDevice->DeviceName = name; } diff --git a/alc/backends/portaudio.cpp b/alc/backends/portaudio.cpp index 5de9ab58..0f5d6d6d 100644 --- a/alc/backends/portaudio.cpp +++ b/alc/backends/portaudio.cpp @@ -284,7 +284,7 @@ void PortCapture::open(const ALCchar *name) samples = maxu(samples, 100 * mDevice->Frequency / 1000); ALuint frame_size{mDevice->frameSizeFromFmt()}; - mRing = CreateRingBuffer(samples, frame_size, false); + mRing = RingBuffer::Create(samples, frame_size, false); auto devidopt = ConfigValueInt(nullptr, "port", "capture"); if(devidopt && *devidopt >= 0) mParams.device = *devidopt; diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 4d851391..0ca7062d 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -393,7 +393,7 @@ void SndioCapture::open(const ALCchar *name) DevFmtTypeString(mDevice->FmtType), DevFmtChannelsString(mDevice->FmtChans), mDevice->Frequency, par.sig?'s':'u', par.bits, par.rchan, par.rate}; - mRing = CreateRingBuffer(mDevice->BufferSize, par.bps*par.rchan, false); + mRing = RingBuffer::Create(mDevice->BufferSize, par.bps*par.rchan, false); SetDefaultChannelOrder(mDevice); diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index 6ef9adcd..f97c8636 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -1627,7 +1627,7 @@ HRESULT WasapiCapture::resetProxy() mDevice->UpdateSize = RefTime2Samples(min_per, mDevice->Frequency); mDevice->BufferSize = buffer_len; - mRing = CreateRingBuffer(buffer_len, mDevice->frameSizeFromFmt(), false); + mRing = RingBuffer::Create(buffer_len, mDevice->frameSizeFromFmt(), false); hr = mClient->SetEventHandle(mNotifyEvent); if(FAILED(hr)) diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index 82625e1f..53a58d0e 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -520,11 +520,11 @@ void WinMMCapture::open(const ALCchar *name) ALuint CapturedDataSize{mDevice->BufferSize}; CapturedDataSize = static_cast<ALuint>(maxz(CapturedDataSize, BufferSize*mWaveBuffer.size())); - mRing = CreateRingBuffer(CapturedDataSize, mFormat.nBlockAlign, false); + mRing = RingBuffer::Create(CapturedDataSize, mFormat.nBlockAlign, false); al_free(mWaveBuffer[0].lpData); mWaveBuffer[0] = WAVEHDR{}; - mWaveBuffer[0].lpData = static_cast<char*>(al_calloc(16, BufferSize*4)); + mWaveBuffer[0].lpData = static_cast<char*>(al_calloc(16, BufferSize * mWaveBuffer.size())); mWaveBuffer[0].dwBufferLength = BufferSize; for(size_t i{1};i < mWaveBuffer.size();++i) { diff --git a/alc/ringbuffer.cpp b/alc/ringbuffer.cpp index 1f72f4b1..2918ce97 100644 --- a/alc/ringbuffer.cpp +++ b/alc/ringbuffer.cpp @@ -30,7 +30,7 @@ #include "almalloc.h" -RingBufferPtr CreateRingBuffer(size_t sz, size_t elem_sz, int limit_writes) +RingBufferPtr RingBuffer::Create(size_t sz, size_t elem_sz, int limit_writes) { size_t power_of_two{0u}; if(sz > 0) diff --git a/alc/ringbuffer.h b/alc/ringbuffer.h index 3151fdcb..78bea846 100644 --- a/alc/ringbuffer.h +++ b/alc/ringbuffer.h @@ -25,6 +25,7 @@ using ll_ringbuffer_data_pair = std::pair<ll_ringbuffer_data,ll_ringbuffer_data> struct RingBuffer { +private: std::atomic<size_t> mWritePtr{0u}; std::atomic<size_t> mReadPtr{0u}; size_t mWriteSize{0u}; @@ -33,6 +34,7 @@ struct RingBuffer { al::FlexArray<al::byte, 16> mBuffer; +public: RingBuffer(const size_t count) : mBuffer{count} { } /** Reset the read and write pointers to zero. This is not thread safe. */ @@ -82,16 +84,16 @@ struct RingBuffer { /** Advance the write pointer `cnt' places. */ void writeAdvance(size_t cnt) noexcept; + /** + * Create a new ringbuffer to hold at least `sz' elements of `elem_sz' + * bytes. The number of elements is rounded up to the next power of two + * (even if it is already a power of two, to ensure the requested amount + * can be written). + */ + static std::unique_ptr<RingBuffer> Create(size_t sz, size_t elem_sz, int limit_writes); + DEF_FAM_NEWDEL(RingBuffer, mBuffer) }; using RingBufferPtr = std::unique_ptr<RingBuffer>; - -/** - * Create a new ringbuffer to hold at least `sz' elements of `elem_sz' bytes. - * The number of elements is rounded up to the next power of two (even if it is - * already a power of two, to ensure the requested amount can be written). - */ -RingBufferPtr CreateRingBuffer(size_t sz, size_t elem_sz, int limit_writes); - #endif /* RINGBUFFER_H */ |