diff options
author | Chris Robinson <chris.kcat@gmail.com> | 2019-04-26 15:58:25 -0700 |
---|---|---|
committer | Chris Robinson <chris.kcat@gmail.com> | 2019-04-26 15:58:25 -0700 |
commit | f23ff0394d8ae58dc12f8d1076fe5cd9dfde383d (patch) | |
tree | 6ab98ccc85c76eb77bf8c533cdaae179fb0b6bd4 /Alc/backends/dsound.cpp | |
parent | 348e01dc4bc16ac4543d54b722fb46dbdebcb1e3 (diff) |
Specify the buffer size as itself instead of the period count
Certain backends don't need a buffer size to be a strict multiple of the period
count, which allows a little more flexibility. The period/update size simply
acts as the minimum request, which helps control CPU load by determining how
often parameter and other pre-mixing updates are processed.
Diffstat (limited to 'Alc/backends/dsound.cpp')
-rw-r--r-- | Alc/backends/dsound.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Alc/backends/dsound.cpp b/Alc/backends/dsound.cpp index 00deafc1..38b1b9f8 100644 --- a/Alc/backends/dsound.cpp +++ b/Alc/backends/dsound.cpp @@ -496,19 +496,16 @@ retry_open: if(SUCCEEDED(hr)) { - if(mDevice->NumUpdates > MAX_UPDATES) - { - mDevice->UpdateSize = (mDevice->UpdateSize*mDevice->NumUpdates + MAX_UPDATES-1) / - MAX_UPDATES; - mDevice->NumUpdates = MAX_UPDATES; - } + ALuint num_updates{mDevice->BufferSize / mDevice->UpdateSize}; + if(num_updates > MAX_UPDATES) + num_updates = MAX_UPDATES; + mDevice->BufferSize = mDevice->UpdateSize * num_updates; DSBUFFERDESC DSBDescription{}; DSBDescription.dwSize = sizeof(DSBDescription); DSBDescription.dwFlags = DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; - DSBDescription.dwBufferBytes = mDevice->UpdateSize * mDevice->NumUpdates * - OutputType.Format.nBlockAlign; + DSBDescription.dwBufferBytes = mDevice->BufferSize * OutputType.Format.nBlockAlign; DSBDescription.lpwfxFormat = &OutputType.Format; hr = mDS->CreateSoundBuffer(&DSBDescription, &mBuffer, nullptr); @@ -528,15 +525,16 @@ retry_open: auto Notifies = static_cast<IDirectSoundNotify*>(ptr); mNotifies = Notifies; - mDevice->NumUpdates = minu(mDevice->NumUpdates, MAX_UPDATES); + ALuint num_updates{mDevice->BufferSize / mDevice->UpdateSize}; + assert(num_updates <= MAX_UPDATES); std::array<DSBPOSITIONNOTIFY,MAX_UPDATES> nots; - for(ALuint i{0};i < mDevice->NumUpdates;++i) + for(ALuint i{0};i < num_updates;++i) { nots[i].dwOffset = i * mDevice->UpdateSize * OutputType.Format.nBlockAlign; nots[i].hEventNotify = mNotifyEvent; } - if(Notifies->SetNotificationPositions(mDevice->NumUpdates, nots.data()) != DS_OK) + if(Notifies->SetNotificationPositions(num_updates, nots.data()) != DS_OK) hr = E_FAIL; } } @@ -743,7 +741,7 @@ ALCenum DSoundCapture::open(const ALCchar *name) InputType.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX); } - ALuint samples{mDevice->UpdateSize * mDevice->NumUpdates}; + ALuint samples{mDevice->BufferSize}; samples = maxu(samples, 100 * mDevice->Frequency / 1000); DSCBUFFERDESC DSCBDescription{}; @@ -758,8 +756,7 @@ ALCenum DSoundCapture::open(const ALCchar *name) mDSC->CreateCaptureBuffer(&DSCBDescription, &mDSCbuffer, nullptr); if(SUCCEEDED(hr)) { - mRing = CreateRingBuffer(mDevice->UpdateSize*mDevice->NumUpdates, - InputType.Format.nBlockAlign, false); + mRing = CreateRingBuffer(mDevice->BufferSize, InputType.Format.nBlockAlign, false); if(!mRing) hr = DSERR_OUTOFMEMORY; } |