Forum

    • Register
    • Login
    • Search
    • Categories

    Buffer.indexOfPeak is wrong

    Bug Reports
    2
    8
    122
    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];
              }
          }
      

      I can't help pressing F5 in the forum...

      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
        

        I can't help pressing F5 in the forum...

        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]);
            

            I can't help pressing F5 in the forum...

            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

                  I can't help pressing F5 in the forum...

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

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

                    I can't help pressing F5 in the forum...

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

                    3
                    Online

                    1.2k
                    Users

                    7.0k
                    Topics

                    64.8k
                    Posts