# AudioBlock::copyTo issue after upgrade to 5.4.4

**URL:** <https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758>\
**Category:** General JUCE discussion\
**Created:** [August 12, 2019, 6:54pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758 "2019-08-12T18:54:59Z")\
**Posts on this page:** 12\
**Page:** 1

<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:** [August 12, 2019, 6:54pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/1 "2019-08-12T18:54:59Z")

</div>

Hello,

I am using in my code juce::dsp::AudioBlock::copyTo method, because I need a temporary copy of the input signal. After upgrading JUCE to 5.4.4 I got an error while compiling:

```Severity
Error	C2664	'const juce::dsp::AudioBlock<const float> &juce::dsp::AudioBlock<const float>::copyTo(juce::AudioBuffer<const float> &,size_t,size_t,size_t) const': cannot convert argument 1 from 'juce::AudioBuffer<float>' to 'juce::AudioBuffer<const float> &'	AudioBlockCopyToIssue_SharedCode	c:\users\mateusz\workspace\small_projects\audioblockcopytoissue\source\pluginprocessor.cpp	138	

```

I have prepared an example project: [Mateusz Salski / AudioBlockCopyToIssue · GitLab](https://gitlab.com/mateusz.salski/audioblockcopytoissue/)  
There are exporters for Visual Studio and XCode.

The problem is illustrated in method:

```auto
void AudioBlockCopyToIssueAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& /*midiMessages*/)
{
    ScopedNoDenormals noDenormals;

	juce::dsp::AudioBlock<float> block{ buffer };
	juce::dsp::ProcessContextReplacing<float> context{ block };
    
	auto& inBlock = context.getInputBlock();
	inBlock.copyTo(tempBuffer); // <---- Compile error
}

```

`tempBuffer` is of type `AudioBuffer<float>`, but for some reason AudioBlock::copyTo expects `AudioBlock<const float>`, if I understand the error message correctly. What does not make sense because `copyTo` would modify buffer.  
IMHO the problem is return type of context.getInputBlock().

I double checked on Windows that this code compiles with JUCE 5.4.3. On MacOSX I only checked that this is not compiling with 5.4.4.

Could you please help me to resolve this? I have no idea how could I fix it on my own.

---

<div class="post-metadata">

**Author:** ![MBO](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mbo/32/5045_2.png) [@MBO](https://forum.juce.com/u/MBO)\
**Post date:** [August 12, 2019, 10:13pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/2 "2019-08-12T22:13:38Z")

</div>

## Change

The AudioBlock class now differentiates between const and non-const data.

## Possible Issues

The return type of the getInputBlock() method of the ProcessContextReplacing  
and ProcessContextNonReplacing classes has changed from AudioBlock to  
AudioBlock.

## Workaround

For ProcessContextReplacing you should use getOutputBlock() instead of  
getInputBlock(). For ProcessContextNonReplacing attempting to modify the input  
block is very likely an error.

## Rationale

This change makes the intent of the code much clearer and means that we can  
remove some const\_cast operations.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 13, 2019, 6:17am UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/3 "2019-08-13T06:17:12Z")

</div>

Actually, that does look like a mistake - copyTo should take a templated destination type rather than the same sample type as the object itself - thanks, we’ll sort that out!

---

<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:** [August 13, 2019, 12:25pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/4 "2019-08-13T12:25:27Z")

</div>

Thank you @MBO and @jules.  
I will track dev branch for fix and use above workaround if necessary.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 13, 2019, 1:00pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/5 "2019-08-13T13:00:05Z")

</div>

Thanks - yes, this has raised a few issues, we’re going to review that class to try to give it more obvious behaviour!

---

<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:** [August 15, 2019, 1:05pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/6 "2019-08-15T13:05:21Z")

</div>

> <https://github.com/WeAreROLI/JUCE/commit/41055ad782bf16cd6aec0af99318524fad216fed>

---

<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:** [August 16, 2019, 1:16pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/7 "2019-08-16T13:16:01Z")

</div>

The fix works great. Thank you. 🙂

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [November 12, 2019, 9:44am UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/8 "2019-11-12T09:44:20Z")

</div>

This doesn’t compile with JUCE 5.4.5. It used to:

```
ScopedPointer<dsp::Oversampling<float>> oversampler{nullptr};

void GranularPitchShifter::process(const dsp::ProcessContextReplacing<float>& context)
{
    auto inputBlock = context.getInputBlock();
    auto workingBlock = oversampler->processSamplesUp(inputBlock);

```

Some kind of const issue with `<const float> vs <float>`.

What are we doing wrong?

---

<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:** [November 12, 2019, 5:43pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/9 "2019-11-12T17:43:05Z")

</div>

Hi,

So the question is: “How to pass input buffer to custom method, so we can modify it?”. Not just about copyTo. Am I right?

As far as I understand copyTo was fixed by adding `std::remove_const<NumericType>::type>` to the declaration.

Unfortunately I am “out of JUCE” right now and I do not have enough time to check it. But it looks like a good question. I will try to play a bit with this. Maybe there are some JUCE processors using inputBlock?

Could you also past error message?

Regards,  
Mateusz

---

<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:** [November 12, 2019, 5:44pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/10 "2019-11-12T17:44:21Z")

</div>

It was an oversight on our behalf, but fixed now:

> <https://github.com/WeAreROLI/JUCE/commit/8b8c3b3280d636b9b868e0d7518eceacfc532552>

---

<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:** [November 12, 2019, 6:15pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/11 "2019-11-12T18:15:11Z")

</div>

Oh, it is JUCE Oversampling processor. 😛  
And there is nothing hard in passing inputBuffer to custom methods. It has simple definition `void processSamplesUp (const AudioBlock<const SampleType>& inputBlock)` and input block is just read only.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [November 12, 2019, 7:20pm UTC](https://forum.juce.com/t/audioblock-copyto-issue-after-upgrade-to-5-4-4/34758/12 "2019-11-12T19:20:41Z")

</div>

Well it’s fixed now 🙂

Looked like a bug!

We’ve spent a few days upgrading projects to VS2019, Xcode 10 (from 2015 and Xcode 9) and from JUCE 4 in some cases to JUCE 5.4.x. So we’ve hit a few painful moments 🙂

However quite frankly I long for the glory days of ScopedPointer. unique\_ptr is ugly, better maybe, but ugly and painful to change!
