MCPcopy Create free account
hub / github.com/jerryuhoo/Fire / setHistoryArray

Method setHistoryArray

Source/PluginProcessor.cpp:1304–1348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302}
1303
1304void FireAudioProcessor::setHistoryArray(int bandIndex)
1305{
1306 // This array holds pointers to all possible source buffers.
1307 std::array<juce::AudioBuffer<float>*, 5> sourceBuffers = { &mBuffer1, &mBuffer2, &mBuffer3, &mBuffer4, &mWetBuffer };
1308
1309 // Use the bandIndex to select the correct buffer. If the index is out of bounds (e.g., -1 for global),
1310 // we safely default to the last buffer in the array (mWetBuffer).
1311 const int effectiveIndex = (juce::isPositiveAndBelow(bandIndex, 4)) ? bandIndex : 4;
1312 auto* sourceBuffer = sourceBuffers[effectiveIndex];
1313
1314 // Safety check: if the selected buffer is invalid for any reason, do nothing.
1315 if (sourceBuffer == nullptr)
1316 return;
1317
1318 const int bufferSamples = sourceBuffer->getNumSamples();
1319 const int numChannels = sourceBuffer->getNumChannels();
1320
1321 if (numChannels == 0 || bufferSamples == 0)
1322 return;
1323
1324 // --- The processing loop is now much cleaner ---
1325 // We only need to get the channel data once.
1326 const float* channelDataL = sourceBuffer->getReadPointer(0);
1327 const float* channelDataR = (numChannels > 1) ? sourceBuffer->getReadPointer(1) : nullptr;
1328
1329 for (int sample = 0; sample < bufferSamples; ++sample)
1330 {
1331 // Downsample the data by only taking every 10th sample.
1332 if (sample % 10 == 0)
1333 {
1334 // Process Left Channel
1335 historyArrayL.add(channelDataL[sample]);
1336 if (historyArrayL.size() > historyLength)
1337 historyArrayL.remove(0);
1338
1339 // Process Right Channel (if it exists)
1340 if (channelDataR != nullptr)
1341 {
1342 historyArrayR.add(channelDataR[sample]);
1343 if (historyArrayR.size() > historyLength)
1344 historyArrayR.remove(0);
1345 }
1346 }
1347 }
1348}
1349
1350juce::Array<float> FireAudioProcessor::getHistoryArrayL()
1351{

Callers 2

paintMethod · 0.80
paintMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected