Make CreateRingBuffer a static RingBuffer method
This commit is contained in:
parent
b31886ad73
commit
e6e2f509f8
@ -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);
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user