MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / mixBus

Method mixBus

extlibs/soloud/src/core/soloud.cpp:1340–1623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1338 }
1339
1340 void Soloud::mixBus(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize, float *aScratch, unsigned int aBus, float aSamplerate, unsigned int aChannels)
1341 {
1342 unsigned int i, j;
1343 // Clear accumulation buffer
1344 for (i = 0; i < aSamplesToRead; i++)
1345 {
1346 for (j = 0; j < aChannels; j++)
1347 {
1348 aBuffer[i + j * aBufferSize] = 0;
1349 }
1350 }
1351
1352 // Accumulate sound sources
1353 for (i = 0; i < mActiveVoiceCount; i++)
1354 {
1355 AudioSourceInstance *voice = mVoice[mActiveVoice[i]];
1356 if (voice &&
1357 voice->mBusHandle == aBus &&
1358 !(voice->mFlags & AudioSourceInstance::PAUSED) &&
1359 !(voice->mFlags & AudioSourceInstance::INAUDIBLE))
1360 {
1361 unsigned int j;
1362 float step = voice->mSamplerate / aSamplerate;
1363 // avoid step overflow
1364 if (step > (1 << (32 - FIXPOINT_FRAC_BITS)))
1365 step = 0;
1366 unsigned int step_fixed = (int)floor(step * FIXPOINT_FRAC_MUL);
1367 unsigned int outofs = 0;
1368
1369 if (voice->mDelaySamples)
1370 {
1371 if (voice->mDelaySamples > aSamplesToRead)
1372 {
1373 outofs = aSamplesToRead;
1374 voice->mDelaySamples -= aSamplesToRead;
1375 }
1376 else
1377 {
1378 outofs = voice->mDelaySamples;
1379 voice->mDelaySamples = 0;
1380 }
1381
1382 // Clear scratch where we're skipping
1383 for (j = 0; j < voice->mChannels; j++)
1384 {
1385 memset(aScratch + j * aBufferSize, 0, sizeof(float) * outofs);
1386 }
1387 }
1388
1389 while (step_fixed != 0 && outofs < aSamplesToRead)
1390 {
1391 if (voice->mLeftoverSamples == 0)
1392 {
1393 // Swap resample buffers (ping-pong)
1394 AlignedFloatBuffer * t = voice->mResampleData[0];
1395 voice->mResampleData[0] = voice->mResampleData[1];
1396 voice->mResampleData[1] = t;
1397

Callers 1

getAudioMethod · 0.80

Calls 6

panAndExpandFunction · 0.85
resampleFunction · 0.70
hasEndedMethod · 0.45
getAudioMethod · 0.45
seekMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected