HISE Logo Forum
    • Categories
    • Register
    • Login

    SNEX and interpolation

    Scheduled Pinned Locked Moved General Questions
    8 Posts 3 Posters 511 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.
    • ustkU
      ustk
      last edited by ustk

      @Christoph-Hart I'm trying to interpolate between values that are changing every 2000 samples.
      But instead of the linear result, I only get spikes...

      float old = 0.0f;
      float newVal = 0.0f;
      int count = 0;      // Sample counter
      float mu = 0.0f;    // Sample interpolation between two values (0-1 based)
      
      /** Mono sample processing callback */
      float processSample(float input)
      {
          if (count > 2000){  
      
              old = newVal;
      
              newVal = (Math.random() - 0.5f) * 2.0f;
      
              count = 0;
          }
          
          count++;
          
          mu = (float)(count / 2000);
          
          // Linear Interpolation
         val = old * (1.0f - mu) + newVal * mu;
      
         return val;
      }
      
      

      If I just return newVal, it works. But As soon as I interpolate, shit happens...
      I don't think the problem comes from the formula itself, but probably more the way I handle things with my poor coding... ☺
      Maybe around mu or count...

      Can't help pressing F5 in the forum...

      giftliftG ustkU 2 Replies Last reply Reply Quote 0
      • giftliftG
        giftlift @ustk
        last edited by

        @ustk, have you tried it with else?

            else
            {
              count++;
              mu = (float)(count / 2000);
              // Linear Interpolation
              val = old * (1.0f - mu) + newVal * mu;
              return val;
            }
        ustkU 1 Reply Last reply Reply Quote 0
        • ustkU
          ustk @ustk
          last edited by ustk

          @ustk Ok so the problem comes from the old variable that doesn't keep the value. It works on the first pass, then returns to 0,
          which explains the "spikes"...
          Any C++ guy to the rescue? :)

          Can't help pressing F5 in the forum...

          1 Reply Last reply Reply Quote 0
          • ustkU
            ustk @giftlift
            last edited by

            @giftlift Oh we crossed! Thank mate I'm testing this :)

            Can't help pressing F5 in the forum...

            1 Reply Last reply Reply Quote 0
            • ustkU
              ustk
              last edited by

              Ok I begin to understand. Instead of taking a reference (if it is the right term...) of a variable for the calculations, I change the variable itself so:

              double thing = old * 2.0;
              

              changes old, am I right?

              Too hard form me damn C++... :)

              Can't help pressing F5 in the forum...

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

                No, old is not changed here (unless I messed something up and the compiler reused the register for the old variable). C++ behaves just like Javascript in that case :)

                But if I were you I wouldn't touch SNEX at the moment because it's currently rewritten from the ground up. The goal is to make it standard compliant enough so that it can compile the C++ code that is generated when you export a scriptnode patch, but that means that these processXXX functions will be deprecated and it will be replaced by the standard C++ API for scriptnode elements.

                This will lead to breaking changes also for exported nodes, but there will be a migration tool that smoothes this process (I have a lot of scriptnode FX in PercX that need to be ported too).

                ustkU 1 Reply Last reply Reply Quote 1
                • ustkU
                  ustk @Christoph Hart
                  last edited by ustk

                  @Christoph-Hart Cool to know ;) but no worries it's good learning for me anyway regarding my level...

                  I'm pretty sure something wrong is happening then. Because if I just comment the line above (and '''thing''' is not used anywhere in the code) the '''old''' output is not the same so yes, the variable changed...

                  This will lead to breaking changes also for exported nodes, but there will be a migration tool that smoothes this process

                  Oh man, I hope so much!
                  My main project is 300 nodes and 100 parameters... If I can't reuse the graph, just give me a rope 😰

                  Can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • ustkU
                    ustk
                    last edited by

                    @Christoph-Hart I placed the interpolation process before the if statement and it works now. I don't understand why though...

                    Can't help pressing F5 in the forum...

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

                    33

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    102.3k

                    Posts