# Tracktion Engine in a plug-in with 0 latency?

**URL:** <https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714>\
**Category:** Tracktion Engine\
**Created:** [January 26, 2023, 2:13pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714 "2023-01-26T14:13:12Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 26, 2023, 2:13pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/1 "2023-01-26T14:13:12Z")

</div>

Hi everyone,

The EngineInPluginDemo shows that the plug-in latency should be set equal to the block size. This introduces a latency which makes the plug-in not suitable for real-time recording because a musician wants to monitor the instrument or vocal with the least amount of latency possible.

Is this latency necessary or can it safely be set to 0?

This is the example:

> <https://github.com/Tracktion/tracktion_engine/blob/master/examples/EngineInPluginDemo.h#L56>

Thank you,  
Jelle

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [January 27, 2023, 10:46am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/2 "2023-01-27T10:46:06Z")

</div>

I _think_ since I rewrote the audio engine it should be possible to process without this latency.

@RolandMR wrote the plugin side of the Engine though so maybe there’s a reason it’s still require. Roland, could it be that the audio inputs won’t be dispatched correctly if they’re not fifo’ed? Or the MIDI inputs?

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 27, 2023, 12:07pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/3 "2023-01-27T12:07:26Z")

</div>

MIDI isn’t required for me at the moment. Let’s wait for his answer.

---

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [January 27, 2023, 1:26pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/4 "2023-01-27T13:26:47Z")

</div>

I’ll need to verify but I think a fixed block size was only required if you were using racks or aux send/return.

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 30, 2023, 9:55am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/5 "2023-01-30T09:55:27Z")

</div>

According to the documentation it looks like there is no work-around for the latency in a plug-in. I tried to simply remove the `setLatencySamples(samplesPerBlock)` line but there is defenitely a latency happening (and the DAW will not compensate without that one line).

This is concering to me, because this means the engine is unsuitable for any application where zero latency is desired.

```auto
/** If the size of the audio buffer passed to processBlock will be fixed or not.
    If you are creating a plugin, this should be false, and your plguin will have
    one block of latency. If you are handling the audio device callback yourself,
    this can be true. */
bool fixedBlockSize = false;

```

From [tracktion\_engine/tracktion\_HostedAudioDevice.h at master · Tracktion/tracktion\_engine · GitHub](https://github.com/Tracktion/tracktion_engine/blob/master/modules/tracktion_engine/playback/tracktion_HostedAudioDevice.h)

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [January 30, 2023, 12:09pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/6 "2023-01-30T12:09:22Z")

</div>

Right, but what we’re discussing is whether that is a legacy option and if now, with the new audio engine `fixedBlockSize` can be used as true in a plugin and no latency will be required.

You can try it out with the EngineInPlugin demo or your own code by passing that parameter as `true`.

We just need to determine if we can remove it all together.

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 30, 2023, 12:15pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/7 "2023-01-30T12:15:56Z")

</div>

Without even testing it, I already can guess this assert will be triggered when fixedBlockSize equals true and a DAW decides to sends small chunks of buffers:

```auto
void HostedAudioDeviceInterface::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midi)
{
    if (parameters.fixedBlockSize)
    {
        jassert (buffer.getNumSamples() == parameters.blockSize);

```

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [January 30, 2023, 12:25pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/8 "2023-01-30T12:25:02Z")

</div>

And if you comment that out?

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [January 30, 2023, 12:41pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/9 "2023-01-30T12:41:35Z")

</div>

I haven’t attached a debugger (because it requires me to disable SIP), but first quick test in Logic is promising because it sounds fine and the latency is gone. And I actually think Logic is chunking because as far as I can remember from tests in the past, Logic always prepares the plug-in with a fixed (1024?) block size.

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [February 3, 2023, 4:11pm UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/10 "2023-02-03T16:11:53Z")

</div>

@dave96  
Is it possible this fix can be pushed to dev?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [February 10, 2023, 10:14am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/11 "2023-02-10T10:14:21Z")

</div>

> <https://github.com/Tracktion/tracktion_engine/commit/4695f371e8fe1f760301275267a4df29e2effe5e>

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [February 10, 2023, 10:30am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/12 "2023-02-10T10:30:27Z")

</div>

Thank you Dave, amazing! I already tried it yesterday and works.

Related to that commit, I wondered why you decided to remove the root CMakeList.txt file because it broke my own CMake setup. `FetchContent_MakeAvailable(Tracktion)` in my CMake didn’t work anymore and I had to add `add_subdirectory(${tracktion_SOURCE_DIR}/modules)` to make it work.

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [February 10, 2023, 11:15am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/13 "2023-02-10T11:15:43Z")

</div>

Sorry, I thought that was just building the examples but didn’t work properly.  
I’ve added back the relevant bit now so it should work for you again?

> <https://github.com/Tracktion/tracktion_engine/commit/d3f24ec6a61ffe3ec99ad16e88b88d4656c8b32b>

One question related to that though, if you were using `FetchContent_MakeAvailable(Tracktion)`, where is CMake picking up “Tracktion” from?

---

<div class="post-metadata">

**Author:** ![jellebakker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jellebakker/32/17053_2.png) [@jellebakker](https://forum.juce.com/u/jellebakker)\
**Post date:** [February 10, 2023, 11:58am UTC](https://forum.juce.com/t/tracktion-engine-in-a-plug-in-with-0-latency/54714/14 "2023-02-10T11:58:35Z")

</div>

Thank you.  
I’m using FetchContent\_Declare to pull the repo and FetchContent\_MakeAvailable will look for the root CMakeLists.txt, similar to when you add any sub directory.

Now that we talk about all this CMake stuff, I also wondered if I could simplify my script because currently I am pulling Tracktion as well as JUCE to fix a CMake error from tracktion repo "Unknown CMake command “juce\_add\_modules”. Do you have any recommendations to setup CMake, does it make sense to pull both? At this moment I am pulling the exact same JUCE version as tracktion is using which feels a bit silly and error prone.
