| 2589 | } |
| 2590 | |
| 2591 | void FireAudioProcessor::calculateAndStoreLevels(const juce::AudioBuffer<float>& buffer, |
| 2592 | std::atomic<float>& rmsLeft, |
| 2593 | std::atomic<float>& rmsRight, |
| 2594 | std::atomic<float>& peakLeft, |
| 2595 | std::atomic<float>& peakRight) |
| 2596 | { |
| 2597 | // This function calculates RMS and Peak levels for a given buffer and stores them |
| 2598 | // in the provided atomic float variables for thread-safe access from the UI. |
| 2599 | |
| 2600 | const int numChannels = buffer.getNumChannels(); |
| 2601 | const int numSamples = buffer.getNumSamples(); |
| 2602 | |
| 2603 | // If there's no audio, reset levels to zero to prevent stale values. |
| 2604 | if (numSamples <= 0) |
| 2605 | { |
| 2606 | rmsLeft.store(0.0f); |
| 2607 | rmsRight.store(0.0f); |
| 2608 | peakLeft.store(0.0f); |
| 2609 | peakRight.store(0.0f); |
| 2610 | return; |
| 2611 | } |
| 2612 | |
| 2613 | // Use JUCE's built-in functions for efficient calculation. |
| 2614 | // getRMSLevel() returns linear RMS amplitude. |
| 2615 | // getMagnitude() with arguments (0, numSamples) finds the peak absolute value. |
| 2616 | |
| 2617 | // Calculate for Left Channel (or Mono) |
| 2618 | rmsLeft.store(buffer.getRMSLevel(0, 0, numSamples)); |
| 2619 | peakLeft.store(buffer.getMagnitude(0, 0, numSamples)); |
| 2620 | |
| 2621 | // Calculate for Right Channel if it exists, otherwise mirror the left channel. |
| 2622 | if (numChannels > 1) |
| 2623 | { |
| 2624 | rmsRight.store(buffer.getRMSLevel(1, 0, numSamples)); |
| 2625 | peakRight.store(buffer.getMagnitude(1, 0, numSamples)); |
| 2626 | } |
| 2627 | else |
| 2628 | { |
| 2629 | rmsRight.store(rmsLeft.load()); |
| 2630 | peakRight.store(peakLeft.load()); |
| 2631 | } |
| 2632 | } |
nothing calls this directly
no outgoing calls
no test coverage detected