HISE Logo Forum
    • Categories
    • Register
    • Login

    Buffer.indexOfPeak is wrong

    Scheduled Pinned Locked Moved Bug Reports
    8 Posts 2 Posters 333 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 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];
              }
          }
      

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

      1 Reply Last reply Reply Quote 1
      • ustkU
        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
        

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

        Christoph HartC 1 Reply Last reply Reply Quote 1
        • Christoph HartC
          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 :)

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

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

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

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

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

              @ustk Nope. A hint: number types :)

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

                PS: The solution is in the commit :)

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

                  @christoph-hart Oh of course... int

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

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

                    @christoph-hart Too evident to jump at the eyes :)

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

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

                    28

                    Online

                    1.8k

                    Users

                    12.1k

                    Topics

                    105.1k

                    Posts