aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends/opensl.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-04-08 21:46:30 -0700
committerChris Robinson <[email protected]>2022-04-08 21:46:30 -0700
commit2fb7538f6860086a8b6dbfbcf983ed2dffb71edd (patch)
tree2b449b803e9b1672e43670679751ffcd28bd14b8 /alc/backends/opensl.cpp
parenta42fe862c54bcaa4cfe39cfcf4de8a4c0f3eab14 (diff)
Clear capture buffers before enqueueing them with OpenSL
Diffstat (limited to 'alc/backends/opensl.cpp')
-rw-r--r--alc/backends/opensl.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp
index 5ba95e4c..85a5f483 100644
--- a/alc/backends/opensl.cpp
+++ b/alc/backends/opensl.cpp
@@ -810,8 +810,11 @@ void OpenSLCapture::open(const char* name)
if(SL_RESULT_SUCCESS == result)
{
const uint chunk_size{mDevice->UpdateSize * mFrameSize};
+ const auto silence = (mDevice->FmtType == DevFmtUByte) ? al::byte{0x80} : al::byte{0};
auto data = mRing->getWriteVector();
+ std::fill_n(data.first.buf, data.first.len*chunk_size, silence);
+ std::fill_n(data.second.buf, data.second.len*chunk_size, silence);
for(size_t i{0u};i < data.first.len && SL_RESULT_SUCCESS == result;i++)
{
result = VCALL(bufferQueue,Enqueue)(data.first.buf + chunk_size*i, chunk_size);
@@ -875,6 +878,7 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
{
const uint update_size{mDevice->UpdateSize};
const uint chunk_size{update_size * mFrameSize};
+ const auto silence = (mDevice->FmtType == DevFmtUByte) ? al::byte{0x80} : al::byte{0};
/* Read the desired samples from the ring buffer then advance its read
* pointer.
@@ -922,15 +926,20 @@ void OpenSLCapture::captureSamples(al::byte *buffer, uint samples)
{
SLresult result{SL_RESULT_SUCCESS};
auto wdata = mRing->getWriteVector();
+ std::fill_n(wdata.first.buf, wdata.first.len*chunk_size, silence);
for(size_t i{0u};i < wdata.first.len && SL_RESULT_SUCCESS == result;i++)
{
result = VCALL(bufferQueue,Enqueue)(wdata.first.buf + chunk_size*i, chunk_size);
PRINTERR(result, "bufferQueue->Enqueue");
}
- for(size_t i{0u};i < wdata.second.len && SL_RESULT_SUCCESS == result;i++)
+ if(wdata.second.len > 0)
{
- result = VCALL(bufferQueue,Enqueue)(wdata.second.buf + chunk_size*i, chunk_size);
- PRINTERR(result, "bufferQueue->Enqueue");
+ std::fill_n(wdata.second.buf, wdata.second.len*chunk_size, silence);
+ for(size_t i{0u};i < wdata.second.len && SL_RESULT_SUCCESS == result;i++)
+ {
+ result = VCALL(bufferQueue,Enqueue)(wdata.second.buf + chunk_size*i, chunk_size);
+ PRINTERR(result, "bufferQueue->Enqueue");
+ }
}
}
}