HISE Logo Forum
    • Categories
    • Register
    • Login

    HISE FX and delay compensation

    Scheduled Pinned Locked Moved General Questions
    66 Posts 11 Posters 4.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan KorneffD
      Dan Korneff
      last edited by Dan Korneff

      I could use some suggestions on how to improve my approach to handling latency in my projects. I've currently been manually measuring latency and compensating for it based on which DSP nodes and oversampling are active. While this works well for static latency, I’m running into a challenge when I need to dynamically update the latency.
      Right now, I’m using:
      prepareToPlay() to get the initial latency with Engine.getLatencySamples()
      processBlock() to set latency using setLatencySamples()
      This works well for static latencies, but now that I’m introducing multiple oversampling filters, I need to adjust latency dynamically, depending on whether the user selects Linear-Phase or Minimum-Phase filtering. Since Linear-Phase filtering can add up to ~120 samples, I don’t want to set a fixed latency that high, as it would negatively impact real-time usage.
      I need a way to recalculate latency when the processing mode changes. For example, when switching between oversampling filters. The goal is to update latency based on active DSP modules.
      @Christoph-Hart or anyone else have suggestions on how to dynamically recalculate the latency?

      Dan Korneff - Producer / Mixer / Audio Nerd

      A 1 Reply Last reply Reply Quote 0
      • A
        aaronventure @Dan Korneff
        last edited by

        @Dan-Korneff can you measure the latency of your modules, put it in consts and make the call to set the new latency to report whenever the user changes any of the controls that affect it?

        Christoph HartC Dan KorneffD 2 Replies Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @aaronventure
          last edited by

          I would not trust every host to support dynamic latency so I‘d definitely check this thoroughly.

          1 Reply Last reply Reply Quote 1
          • Dan KorneffD
            Dan Korneff @aaronventure
            last edited by

            @aaronventure said in HISE FX and delay compensation:

            @Dan-Korneff can you measure the latency of your modules, put it in consts and make the call to set the new latency to report whenever the user changes any of the controls that affect it?

            That's definitely plan B. I guess I need to use a global variable to get this data into scriptFX?

            Dan Korneff - Producer / Mixer / Audio Nerd

            A 1 Reply Last reply Reply Quote 0
            • A
              aaronventure @Dan Korneff
              last edited by

              @Dan-Korneff why do you need to get it into script fx in the first place?

              Dan KorneffD 1 Reply Last reply Reply Quote 0
              • Dan KorneffD
                Dan Korneff @aaronventure
                last edited by

                @aaronventure scriptFX is the only place you can access the processBlock to call Engine.setLatencySamples()

                Dan Korneff - Producer / Mixer / Audio Nerd

                Christoph HartC A 2 Replies Last reply Reply Quote 0
                • Christoph HartC
                  Christoph Hart @Dan Korneff
                  last edited by Christoph Hart

                  @Dan-Korneff Why do you need to access processBlock?

                  If you need the sample rate / block size for the calculation, attach a broadcaster to the processing specs.

                  Dan KorneffD 1 Reply Last reply Reply Quote 0
                  • A
                    aaronventure @Dan Korneff
                    last edited by

                    @Dan-Korneff I'm calling it from a control callback where sample offset is adjusted and it works just fine (in Reaper).

                    Dan KorneffD 1 Reply Last reply Reply Quote 0
                    • Dan KorneffD
                      Dan Korneff @Christoph Hart
                      last edited by

                      @Christoph-Hart I was just following your Latency Test repo

                      Screenshot 2025-01-31 082335.png

                      Dan Korneff - Producer / Mixer / Audio Nerd

                      1 Reply Last reply Reply Quote 0
                      • Dan KorneffD
                        Dan Korneff @aaronventure
                        last edited by

                        @aaronventure Damn... Just tested and it works like you said. Happy days!

                        Dan Korneff - Producer / Mixer / Audio Nerd

                        Christoph HartC 1 Reply Last reply Reply Quote 0
                        • Christoph HartC
                          Christoph Hart @Dan Korneff
                          last edited by

                          @Dan-Korneff ah the example might precede the broadcaster addition, so that‘s kind of outdated as a best practice but if it works…

                          T 1 Reply Last reply Reply Quote 0
                          • T
                            tomekslesicki @Christoph Hart
                            last edited by

                            @Christoph-Hart could you please share an example of checking the sample rate with a broadcaster? I see a attachToProcessingSpecs call in the docs but a simple example would be of great help!

                            T 1 Reply Last reply Reply Quote 0
                            • T
                              tomekslesicki @tomekslesicki
                              last edited by

                              Is this the correct logic?

                              // Broadcaster definition
                              const var SampleRateBroadcaster = Engine.createBroadcaster({
                                "id": "SampleRateBroadcaster",
                                "args": ["sampleRate", "blockSize"],
                                "tags": []
                              });
                              
                              // attach to event Type
                              SampleRateBroadcaster.attachToProcessingSpecs("");
                              
                              SampleRateBroadcaster.addListener("sampleRate", "blockSize", function(component, event)
                              {
                              	Console.print(Engine.getSampleRate());
                              });
                              
                              Christoph HartC resonantR 2 Replies Last reply Reply Quote 0
                              • Christoph HartC
                                Christoph Hart @tomekslesicki
                                last edited by

                                @tomekslesicki no you get the samplerate and blocksize as function arguments (which you named component and event).

                                T 1 Reply Last reply Reply Quote 0
                                • T
                                  tomekslesicki @Christoph Hart
                                  last edited by

                                  @Christoph-Hart could you please tell me how should I call this then? I'm new to broadcasters!

                                  d.healeyD 1 Reply Last reply Reply Quote 0
                                  • d.healeyD
                                    d.healey @tomekslesicki
                                    last edited by

                                    @tomekslesicki You have them

                                    34a589c9-acd2-4256-b001-e3d55ae3b90d-image.png

                                    component = samplerrate
                                    event = blocksize

                                    Libre Wave - Freedom respecting instruments and effects
                                    My Patreon - HISE tutorials
                                    YouTube Channel - Public HISE tutorials

                                    T Christoph HartC 2 Replies Last reply Reply Quote 0
                                    • T
                                      tomekslesicki @d.healey
                                      last edited by

                                      @d-healey thank you!

                                      1 Reply Last reply Reply Quote 0
                                      • Christoph HartC
                                        Christoph Hart @d.healey
                                        last edited by

                                        On a very high level you give the broadcaster an event source (in this case a change to the processing specifications) and then you can add functions (=listeners) that are called whenever the source event occurs. You are free to call the function parameters as you wish, but there is a expected number of parameters for each event source - in this case it's two, and the first parameter will hold the sample rate and the second one the block size.

                                        Now you've probably copy & pasted this from somewhere (or the broadcaster wizard spat this out) and the function parameters are named component and event (probably from a mouse callback source type), just rename them and address them.

                                        SampleRateBroadcaster.addListener("sampleRate", "blockSize", function(component, event)
                                        {
                                        	Console.print(Engine.getSampleRate());
                                        });
                                        

                                        Also where you put "sampleRate" and "blockSize" in your example, it expects a object and a comment that will show up in the broadcaster map, but both are optional, it's looks a bit misleading.

                                        So basically you need to do this instead:

                                        SampleRateBroadcaster.addListener("", "will be called when sample rate changes", function(sampleRate, blockSize)
                                        {
                                        	Console.print(sampleRate);
                                        });
                                        
                                        T 1 Reply Last reply Reply Quote 2
                                        • resonantR
                                          resonant @tomekslesicki
                                          last edited by

                                          @tomekslesicki said in HISE FX and delay compensation:

                                          Is this the correct logic?

                                          // Broadcaster definition
                                          const var SampleRateBroadcaster = Engine.createBroadcaster({
                                            "id": "SampleRateBroadcaster",
                                            "args": ["sampleRate", "blockSize"],
                                            "tags": []
                                          });
                                          
                                          // attach to event Type
                                          SampleRateBroadcaster.attachToProcessingSpecs("");
                                          
                                          SampleRateBroadcaster.addListener("sampleRate", "blockSize", function(component, event)
                                          {
                                          	Console.print(Engine.getSampleRate());
                                          });
                                          

                                          So how can this broadcaster be used for dynamic delay compensation?

                                          Christoph HartC 1 Reply Last reply Reply Quote 0
                                          • Christoph HartC
                                            Christoph Hart @resonant
                                            last edited by

                                            @resonant Call this function instead of Console.print in the callback and hope that every DAW supports dynamic changing of the latency.

                                            resonantR 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post

                                            22

                                            Online

                                            1.8k

                                            Users

                                            12.1k

                                            Topics

                                            105.4k

                                            Posts