# AU/Logic: Different latency for offline rendering

**URL:** <https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372>\
**Category:** Audio Plugins\
**Created:** [January 11, 2016, 8:03am UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372 "2016-01-11T08:03:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckk](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@ckk](https://forum.juce.com/u/ckk)\
**Post date:** [January 11, 2016, 8:03am UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372/1 "2016-01-11T08:03:47Z")

</div>

We’re observing an issue in a plugin in Logic Pro X where we use different latencies for online (latency = 0) and offline (latency \> 0) rendering. As a result, the (offline) rendered audio is out of sync.

Using the latest tip I had a look at what happens during the rendering process and noticed that AudioProcessor::prepareToPlay() where the latency is set (via AudioProcessor::setLatencySamples()) isn’t called. I added calls to AudioProcessor::releaseResources() and JuceAU::prepareToPlay() in the AU wrapper’s SetProperty() handling of [font=Courier]kAudioUnitProperty\_OfflineRender[/font]:

```auto
case kAudioUnitProperty_OfflineRender:
    if (juceFilter != nullptr)
    {
        juceFilter->setNonRealtime ((*(UInt32*) inData) != 0);

        PluginHostType host;

        if (host.isLogic()) // other hosts seem to work without this
        {
            juceFilter->releaseResources();
            prepareToPlay();
        }
    }

    return noErr;
```

This way, AudioProcessor::prepareToPlay() is called before the rendering starts but still Logic Pro won’t compensate the latency correctly.  
Generally, this should be possible as it seems to work with The Glue (cytomic) when setting online oversampling to 1x and offline oversampling to 2x or higher.

Any idea what can be done to solve this?  
If it helps, I can post the example plugin I used which mainly introduces a delay of 1000 samples in offline mode.

---

<div class="post-metadata">

**Author:** ![timur](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/timur/32/541_2.png) [@timur](https://forum.juce.com/u/timur)\
**Post date:** [January 22, 2016, 6:06pm UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372/2 "2016-01-22T18:06:42Z")

</div>

Thanks, I'll have a look!

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [February 3, 2016, 5:11pm UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372/3 "2016-02-03T17:11:12Z")

</div>

Can you replace your code with the following code and let me know if this works for you:

```
case kAudioUnitProperty_OfflineRender:
                    if (juceFilter != nullptr)
                    {
                        const bool nonRealTime = ((*(UInt32*) inData) != 0);

                        if (nonRealTime != juceFilter->isNonRealtime())
                        {
                            const int lastLatency = juceFilter->getLatencySamples();
                            juceFilter->setNonRealtime ((*(UInt32*) inData) != 0);

                            if (prepared) juceFilter->releaseResources();

                            prepareToPlay();
                            prepared = true;

                            if (lastLatency != juceFilter->getLatencySamples())
                                PropertyChanged (kAudioUnitProperty_Latency, kAudioUnitScope_Global, 0);
                        }
                    }

                    return noErr;
```

---

<div class="post-metadata">

**Author:** ![ckk](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@ckk](https://forum.juce.com/u/ckk)\
**Post date:** [February 4, 2016, 4:22pm UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372/4 "2016-02-04T16:22:58Z")

</div>

Unfortunately, with the code above the latency still won’t be compensated during offline rendering.

On a completely unrelated matter, how do you get these fancy (black background & syntax highlighting) code sections?

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [February 5, 2016, 6:15pm UTC](https://forum.juce.com/t/au-logic-different-latency-for-offline-rendering/16372/5 "2016-02-05T18:15:09Z")

</div>

Hmm.. I've done some more debugging today. The way AudioUnit works is that the host needs to call into the audiounit to probe the current latency. It does this once when you add the AudioUnit to the track but never probes the latency again even when bouncing a track. I though the` PropertyChanged (kAudioUnitProperty_Latency,       kAudioUnitScope_Global, 0);` would nudge Logic to query the latency again but to no avail. Right now, I am out of ideas how to fix this.

&nbsp;

P.S: Not sure if the highlited code needs special admin permission but I use "code: highlited C++" from the Paragraph drop down menu.
