HISE Logo Forum
    • Categories
    • Register
    • Login

    Little buffer query

    Scheduled Pinned Locked Moved Solved Scripting
    5 Posts 3 Posters 124 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
      last edited by

      I'm running a loop over a mono sample, loaded as a buffer, and I'm outputting the amplitude every 5000 samples.

      But I'm getting unexpected values as I get towards the end of the sample.

      Here is the waveform

      cd5d29a6-089c-42e5-8b6b-dd1fc9d3dda3-image.png

      And here is an example of some of the final values (in dB) I'm getting in the output.

      Interface: 21201.8ms : -2.999999518003015
      Interface: 21315.2ms : -2.999999518003015
      Interface: 21428.6ms : -2.999999518003015
      Interface: 21542ms : -2.999999518003015
      Interface: 21655.3ms : -2.999999518003015
      Interface: 21768.7ms : -2.999999518003015
      Interface: 21882.1ms : -2.999999518003015
      Interface: 21995.5ms : -2.999999518003015
      Interface: 22108.8ms : -2.999999518003015
      

      Anyone know what's going on?

      	local selection = Sampler1.createSelection("");
      	local stepSize = 5000;
      	
      	for (x in selection)
      	{
      		local buf = x.loadIntoBufferArray();
      
      		for (i = 0; i < buf.length; i++)
      		{
      			for (j = stepSize; j < buf[i].length; j += stepSize)
      			{
      				Console.print(Engine.getMilliSecondsForSamples(j) + " : " + Engine.getDecibelsForGainFactor(buf[i].getMagnitude(j - stepSize, j)));
      			}
      		}
      	}
      

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

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

        @d-healey Are you reading past the array? what if buf[i].length - j < 5000?

        d.healeyD 1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey @Christoph Hart
          last edited by

          @Christoph-Hart I thought that too so tested with

          Console.print(j + " : " + buf[i].length);

          The last line output is:

          Interface: 975000 : 976752
          

          And since I'm never reading beyond j I think that should be good. Or perhaps I'm misunderstanding the question.

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

          ustkU 1 Reply Last reply Reply Quote 0
          • ustkU
            ustk @d.healey
            last edited by ustk

            @d-healey this seems wrong, the second parameter numSamples should be your stepSize (protected), not the position j

            Also you need to protect it when reaching the end as Chris mentioned

            for (j = stepSize; j < buf[i].length; j += stepSize)
            {
                local position = j - stepSize;
                local numSamples = Math.min(buf[i].length - position, stepSize); // protect
                buf[i].getMagnitude(position, numSamples);
            }
            

            And why not starting the loop at 0 to save some calculations

            for (j = 0; j < buf[i].length; j += stepSize)
            {
                local numSamples = Math.min(buf[i].length - j, stepSize); // protect
                buf[i].getMagnitude(j, numSamples);
            }
            

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

            d.healeyD 1 Reply Last reply Reply Quote 1
            • d.healeyD
              d.healey @ustk
              last edited by

              @ustk Oh, you're right, I was thinking it was start samples and end samples, but it's start samples and num samples. Now I get it, thanks!

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

              1 Reply Last reply Reply Quote 0
              • d.healeyD d.healey marked this topic as a question on
              • d.healeyD d.healey has marked this topic as solved on
              • First post
                Last post

              24

              Online

              1.8k

              Users

              12.1k

              Topics

              104.9k

              Posts