diff options
author | Chris Robinson <[email protected]> | 2018-11-19 04:46:49 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-19 04:46:49 -0800 |
commit | ad5f9d9b22f8860f0c6ca06004c134182dda95df (patch) | |
tree | aac46dac1585e5f58ba8bc1be6bb06d3a36e9ab6 /Alc/backends | |
parent | a14f39ea06a458e6b3b70e0428264967847da7f4 (diff) |
Return the ringbuffer data pointers as a pair
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/alsa.cpp | 9 | ||||
-rw-r--r-- | Alc/backends/jack.cpp | 26 | ||||
-rw-r--r-- | Alc/backends/opensl.cpp | 38 | ||||
-rw-r--r-- | Alc/backends/oss.cpp | 7 | ||||
-rw-r--r-- | Alc/backends/sndio.cpp | 19 | ||||
-rw-r--r-- | Alc/backends/wasapi.cpp | 19 |
6 files changed, 55 insertions, 63 deletions
diff --git a/Alc/backends/alsa.cpp b/Alc/backends/alsa.cpp index b3adfafa..e1e861db 100644 --- a/Alc/backends/alsa.cpp +++ b/Alc/backends/alsa.cpp @@ -1237,12 +1237,11 @@ ALCuint ALCcaptureAlsa_availableSamples(ALCcaptureAlsa *self) while(avail > 0) { - ll_ringbuffer_data_t vec[2]; - ll_ringbuffer_get_write_vector(self->ring, vec); - if(vec[0].len == 0) break; + auto vec = ll_ringbuffer_get_write_vector(self->ring); + if(vec.first.len == 0) break; - snd_pcm_sframes_t amt{std::min<snd_pcm_sframes_t>(vec[0].len, avail)}; - amt = snd_pcm_readi(self->pcmHandle, vec[0].buf, amt); + snd_pcm_sframes_t amt{std::min<snd_pcm_sframes_t>(vec.first.len, avail)}; + amt = snd_pcm_readi(self->pcmHandle, vec.first.buf, amt); if(amt < 0) { ERR("read error: %s\n", snd_strerror(amt)); diff --git a/Alc/backends/jack.cpp b/Alc/backends/jack.cpp index 924e1926..93dbaf13 100644 --- a/Alc/backends/jack.cpp +++ b/Alc/backends/jack.cpp @@ -249,33 +249,32 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg) { ALCjackPlayback *self = static_cast<ALCjackPlayback*>(arg); jack_default_audio_sample_t *out[MAX_OUTPUT_CHANNELS]; - ll_ringbuffer_data_t data[2]; - jack_nframes_t total = 0; + jack_nframes_t total{0}; jack_nframes_t todo; ALsizei i, c, numchans; - ll_ringbuffer_get_read_vector(self->Ring, data); + auto data = ll_ringbuffer_get_read_vector(self->Ring); for(c = 0;c < MAX_OUTPUT_CHANNELS && self->Port[c];c++) out[c] = static_cast<float*>(jack_port_get_buffer(self->Port[c], numframes)); numchans = c; - todo = minu(numframes, data[0].len); + todo = minu(numframes, data.first.len); for(c = 0;c < numchans;c++) { - const ALfloat *RESTRICT in = ((ALfloat*)data[0].buf) + c; + const ALfloat *RESTRICT in = ((ALfloat*)data.first.buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; } total += todo; - todo = minu(numframes-total, data[1].len); + todo = minu(numframes-total, data.second.len); if(todo > 0) { for(c = 0;c < numchans;c++) { - const ALfloat *RESTRICT in = ((ALfloat*)data[1].buf) + c; + const ALfloat *RESTRICT in = ((ALfloat*)data.second.buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; @@ -303,7 +302,6 @@ static int ALCjackPlayback_mixerProc(void *arg) { ALCjackPlayback *self = static_cast<ALCjackPlayback*>(arg); ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; - ll_ringbuffer_data_t data[2]; SetRTPriority(); althrd_setname(MIXER_THREAD_NAME); @@ -322,16 +320,16 @@ static int ALCjackPlayback_mixerProc(void *arg) continue; } - ll_ringbuffer_get_write_vector(self->Ring, data); - todo = data[0].len + data[1].len; + auto data = ll_ringbuffer_get_write_vector(self->Ring); + todo = data.first.len + data.second.len; todo -= todo%device->UpdateSize; - len1 = minu(data[0].len, todo); - len2 = minu(data[1].len, todo-len1); + len1 = minu(data.first.len, todo); + len2 = minu(data.second.len, todo-len1); - aluMixData(device, data[0].buf, len1); + aluMixData(device, data.first.buf, len1); if(len2 > 0) - aluMixData(device, data[1].buf, len2); + aluMixData(device, data.second.buf, len2); ll_ringbuffer_write_advance(self->Ring, todo); } ALCjackPlayback_unlock(self); diff --git a/Alc/backends/opensl.cpp b/Alc/backends/opensl.cpp index 0eb194e0..a53c0759 100644 --- a/Alc/backends/opensl.cpp +++ b/Alc/backends/opensl.cpp @@ -239,7 +239,6 @@ static int ALCopenslPlayback_mixerProc(void *arg) ALCopenslPlayback *self = static_cast<ALCopenslPlayback*>(arg); ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; SLAndroidSimpleBufferQueueItf bufferQueue; - ll_ringbuffer_data_t data[2]; SLPlayItf player; SLresult result; @@ -291,13 +290,12 @@ static int ALCopenslPlayback_mixerProc(void *arg) } } - ll_ringbuffer_get_write_vector(self->mRing, data); + auto data = ll_ringbuffer_get_write_vector(self->mRing); + aluMixData(device, data.first.buf, data.first.len*device->UpdateSize); + if(data.second.len > 0) + aluMixData(device, data.second.buf, data.second.len*device->UpdateSize); - aluMixData(device, data[0].buf, data[0].len*device->UpdateSize); - if(data[1].len > 0) - aluMixData(device, data[1].buf, data[1].len*device->UpdateSize); - - todo = data[0].len+data[1].len; + todo = data.first.len+data.second.len; ll_ringbuffer_write_advance(self->mRing, todo); for(size_t i = 0;i < todo;i++) @@ -869,18 +867,17 @@ static ALCenum ALCopenslCapture_open(ALCopenslCapture *self, const ALCchar *name if(SL_RESULT_SUCCESS == result) { ALsizei chunk_size = device->UpdateSize * self->mFrameSize; - ll_ringbuffer_data_t data[2]; size_t i; - ll_ringbuffer_get_write_vector(self->mRing, data); - for(i = 0;i < data[0].len && SL_RESULT_SUCCESS == result;i++) + auto data = ll_ringbuffer_get_write_vector(self->mRing); + for(i = 0;i < data.first.len && SL_RESULT_SUCCESS == result;i++) { - result = VCALL(bufferQueue,Enqueue)(data[0].buf + chunk_size*i, chunk_size); + result = VCALL(bufferQueue,Enqueue)(data.first.buf + chunk_size*i, chunk_size); PRINTERR(result, "bufferQueue->Enqueue"); } - for(i = 0;i < data[1].len && SL_RESULT_SUCCESS == result;i++) + for(i = 0;i < data.second.len && SL_RESULT_SUCCESS == result;i++) { - result = VCALL(bufferQueue,Enqueue)(data[1].buf + chunk_size*i, chunk_size); + result = VCALL(bufferQueue,Enqueue)(data.second.buf + chunk_size*i, chunk_size); PRINTERR(result, "bufferQueue->Enqueue"); } } @@ -949,7 +946,6 @@ static ALCenum ALCopenslCapture_captureSamples(ALCopenslCapture *self, ALCvoid * ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; ALsizei chunk_size = device->UpdateSize * self->mFrameSize; SLAndroidSimpleBufferQueueItf bufferQueue; - ll_ringbuffer_data_t data[2]; SLresult result; ALCuint i; @@ -960,12 +956,12 @@ static ALCenum ALCopenslCapture_captureSamples(ALCopenslCapture *self, ALCvoid * /* Read the desired samples from the ring buffer then advance its read * pointer. */ - ll_ringbuffer_get_read_vector(self->mRing, data); + auto data = ll_ringbuffer_get_read_vector(self->mRing); for(i = 0;i < samples;) { ALCuint rem = minu(samples - i, device->UpdateSize - self->mSplOffset); memcpy((ALCbyte*)buffer + i*self->mFrameSize, - data[0].buf + self->mSplOffset*self->mFrameSize, + data.first.buf + self->mSplOffset*self->mFrameSize, rem * self->mFrameSize); self->mSplOffset += rem; @@ -975,15 +971,15 @@ static ALCenum ALCopenslCapture_captureSamples(ALCopenslCapture *self, ALCvoid * self->mSplOffset = 0; ll_ringbuffer_read_advance(self->mRing, 1); - result = VCALL(bufferQueue,Enqueue)(data[0].buf, chunk_size); + result = VCALL(bufferQueue,Enqueue)(data.first.buf, chunk_size); PRINTERR(result, "bufferQueue->Enqueue"); if(SL_RESULT_SUCCESS != result) break; - data[0].len--; - if(!data[0].len) - data[0] = data[1]; + data.first.len--; + if(!data.first.len) + data.first = data.second; else - data[0].buf += chunk_size; + data.first.buf += chunk_size; } i += rem; diff --git a/Alc/backends/oss.cpp b/Alc/backends/oss.cpp index 32ee1022..3985cd27 100644 --- a/Alc/backends/oss.cpp +++ b/Alc/backends/oss.cpp @@ -582,11 +582,10 @@ int ALCcaptureOSS_recordProc(ALCcaptureOSS *self) continue; } - ll_ringbuffer_data_t vec[2]; - ll_ringbuffer_get_write_vector(self->ring, vec); - if(vec[0].len > 0) + auto vec = ll_ringbuffer_get_write_vector(self->ring); + if(vec.first.len > 0) { - amt = read(self->fd, vec[0].buf, vec[0].len*frame_size); + amt = read(self->fd, vec.first.buf, vec.first.len*frame_size); if(amt < 0) { ERR("read failed: %s\n", strerror(errno)); diff --git a/Alc/backends/sndio.cpp b/Alc/backends/sndio.cpp index cc5eacbe..2a20fb61 100644 --- a/Alc/backends/sndio.cpp +++ b/Alc/backends/sndio.cpp @@ -345,11 +345,10 @@ static int SndioCapture_recordProc(void* ptr) while(!ATOMIC_LOAD(&self->killNow, almemory_order_acquire) && ATOMIC_LOAD(&device->Connected, almemory_order_acquire)) { - ll_ringbuffer_data_t data[2]; size_t total, todo; - ll_ringbuffer_get_write_vector(self->ring, data); - todo = data[0].len + data[1].len; + auto data = ll_ringbuffer_get_write_vector(self->ring); + todo = data.first.len + data.second.len; if(todo == 0) { static char junk[4096]; @@ -358,17 +357,17 @@ static int SndioCapture_recordProc(void* ptr) } total = 0; - data[0].len *= frameSize; - data[1].len *= frameSize; + data.first.len *= frameSize; + data.second.len *= frameSize; todo = minz(todo, device->UpdateSize) * frameSize; while(total < todo) { size_t got; - if(!data[0].len) - data[0] = data[1]; + if(!data.first.len) + data.first = data.second; - got = sio_read(self->sndHandle, data[0].buf, minz(todo-total, data[0].len)); + got = sio_read(self->sndHandle, data.first.buf, minz(todo-total, data.first.len)); if(!got) { SndioCapture_lock(self); @@ -377,8 +376,8 @@ static int SndioCapture_recordProc(void* ptr) break; } - data[0].buf += got; - data[0].len -= got; + data.first.buf += got; + data.first.len -= got; total += got; } ll_ringbuffer_write_advance(self->ring, total / frameSize); diff --git a/Alc/backends/wasapi.cpp b/Alc/backends/wasapi.cpp index 751c56d8..e531a9ae 100644 --- a/Alc/backends/wasapi.cpp +++ b/Alc/backends/wasapi.cpp @@ -1275,8 +1275,7 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self) rdata = reinterpret_cast<BYTE*>(samples.data()); } - ll_ringbuffer_data_t data[2]; - ll_ringbuffer_get_write_vector(self->mRing, data); + auto data = ll_ringbuffer_get_write_vector(self->mRing); size_t dstframes; if(self->mSampleConv) @@ -1285,16 +1284,18 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self) ALsizei srcframes = numsamples; dstframes = SampleConverterInput(self->mSampleConv, - &srcdata, &srcframes, data[0].buf, (ALsizei)minz(data[0].len, INT_MAX) + &srcdata, &srcframes, data.first.buf, + (ALsizei)minz(data.first.len, INT_MAX) ); - if(srcframes > 0 && dstframes == data[0].len && data[1].len > 0) + if(srcframes > 0 && dstframes == data.first.len && data.second.len > 0) { /* If some source samples remain, all of the first dest * block was filled, and there's space in the second * dest block, do another run for the second block. */ dstframes += SampleConverterInput(self->mSampleConv, - &srcdata, &srcframes, data[1].buf, (ALsizei)minz(data[1].len, INT_MAX) + &srcdata, &srcframes, data.second.buf, + (ALsizei)minz(data.second.len, INT_MAX) ); } } @@ -1302,12 +1303,12 @@ FORCE_ALIGN int ALCwasapiCapture_recordProc(ALCwasapiCapture *self) { ALuint framesize = FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->mAmbiOrder); - size_t len1 = minz(data[0].len, numsamples); - size_t len2 = minz(data[1].len, numsamples-len1); + size_t len1 = minz(data.first.len, numsamples); + size_t len2 = minz(data.second.len, numsamples-len1); - memcpy(data[0].buf, rdata, len1*framesize); + memcpy(data.first.buf, rdata, len1*framesize); if(len2 > 0) - memcpy(data[1].buf, rdata+len1*framesize, len2*framesize); + memcpy(data.second.buf, rdata+len1*framesize, len2*framesize); dstframes = len1 + len2; } |