MCPcopy Create free account
hub / github.com/LabSound/LabSound / pushBuffer

Method pushBuffer

src/backends/RtAudio/RtAudio.cpp:4235–4296  ·  view source on GitHub ↗

attempt to push a buffer into the ring buffer at the current "in" index

Source from the content-addressed store, hash-verified

4233
4234 // attempt to push a buffer into the ring buffer at the current "in" index
4235 bool pushBuffer(char * buffer, unsigned int bufferSize, RtAudioFormat format)
4236 {
4237 if (!buffer || // incoming buffer is NULL
4238 bufferSize == 0 || // incoming buffer has no data
4239 bufferSize > bufferSize_) // incoming buffer too large
4240 {
4241 return false;
4242 }
4243
4244 unsigned int relOutIndex = outIndex_;
4245 unsigned int inIndexEnd = inIndex_ + bufferSize;
4246 if (relOutIndex < inIndex_ && inIndexEnd >= bufferSize_)
4247 {
4248 relOutIndex += bufferSize_;
4249 }
4250
4251 // the "IN" index CAN BEGIN at the "OUT" index
4252 // the "IN" index CANNOT END at the "OUT" index
4253 if (inIndex_ < relOutIndex && inIndexEnd >= relOutIndex)
4254 {
4255 return false; // not enough space between "in" index and "out" index
4256 }
4257
4258 // copy buffer from external to internal
4259 int fromZeroSize = inIndex_ + bufferSize - bufferSize_;
4260 fromZeroSize = fromZeroSize < 0 ? 0 : fromZeroSize;
4261 int fromInSize = bufferSize - fromZeroSize;
4262
4263 switch (format)
4264 {
4265 case RTAUDIO_SINT8:
4266 memcpy(&((char *) buffer_)[inIndex_], buffer, fromInSize * sizeof(char));
4267 memcpy(buffer_, &((char *) buffer)[fromInSize], fromZeroSize * sizeof(char));
4268 break;
4269 case RTAUDIO_SINT16:
4270 memcpy(&((short *) buffer_)[inIndex_], buffer, fromInSize * sizeof(short));
4271 memcpy(buffer_, &((short *) buffer)[fromInSize], fromZeroSize * sizeof(short));
4272 break;
4273 case RTAUDIO_SINT24:
4274 memcpy(&((S24 *) buffer_)[inIndex_], buffer, fromInSize * sizeof(S24));
4275 memcpy(buffer_, &((S24 *) buffer)[fromInSize], fromZeroSize * sizeof(S24));
4276 break;
4277 case RTAUDIO_SINT32:
4278 memcpy(&((int *) buffer_)[inIndex_], buffer, fromInSize * sizeof(int));
4279 memcpy(buffer_, &((int *) buffer)[fromInSize], fromZeroSize * sizeof(int));
4280 break;
4281 case RTAUDIO_FLOAT32:
4282 memcpy(&((float *) buffer_)[inIndex_], buffer, fromInSize * sizeof(float));
4283 memcpy(buffer_, &((float *) buffer)[fromInSize], fromZeroSize * sizeof(float));
4284 break;
4285 case RTAUDIO_FLOAT64:
4286 memcpy(&((double *) buffer_)[inIndex_], buffer, fromInSize * sizeof(double));
4287 memcpy(buffer_, &((double *) buffer)[fromInSize], fromZeroSize * sizeof(double));
4288 break;
4289 }
4290
4291 // update "in" index
4292 inIndex_ += bufferSize;

Callers 1

wasapiThreadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected