MCPcopy Create free account
hub / github.com/DISTRHO/DPF / reallocAudioBufferList

Function reallocAudioBufferList

distrho/src/DistrhoPluginAU.cpp:2429–2476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2427
2428 #if DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS != 0
2429 bool reallocAudioBufferList(const bool alloc)
2430 {
2431 if (fAudioBufferList != nullptr)
2432 {
2433 for (uint16_t i = 0; i < fAudioBufferList->mNumberBuffers; ++i)
2434 delete[] static_cast<float*>(fAudioBufferList->mBuffers[i].mData);
2435 }
2436
2437 #ifdef DISTRHO_PLUGIN_EXTRA_IO
2438 #if DISTRHO_PLUGIN_NUM_INPUTS != 0 && DISTRHO_PLUGIN_NUM_OUTPUTS != 0
2439 const uint16_t numBuffers = std::max(fNumInputs, fNumOutputs);
2440 #elif DISTRHO_PLUGIN_NUM_INPUTS != 0
2441 const uint16_t numBuffers = fNumInputs;
2442 #else
2443 const uint16_t numBuffers = fNumOutputs;
2444 #endif
2445 #else
2446 constexpr const uint16_t numBuffers = d_max(DISTRHO_PLUGIN_NUM_INPUTS, DISTRHO_PLUGIN_NUM_OUTPUTS);
2447 #endif
2448 const uint32_t bufferSize = fPlugin.getBufferSize();
2449
2450 if (! alloc)
2451 {
2452 std::free(fAudioBufferList);
2453 fAudioBufferList = nullptr;
2454 return true;
2455 }
2456
2457 if (AudioBufferList* const abl = static_cast<AudioBufferList*>(
2458 std::realloc(fAudioBufferList, sizeof(uint32_t) + sizeof(AudioBuffer) * numBuffers)))
2459 {
2460 abl->mNumberBuffers = numBuffers;
2461
2462 for (uint16_t i = 0; i < numBuffers; ++i)
2463 {
2464 abl->mBuffers[i].mNumberChannels = 1;
2465 abl->mBuffers[i].mData = new float[bufferSize];
2466 abl->mBuffers[i].mDataByteSize = sizeof(float) * bufferSize;
2467 }
2468
2469 fAudioBufferList = abl;
2470 return true;
2471 }
2472
2473 std::free(fAudioBufferList);
2474 fAudioBufferList = nullptr;
2475 return false;
2476 }
2477 #endif
2478
2479 // ----------------------------------------------------------------------------------------------------------------

Callers 3

~PluginAUFunction · 0.85
auInitializeFunction · 0.85
auUninitializeFunction · 0.85

Calls 2

d_maxFunction · 0.85
getBufferSizeMethod · 0.45

Tested by

no test coverage detected