HISE Logo Forum
    • Categories
    • Register
    • Login

    4 samples delay?

    Scheduled Pinned Locked Moved General Questions
    22 Posts 6 Posters 1.2k 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.
    • d.healeyD
      d.healey @A Former User
      last edited by d.healey

      @Steve-Mohican No, only for instruments I think (I didn't ready your post properly it seems :p ).

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

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User
        last edited by A Former User

        I found a Script FX delay core module, but I can't see the parameter name to give delay amount in samples.

        alt text

        HiseSnippet 1201.3oc4XstZabDEdVIuMQJUkjhKzetX5OVCtFIkj1BlRTrrcPTeQX4jz+EFO6QVCd0LKyNqaTMF5iVeD5iPeD5aP6Y1KRirUb1JHtgz0fMy4xLemybNeyA2WIYPbrTQbpcxjHf374tClHzi5NhxEjd6Pbp6tCDRm.JEY6IQz3XHf33T8EF8N0Vgj98WOaaZHUvfYhHjWI4LXe9Xtdlz9c9IdX3dz.3D9XKqeRmdLonqLTlfXopaSRDkcN8L3PpwrJtDmOa2.tVpFnoZHl3rx1xfICFI+EQl8uhGyOMDLKZQFfaTl38jgAFDajR5NhGFzuHliIDG29yx.Uyx.q5d.OfOU9rLwCSU3MyC67gSkaCdsrgWyxCOGK3sRF7dj6.lhGomowfsG31SnA0PJdEXCqLaIN+taWIZfPu4X54vdJbwTG7ebyla30tYy02ZXhfo4RgmTbnTCGI7Wu9k0qU+p5dWW0vgKTm4XTxvPPsP0lac0s4nuHY7ofZCuKngIvTCwve97q66N+Ze8yxhZKCkhdBt9nHP7tx5j7TkI+miJzTcZ1+Kxy9amn0RAgiI4ZtYKZQRgrcG.4k81gpoEaDtm34DAJM2DBN6.WfcHYWq0v1r3y0xnTaGGIEFD3buRbruc1QdRmISW7aurSTQT0Cc3dYMxXikB6ov69dysKZ3s5YFQtYgGV9KCRBo546ILDA4JvKx4J9LUXhXtdhMQwGjFkxB2G41mqYiVLdqr.7hWcenwaNsSC2cGNDX5YfcE2894+a3XpmWtgmuAHEEEKfXoxVUbaTG6xh0XGqxiIUf2O5sO+TEUgU4aFJoA9qYDu15a0ntssAlMEM1nbSlBvfJ8hA7WKU0MbHuTEcofL6LPOsYwesb8490nNWDxEfMIStEEbMrBeKnaZT+xF083C87KV6geWl8GyWJv1LFz8K5h7y3NQxSTclgWk8G72PXLTx8XAaP1lbUZz7dhXy1kGUcoggmhOd5e8vsHsX9YZNIRAHg.bhrOBJ+X53nP3X7lXCuSCkryGv+U3lr047JaarvmMhJDXftLj5tyWPWsbj5Kne5XYhlKN6.pVwQ9P2CSFO.GkfAcyQGJyohgaOacSyZS68.PDjt3uwubksLqcxU1pP4GSOKrx+tmE1x5YAxC6Xy9rZ147.2WSu.RG8Ksk+qRWOTpF68BP.JCMZqaY.v+nrC.FU5A.OhoQHbhhJhijwPK6c9Z5ZaqaGPmHl27LQyYkI71CCOK6temBgssE1mJlayv0ysSGvsxz+4y1UPwR1A.FMAGEyvf0j6reAreBxJ7ZdfdTKaGmItssXmpklz+Sl4du6l9nZ4f664YyZEXb.2vetq3BHDanSw3WhcvCoIg5Boy2FcfTHiFIEblcM0w.xic1Yvb0MKLfdtVib8yjrZmigPfFa0Z8Mc1GeFjpv7Drj4hVkOWba2WesaFb8L89deZL0X0+WN0X46PQ5wOBtouKlO3t3LFSYJ4aXYieXZ8tepDLtEo+iRp4dfYs2zoNbcatYSxXj.+MLlo53aw7yh8o8R3yiWBedxR3ySWBe9tkvmueI74GtUeLuc97DsbbV8OJn+toS+43jMpPZq.4e.z3VLMC
        
        1 Reply Last reply Reply Quote 0
        • ?
          A Former User
          last edited by A Former User

          Any ideas please?

          LindonL 1 Reply Last reply Reply Quote 0
          • LindonL
            Lindon @A Former User
            last edited by

            @Steve-Mohican use SNEX?

            HISE Development for hire.
            www.channelrobot.com

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @Lindon
              last edited by

              @Lindon The picture above is ScriptFX DSP core.
              I couldn't find sample delay in SNEX also

              orangeO 1 Reply Last reply Reply Quote 0
              • orangeO
                orange @A Former User
                last edited by orange

                @Steve-Mohican You can achieve the sample delay with the Simple Gain unit. But we need to convert milliseconds to samples first.

                Let's look at the principles. For example if we have 2 milliseconds delay in 44.1 kHz, the sample delay would be:

                2 x 44.1 = 88.2 samples

                If the sample rate was 96 kHz, sample delay would be:

                2 x 96 = 192 samples


                Acording to this equation you need to get the sample rate with Engine.getSampleRate() and calculate the ms delay amount. In your case since you need 4 samples delay, your equation will be;

                4 / (Engine.getSampleRate())/1000

                So you need to use below loop in a Simple Gain unit.

                   if Over sampling is active
                     {
                        SimpleGain.setAttribute(SimpleGain.Delay, 0);
                     }
                        
                    if Over sampling is not active
                     {
                        SimpleGain.setAttribute(SimpleGain.Delay, (4 / ((Engine.getSampleRate())/1000)));
                     }        
                
                

                NOTE: / 1000 is the conversion rate from Hz to kHz

                develop Branch / XCode 13.1
                macOS Monterey / M1 Max

                ? orangeO 2 Replies Last reply Reply Quote 2
                • d.healeyD
                  d.healey
                  last edited by d.healey

                  @orange You might find these useful:
                  98a4bf5d-95a6-4871-927f-01292a36ac33-image.png
                  401a9f34-f810-47b0-a62c-d228a82ee8bd-image.png

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

                  1 Reply Last reply Reply Quote 2
                  • ?
                    A Former User @orange
                    last edited by

                    @orange Wow! That's it. Thank you so much :)

                    1 Reply Last reply Reply Quote 0
                    • orangeO
                      orange @orange
                      last edited by orange

                      @orange Alternatively, Engine.getMilliSecondsForSamples() would be a shorter way for this.
                      For example; if the declared delay compensation amount is 4 samples :

                      if Over sampling is active
                      SimpleGain.setAttribute(SimpleGain.Delay, 0);
                      
                      else
                      SimpleGain.setAttribute(SimpleGain.Delay, Engine.getMilliSecondsForSamples(4));
                      
                      

                      develop Branch / XCode 13.1
                      macOS Monterey / M1 Max

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

                        Can I get some extra eyes on this script? Incorporating delay compensation with Engine.setMinimumSampleRate() has become a challenge.

                        I've created a simple project that has the following:

                        • simple gain module (set to induce 1ms latency)
                        • scriptFX to set Engine.setLatencySamples()
                        • button to enable oversampling
                        • simple gain module to compensate for oversampling latency
                        • label to display simple gain compensation delay

                        What I'm expecting to see is 4 samples delay when OS is off and 0 samples delay with OS on. Instead, I'm getting double the amount of delay at init, and then the expected values when I toggle the button. Does anyone see what I'm doing wrong?

                        HiseSnippet 1374.3oc6X0saaaCElJwZKVctncnO.B4JEzrT40zlNTLrz3jTDr7iQbV15tXAzRz1DQlTPhtsdEEXOE6UY21WjArGg8FrcHo9gNVIywXKXAn5FCRd946b3geGR2NgGPRS4IHq5mLNlfr9L6NiYhAsFfoLzdairtq8A3TAIwUO0ViiwoojPjk0huTNgU8ZH02e9Magivr.R4THzobZ.Ye5Ppnb11a9sznncwgjSnCMjd8M2KfyZwi3i.7rnsOJFGbNtO4PrTrErQVexNgTAOoi.KHofLawCG2Y.+MLs7mRSociHxAMQc.ComF0Z.MJrcdrlhPV0ZWF4Kpi7GXe.MjVLeYF3dpEbK0vLGXsvjPp1DPp4kAoc4QgRCbIvyx.d0zv691cBRnwhxUjX6N16wfMmdXHsaBKsrnEVslcKNHASr1P74jcSfAEZ38Te+Ucehu+JOugSCGH4mJbeMNw8nNms0Hgfyb+Z2b06SDs3Ci4LXf2xERrrT2RM2lDgGe1o3nQjKUWCYtf1gpUB.QIrTrfp.fpdTZhc50iD.5OsTKqCfFNTVDkQb6MhEnzlyJ.pDKI7HufbfrJ3R.Bqzv4cMbbguG8H9qIIo3gwfQ5C51voNsmWtTRQxjT9sCqO3p0RIhCnL5vQC6HUjbLTF30zW9IAUtzSiYoluPHRncGAZTw5pzzptEl485epFq85ommDkRtVPc8+8PZla5KcSTDsCA1XCS2ENanb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6cTW9zxZGl7o2piBn+FvbCV5y
                        

                        Dan Korneff - Producer / Mixer / Audio Nerd

                        orangeO 1 Reply Last reply Reply Quote 0
                        • orangeO
                          orange @Dan Korneff
                          last edited by orange

                          @dustbro said in 4 samples delay?:

                          Can I get some extra eyes on this script? Incorporating delay compensation with Engine.setMinimumSampleRate() has become a challenge.

                          I've created a simple project that has the following:

                          • simple gain module (set to induce 1ms latency)
                          • scriptFX to set Engine.setLatencySamples()
                          • button to enable oversampling
                          • simple gain module to compensate for oversampling latency
                          • label to display simple gain compensation delay

                          What I'm expecting to see is 4 samples delay when OS is off and 0 samples delay with OS on. Instead, I'm getting double the amount of delay at init, and then the expected values when I toggle the button. Does anyone see what I'm doing wrong?

                          Why do you use Engine.setMinimumSampleRate() for that instead of Engine.getMilliSecondsForSamples()?

                          Let's say the (ampirically) calculated latency value is 4 samples. The latency compensation value is declared with a script fx at the very end of the fx chain.

                          In this example I've used ShapeFX for oversampling. So when oversampling is on (for example 16x), the simple gain delay must be 0 (because we've already declared a latency compensation value with script fx).

                          If the oversampling is 1x (since there is no oversampling delay anymore), then we need to give an artificial simple gain delay because of the previously declared latency compensation value, in order to keep the delay balanced.

                          We need to calculate the delay amount (in ms unit) with the current sample rate and previously declared sample delay using Engine.getMilliSecondsForSamples()

                          HiseSnippet 1363.3oc0X80aaTDDeujrnDCopklG5KHsxOcQDhrg1BhJDWicbwh3Vq3RoUBonM2s1dUta2S2smaMUUpOxGIdfG3QdmuH7M.l89iu8puFRMsUDGIqLyN+42N6ryLqGFIcYwwxHj0VObdHCY8Q3QyEpoclR4BT+tHqqfGPiUrHRFqClGRiiYdHKq0umlg0VafR+7We6ATepvkUxBgdjj6xNhGvUkbG578be+dTO1C4AFReSm9tRQGouLAvy53VnPp6YzIr6S0hsFFY8AG5wUxnQJphEir13.o27QSkOUjI+i3w7S8YZh1nQfgxX2S56oQrlKpyTtu2vh8cLBrxvxnv5YQgcvC3d7E7KiFWMcARoFlwCq0NO301Ddst3vyx.d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Uj0cc7RsjOm2nfPohZx3GqT3C8DmZdESeAblpFJ8oQu50s2VwyJuB47qIn2RjKM0v937h6Wh.bZJwkG.eU7P5+GRHdOWQHOjzHeDj7p+MvcO5ImzYvv108FXqeEWNlYXDKjFwdnbHjeZmVxlcLDP1ibpuz8rQ7e13YZYem+xEX35i.AEtyKewRwX6v75lyNGlA3CzVz1MOPrJi7huLU3dwPyqzTtuWfX.0MRdhaVTWW.dyTNPXSj9yMsEdfllztXzcLFdiGJf6wOw0UOtymA2BpWmOeEz4KVAct4JnysVAct8JnyWtB57UmqN5e4M8HRAYU4.FCOLM4xx5PAER9Suoi9G4sdruC
                          

                          develop Branch / XCode 13.1
                          macOS Monterey / M1 Max

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

                            @orange The only problem with ShapeFX is the oversampling is restricted to that individual module. Engine.setMinimumSampleRate() must be called to encapsulate the entire plugin in oversampling... and that's where I'm getting the issue.

                            Dan Korneff - Producer / Mixer / Audio Nerd

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

                              @Christoph-Hart said in Scriptnode "oversample" node starting at 4x crashes in PC:

                              You could add a HQ button somewhere and do

                              if(value)
                                  Engine.setMinimumSampleRate(100000);
                              else
                                  Engine.setMinimumSampleRate(40000);
                              

                              in its callback. 100.000 will ensure that it's always 4x oversampled for lower samplerates and 40000 that it's never oversampled in non-HQ mode (using 48000 would cause oversampling in 44,1kHz).

                              It will fade out all voices and then reinitiliase the processing chain with the new samplerate .

                              Dan Korneff - Producer / Mixer / Audio Nerd

                              1 Reply Last reply Reply Quote 0
                              • orangeO
                                orange @Dan Korneff
                                last edited by orange

                                @dustbro said in 4 samples delay?:

                                @orange The only problem with ShapeFX is the oversampling is restricted to that individual module. Engine.setMinimumSampleRate() must be called to encapsulate the entire plugin in oversampling... and that's where I'm getting the issue.

                                function prepareToPlay(sampleRate, blockSize)
                                {
                                    //calculate latency
                                    const var dsp_latency = Engine.getSamplesForMilliSeconds(1); //calculated dsp latency
                                    const var os_latency = 4; //calculated oversampling latency
                                    
                                    //set total compensation
                                	Engine.setLatencySamples(dsp_latency + os_latency);
                                }
                                 
                                
                                

                                I see that in above delay compensation code you used a dynamic value (dsp_latency + os_latency).

                                AFAIK Engine.setLatencySamples should be set to a static value. This value is declared to the DAW while the initialization and it can't be changed after the plugin is loaded.

                                Since dsp_latency will change with sample rate, that might cause the crash.

                                If setting the delay compensation to a static value doesn't solve the issue, maybe the new scriptnode version will be better for this.

                                develop Branch / XCode 13.1
                                macOS Monterey / M1 Max

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

                                  @orange said in 4 samples delay?:

                                  I see that in above delay compensation code you used a dynamic value (dsp_latency + os_latency).

                                  This is actually the described method for the Latency Test sample in HISE tutorial.

                                      // This converts the 200ms delay to samples using the samplerate
                                      local numSamples = Engine.getSamplesForMilliSeconds(200.0);
                                  	
                                      // Propagate the latency to the host. This callback is as late as possible to
                                      // catch any misbehaving hosts...
                                  	Engine.setLatencySamples(numSamples);
                                  

                                  Engine.setLatencySamples should be set to a static value.

                                  In the real world I'm calculating absolute latency values for each module (in samples), adding them up, and then using Engine.setLatencySamples() to compensate for the largest possible latency. I'm just using Engine.getSamplesForMilliSeconds() as a quick way to compensate for the faux latency I set in the example.

                                  I'm not seeing any crashes on this end (that I know of :grinning_cat_face_with_smiling_eyes: ) Just the wrong calculation of Engine.getMilliSecondsForSamples() at init.

                                  Dan Korneff - Producer / Mixer / Audio Nerd

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

                                    After a little digging, I'm getting closer to the calculation issue.

                                    Calling Console.print(Engine.getSampleRate()); from inside the ScriptFX I'm using for Engine.setLatencySamples() shows this in the console:

                                    Oversampling off:

                                    Interface: 88200
                                    ScriptFX: 44100
                                    

                                    Oversampling on:

                                    Interface: 44100
                                    ScriptFX: 88200
                                    

                                    @Christoph-Hart is this because Engine.getSampleRate() is reporting the oversampled rate, and not the sample rate of the DAW?

                                    Dan Korneff - Producer / Mixer / Audio Nerd

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

                                      I'm going to try to grab the sample rate at init and store it in a variable. Then calculate the delay with that as my baseline.

                                      const var HostSampleRate = Engine.getSampleRate();
                                      

                                      Dan Korneff - Producer / Mixer / Audio Nerd

                                      pluginboiP 1 Reply Last reply Reply Quote 1
                                      • pluginboiP
                                        pluginboi @Dan Korneff
                                        last edited by

                                        @dustbro I know this thread is a bit old but did you end up figuring out the sample delay issue? I'm running into the same problem of double the amount of delay at init until I toggle the os button. Then it works as expected.

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

                                          @pluginboi I ended up making a script that toggles the oversampling back and forth.
                                          Not the most elegant way to do it, but it works

                                          Dan Korneff - Producer / Mixer / Audio Nerd

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

                                          21

                                          Online

                                          1.7k

                                          Users

                                          11.8k

                                          Topics

                                          103.2k

                                          Posts