# ProcessContextNonReplacing assertion 5.4.4

**URL:** <https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873>\
**Category:** General JUCE discussion\
**Created:** [August 20, 2019, 2:09pm UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873 "2019-08-20T14:09:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielrudrich](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danielrudrich/32/3735_2.png) [@danielrudrich](https://forum.juce.com/u/danielrudrich)\
**Post date:** [August 20, 2019, 2:09pm UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873/1 "2019-08-20T14:09:44Z")

</div>

> <https://github.com/juce-framework/JUCE/commit/9f344aaa5ace1c4b746365c16760b7ce82fd42db>

Is this one really necessary? I have a couple of processors which can handle both replacing and non replacing context, simply by forwarding the replacing to the non-replacing by creating a context with the same in and out AudioBlock. Did not want to create the same code, as there has to be done an internal copy of the data anyhow.  
Or is there a more elegant way to avoid having two methods with the same dsp code inside?

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [September 2, 2019, 1:34pm UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873/2 "2019-09-02T13:34:26Z")

</div>

That one was a request from the software team at ROLI who had suffered a bit from `ProcessContextNonReplacing` not doing what they expected it to, so there’s certainly some merit for having a check in there. That being said, I’m not sure there’s a nice way around your use-case either…

---

<div class="post-metadata">

**Author:** ![mateuszsalski](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@mateuszsalski](https://forum.juce.com/u/mateuszsalski)\
**Post date:** [September 3, 2019, 4:17am UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873/3 "2019-09-03T04:17:50Z")

</div>

Hi @danielrudrich,  
Maybe just try to do it the other way around 🙂 Forward non-replacing to replacing one. The disadvantage is that the additional temporary output buffer is needed in this case. Which may not make sense to have it in some processors.

Some time ago I was trying to write ProcessorParallel (like there is a juce::dsp::ProcessorChain). Unfortunately I was disturbed by other tasks and it is not tested well. But I used there this trick with temporary buffer.

Btw. Is ProcessContextNonReplacing used in other scenarios than parallel processing of a signal?

greetings 😃

---

<div class="post-metadata">

**Author:** ![danielrudrich](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danielrudrich/32/3735_2.png) [@danielrudrich](https://forum.juce.com/u/danielrudrich)\
**Post date:** [September 3, 2019, 7:18am UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873/4 "2019-09-03T07:18:51Z")

</div>

Thanks for your reply!  
Yea the additional buffer is indeed a disadvantage, especially if the signal might get buffered in the non-replacing again.

> [@mateusz](#):
>
> Btw. Is ProcessContextNonReplacing used in other scenarios than parallel processing of a signal?

Not really 🙂

@t0m I see the reason for the check, might make things easier in most of the cases. I guess I’ll consider writing inline code of the processing and put it into both methods, replacing and non-replacing.

Rethinking the check, shouldn’t there actually be an assertion that the AudioBlocks don’t overlap to assure that the content is not replaced during that call? I mean, just adding one sample would be a very dirty hack to circumvent the assertion, right? 🙂

---

<div class="post-metadata">

**Author:** ![danielrudrich](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danielrudrich/32/3735_2.png) [@danielrudrich](https://forum.juce.com/u/danielrudrich)\
**Post date:** [September 3, 2019, 8:10am UTC](https://forum.juce.com/t/processcontextnonreplacing-assertion-5-4-4/34873/5 "2019-09-03T08:10:41Z")

</div>

> [@danielrudrich](#):
>
> I’ll consider writing inline code of the processing and put it into both methods, replacing and non-replacing.

Better solution for that: as the `process (const ProcessContextNonReplacing<float>& context)` is not required when inheriting from `ProcessorBase`, I’ll just write a method like `process (const AudioBlock<float>& input, AudioBlock<float>& output)` and forward both replacing and non replacing to it, or simply call that one directly to avoid that additional call.

Edit to sum up:  
That’s my processor’s methods:

```auto
void prepare (const ProcessSpec& specs);
void process (const ProcessContextReplacing<float>& replacingContext);
void process (const ProcessContextNonReplacing<float>& nonReplacingContext);
void process (const AudioBlock<const float>& input, AudioBlock<float>& output);
void reset();

```

and here’s the implementation for the Context calls:

```auto
void MatrixConvolution::process (const ProcessContextReplacing<float>& replacingContext)
{
    process (replacingContext.getInputBlock(), replacingContext.getOutputBlock());
};

void MatrixConvolution::process (const ProcessContextNonReplacing<float>& nonReplacingContext)
{
    process (nonReplacingContext.getInputBlock(), nonReplacingContext.getOutputBlock());
}

```
