# Set latency for a plugin generated with faust (faust2juce)

**URL:** <https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521>\
**Category:** Audio Plugins\
**Created:** [August 8, 2022, 10:00am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521 "2022-08-08T10:00:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![trummerschlunk](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trummerschlunk](https://forum.juce.com/u/trummerschlunk)\
**Post date:** [August 8, 2022, 10:00am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/1 "2022-08-08T10:00:38Z")

</div>

Hi all,  
I wrote an audio plugin in faust. It has a defined latency because of a lookahead function.  
As the faust2juce architecture has no option to report latency to the projucer, my question is: Where and how can I set the latency which the plugin reports back to the DAW?  
Thanks!

---

<div class="post-metadata">

**Author:** ![PierreGuillot](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pierreguillot/32/11653_2.png) [@PierreGuillot](https://forum.juce.com/u/PierreGuillot)\
**Post date:** [August 8, 2022, 10:41am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/2 "2022-08-08T10:41:26Z")

</div>

You should use the method [AudioProcessor::setLatencySamples()](https://github.com/juce-framework/JUCE/blob/2b16c1b94c90d0db3072f6dc9da481a9484d0435/modules/juce_audio_processors/processors/juce_AudioProcessor.h#L831).

---

<div class="post-metadata">

**Author:** ![trummerschlunk](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trummerschlunk](https://forum.juce.com/u/trummerschlunk)\
**Post date:** [August 8, 2022, 11:19am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/3 "2022-08-08T11:19:19Z")

</div>

Thanks. Where in the projucer code would I put that?

---

<div class="post-metadata">

**Author:** ![trummerschlunk](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trummerschlunk](https://forum.juce.com/u/trummerschlunk)\
**Post date:** [August 8, 2022, 11:27am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/4 "2022-08-08T11:27:48Z")

</div>

And is there a way to make this dependent on the samplerate?  
My lookahead in faust is defined as 0.001 seconds.

---

<div class="post-metadata">

**Author:** ![PierreGuillot](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pierreguillot/32/11653_2.png) [@PierreGuillot](https://forum.juce.com/u/PierreGuillot)\
**Post date:** [August 8, 2022, 11:54am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/5 "2022-08-08T11:54:16Z")

</div>

There is no way to do it from the projucer, you’ll have to code it in the `prepareToPlay()` or `processBlock()` methods. You should have a look at the example DSPModuleDemoPlugin.

---

<div class="post-metadata">

**Author:** ![trummerschlunk](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trummerschlunk](https://forum.juce.com/u/trummerschlunk)\
**Post date:** [August 8, 2022, 1:51pm UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/6 "2022-08-08T13:51:17Z")

</div>

thank you, will try

---

<div class="post-metadata">

**Author:** ![JaSn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jasn/32/8182_2.png) [@JaSn](https://forum.juce.com/u/JaSn)\
**Post date:** [August 10, 2022, 5:45am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/7 "2022-08-10T05:45:20Z")

</div>

Just a note that from my experience, putting setLatencySamples() in processBlock() is not handled well by a number of Windows hosts, resulting in audio artifacts. PrepareToPlay() is a safe place to do it.

---

<div class="post-metadata">

**Author:** ![PierreGuillot](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pierreguillot/32/11653_2.png) [@PierreGuillot](https://forum.juce.com/u/PierreGuillot)\
**Post date:** [August 10, 2022, 8:14am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/8 "2022-08-10T08:14:19Z")

</div>

And this is not well supported by Cubase on macOS either 😉 Indeed, it seems that `prepareToPlay()` is the best place to do it.

---

<div class="post-metadata">

**Author:** ![sletz](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sletz](https://forum.juce.com/u/sletz)\
**Post date:** [September 7, 2022, 10:40am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/9 "2022-09-07T10:40:00Z")

</div>

@trummerschlunk We could possibly code that at Faust DSP level using a syntax like:

- `declare options [latency_frames:<frames>]` or `declare options [latency_sec:<sec>]`

- the have the C++ architecture uses this metadata with `AudioProcessor::setLatencySamples()` in `prepareToPlay()` .

Would this work?

---

<div class="post-metadata">

**Author:** ![trummerschlunk](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trummerschlunk](https://forum.juce.com/u/trummerschlunk)\
**Post date:** [September 7, 2022, 11:04am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/10 "2022-09-07T11:04:28Z")

</div>

That would be awesome 🙂  
latency\_samples would also be great.

---

<div class="post-metadata">

**Author:** ![sletz](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sletz](https://forum.juce.com/u/sletz)\
**Post date:** [September 8, 2022, 8:35am UTC](https://forum.juce.com/t/set-latency-for-a-plugin-generated-with-faust-faust2juce/52521/11 "2022-09-08T08:35:39Z")

</div>

Done in [[NEW] Latency metadata added in faust2juce. Set version to 2.48.4. · grame-cncm/faust@a8dd82e · GitHub](https://github.com/grame-cncm/faust/commit/a8dd82e5af2fe9e87fd0d42975d8d8aced2f6246)  
and read [faust/architecture/juce at master-dev · grame-cncm/faust · GitHub](https://github.com/grame-cncm/faust/tree/master-dev/architecture/juce#latency-setting)
