Forum

    • Register
    • Login
    • Search
    • Categories

    Buffer.indexOfPeak is wrong

    Bug Reports
    2
    8
    54
    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.
    • ustk
      ustk last edited by ustk

      @Christoph-Hart It seems that Buffer.indexOfPeak() always throw the last sample

      it uses the same search I've made by script but they don't throw the same index (far from this in fact)
      except that in my case I don't need an abs value (but this is not the issue since the value at indexOfPeak is close to 0 anyway so it shouldn't be this one)

      for (i = 1; i < buffer.length; i++)
          {
              if (buffer[i] > max)
              {
                  index = i;
                  max = buffer[i];
              }
          }
      

      Tired to press F5 in the forum...
      Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

        Hasn't been resolved

        const var buffer = Buffer.create(64);
        
        buffer[31] = 0.6;
        buffer[42] = 0.1;
        
        Console.print(buffer.indexOfPeak()); // 42 instead of 31
        

        Tired to press F5 in the forum...
        Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

          @ustk Yeah, that was a silly one. Can you spot the mistake?

          int index = 0;
          int maxValue = 0.0f;
          
          for (int i = 0; i < numSamples; i++)
          {
          	auto thisValue = std::abs(ptr[i]);
              
          	if (thisValue > maxValue)
          	{
          		maxValue = thisValue;
          		index = i;
          	}
          }
          

          I needed to debug it because I couldn't solve it just from staring at the code 🙂

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

            @christoph-hart Hmm... Maybe dereference the read pointer?

            std::abs(*ptr[i]);
            

            Tired to press F5 in the forum...
            Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

              @ustk Nope. A hint: number types 🙂

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

                PS: The solution is in the commit 🙂

                ustk 2 Replies Last reply Reply Quote 0
                • ustk
                  ustk @Christoph Hart last edited by

                  @christoph-hart Oh of course... int

                  Tired to press F5 in the forum...
                  Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

                    @christoph-hart Too evident to jump at the eyes 🙂

                    Tired to press F5 in the forum...
                    Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

                    14
                    Online

                    742
                    Users

                    5.4k
                    Topics

                    50.4k
                    Posts