Advertisement
olivercromwell

Untitled

May 28th, 2023 (edited)
1,355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1.  
  2. Filter filter_left;
  3. Filter filter_right;
  4.  
  5.  
  6. std::array<float, 8192> arr_left = {};
  7. std::array<float, 8192> arr_right = {};
  8. #include <deque>
  9. #include <array>
  10.  
  11.  
  12. std::deque<float> output_buffer_left;
  13. std::deque<float> output_buffer_right;
  14. std::deque<float> buffer_left;
  15. std::deque<float> buffer_right;
  16.  
  17. void SSBCleanupProcessorAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
  18.  
  19.     juce::ScopedNoDenormals noDenormals;
  20.     auto totalNumInputChannels = getTotalNumInputChannels();
  21.     auto totalNumOutputChannels = getTotalNumOutputChannels();
  22.     auto numSamples = buffer.getNumSamples();
  23.     auto* audiobufferleft = buffer.getWritePointer(0);
  24.     auto* audiobufferright = buffer.getWritePointer(1);
  25.  
  26.     filter_left.setConstant(entropyValue);
  27.     filter_left.set_NBINS(binsValue);
  28.     filter_right.setConstant(entropyValue);
  29.     filter_right.set_NBINS(binsValue);
  30.  
  31.  
  32.  
  33.     for (int i = 0; i < numSamples; ++i) {
  34.         buffer_left.push_back(audiobufferleft[i]);
  35.         buffer_right.push_back(audiobufferright[i]);
  36.     }
  37.  
  38.     if (buffer_left.size() >= 8192) {
  39.         int multiples = buffer_left.size() / 8192;
  40.         int remainder = buffer_left.size() % 8192;
  41.  
  42.         for (int m = 0; m < multiples; ++m) {
  43.             for (int i = 0; i < 8192; ++i) {
  44.                 arr_left[i] = buffer_left[m * 8192 + i];
  45.             }
  46.  
  47.             // Process and push to output_buffer_left...
  48.             arr_left = filter_left.process(arr_left);
  49.  
  50.             for (const auto& sample : arr_left) {
  51.                 output_buffer_left.push_back(sample);
  52.             }
  53.         }
  54.  
  55.         // Move the remaining values to the front of the buffer
  56.         for (int i = 0; i < remainder; ++i) {
  57.             buffer_left[i] = buffer_left[multiples * 8192 + i];
  58.         }
  59.  
  60.         // Erase the processed values
  61.         for (int i = 0; i < (buffer_left.size() - remainder); ++i) {
  62.             buffer_left.pop_front();
  63.         }
  64.     }
  65.  
  66.     if (buffer_right.size() >= 8192) {
  67.         int multiples = buffer_right.size() / 8192;
  68.         int remainder = buffer_right.size() % 8192;
  69.  
  70.         for (int m = 0; m < multiples; ++m) {
  71.             for (int i = 0; i < 8192; ++i) {
  72.                 arr_right[i] = buffer_right[m * 8192 + i];
  73.             }
  74.  
  75.             // Process and push to output_buffer_left...
  76.             arr_right = filter_right.process(arr_right);
  77.             for (const auto& sample : arr_right) {
  78.                 output_buffer_right.push_back(sample);
  79.             }
  80.         }
  81.  
  82.         // Move the remaining values to the front of the buffer
  83.         for (int i = 0; i < remainder; ++i) {
  84.             buffer_right[i] = buffer_right[multiples * 8192 + i];
  85.         }
  86.  
  87.         // Erase the processed values
  88.         for (int i = 0; i < (buffer_left.size() - remainder); ++i) {
  89.             buffer_right.pop_front();
  90.         }
  91.     }
  92.     int availableSamples_left = output_buffer_left.size();
  93.     int samplesToCopy_left = std::min(numSamples, availableSamples_left);
  94.  
  95.     // Copy samples to the output buffer
  96.     std::copy(output_buffer_left.begin(), output_buffer_left.begin() + samplesToCopy_left, audiobufferleft);
  97.  
  98.     // Erase used samples from the beginning of the buffer
  99.     for (int i = 0; i <  samplesToCopy_left; ++i) {
  100.         output_buffer_left.pop_front();
  101.     }
  102.  
  103.     // If there were not enough samples in the buffer, fill the rest of the output with zeros- skipping
  104.     if (samplesToCopy_left < numSamples) {
  105.         std::fill(audiobufferleft + samplesToCopy_left, audiobufferleft + numSamples, 0.0f);
  106.     }
  107.     int availableSamples_right = output_buffer_right.size();
  108.     int samplesToCopy_right = std::min(numSamples, availableSamples_right);
  109.  
  110.     // Copy samples to the output buffer
  111.     std::copy(output_buffer_right.begin(), output_buffer_right.begin() + samplesToCopy_right, audiobufferright);
  112.  
  113.     // Erase used samples from the beginning of the buffer
  114.     for (int i = 0; i < samplesToCopy_right; ++i) {
  115.         output_buffer_right.pop_front();
  116.     }
  117.     // If there were not enough samples in the buffer, fill the rest of the output with zeros
  118.     if (samplesToCopy_right < numSamples) {
  119.         std::fill(audiobufferright + samplesToCopy_right, audiobufferright + numSamples, 0.0f);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement