Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Filter filter_left;
- Filter filter_right;
- std::array<float, 8192> arr_left = {};
- std::array<float, 8192> arr_right = {};
- #include <deque>
- #include <array>
- std::deque<float> output_buffer_left;
- std::deque<float> output_buffer_right;
- std::deque<float> buffer_left;
- std::deque<float> buffer_right;
- void SSBCleanupProcessorAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) {
- juce::ScopedNoDenormals noDenormals;
- auto totalNumInputChannels = getTotalNumInputChannels();
- auto totalNumOutputChannels = getTotalNumOutputChannels();
- auto numSamples = buffer.getNumSamples();
- auto* audiobufferleft = buffer.getWritePointer(0);
- auto* audiobufferright = buffer.getWritePointer(1);
- filter_left.setConstant(entropyValue);
- filter_left.set_NBINS(binsValue);
- filter_right.setConstant(entropyValue);
- filter_right.set_NBINS(binsValue);
- for (int i = 0; i < numSamples; ++i) {
- buffer_left.push_back(audiobufferleft[i]);
- buffer_right.push_back(audiobufferright[i]);
- }
- if (buffer_left.size() >= 8192) {
- int multiples = buffer_left.size() / 8192;
- int remainder = buffer_left.size() % 8192;
- for (int m = 0; m < multiples; ++m) {
- for (int i = 0; i < 8192; ++i) {
- arr_left[i] = buffer_left[m * 8192 + i];
- }
- // Process and push to output_buffer_left...
- arr_left = filter_left.process(arr_left);
- for (const auto& sample : arr_left) {
- output_buffer_left.push_back(sample);
- }
- }
- // Move the remaining values to the front of the buffer
- for (int i = 0; i < remainder; ++i) {
- buffer_left[i] = buffer_left[multiples * 8192 + i];
- }
- // Erase the processed values
- for (int i = 0; i < (buffer_left.size() - remainder); ++i) {
- buffer_left.pop_front();
- }
- }
- if (buffer_right.size() >= 8192) {
- int multiples = buffer_right.size() / 8192;
- int remainder = buffer_right.size() % 8192;
- for (int m = 0; m < multiples; ++m) {
- for (int i = 0; i < 8192; ++i) {
- arr_right[i] = buffer_right[m * 8192 + i];
- }
- // Process and push to output_buffer_left...
- arr_right = filter_right.process(arr_right);
- for (const auto& sample : arr_right) {
- output_buffer_right.push_back(sample);
- }
- }
- // Move the remaining values to the front of the buffer
- for (int i = 0; i < remainder; ++i) {
- buffer_right[i] = buffer_right[multiples * 8192 + i];
- }
- // Erase the processed values
- for (int i = 0; i < (buffer_left.size() - remainder); ++i) {
- buffer_right.pop_front();
- }
- }
- int availableSamples_left = output_buffer_left.size();
- int samplesToCopy_left = std::min(numSamples, availableSamples_left);
- // Copy samples to the output buffer
- std::copy(output_buffer_left.begin(), output_buffer_left.begin() + samplesToCopy_left, audiobufferleft);
- // Erase used samples from the beginning of the buffer
- for (int i = 0; i < samplesToCopy_left; ++i) {
- output_buffer_left.pop_front();
- }
- // If there were not enough samples in the buffer, fill the rest of the output with zeros- skipping
- if (samplesToCopy_left < numSamples) {
- std::fill(audiobufferleft + samplesToCopy_left, audiobufferleft + numSamples, 0.0f);
- }
- int availableSamples_right = output_buffer_right.size();
- int samplesToCopy_right = std::min(numSamples, availableSamples_right);
- // Copy samples to the output buffer
- std::copy(output_buffer_right.begin(), output_buffer_right.begin() + samplesToCopy_right, audiobufferright);
- // Erase used samples from the beginning of the buffer
- for (int i = 0; i < samplesToCopy_right; ++i) {
- output_buffer_right.pop_front();
- }
- // If there were not enough samples in the buffer, fill the rest of the output with zeros
- if (samplesToCopy_right < numSamples) {
- std::fill(audiobufferright + samplesToCopy_right, audiobufferright + numSamples, 0.0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement