gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > Envelopes?!

#37584 - ProblemBaby - Sun Mar 13, 2005 3:36 pm

I know how they work, but it is some things I dont understand..

First:
Say Ive the first point at (0, 0) and the second at (2, 2) and third at (4,4)
Is this correct:
Tick 0: Vol = 0
Tick 1: Vol = 1
Tick 2: Vol = 2
Tick 3: Vol = 2
Tick 4: Vol = 3
Tick 5: Vol = 4
etc...
or should it continue right after?
then a interesting question appears what about the delta value 0 or 1 between two points..
should that be recoqnized?
some info whould be great!

edit: I refer to the XM format

#37594 - DekuTree64 - Sun Mar 13, 2005 11:01 pm

Yep, that's exactly right. Just interpolate between the current node and the next node, using the current tick. It does involve a divide, but you could make a reciprocal table to speed that up.

The actual updating process goes something like this
Code:
tick++;
while (tick >= nodeX[nextNode])
{
   curNode = nextNode;
   if (curNode >= end)
      // deal with looping/ending
   else
      nextNode = curNode+1;
}

That while loop will deal with the 0-delta nodes, just jumping past them.
The 'end' there is either the last node of the loop, or nodeCount-1, because you want to go into your special end processing immediately when you get to the last node.

Then calculating the final volume based on the tick:
Code:
if (nodeX[nextNode] == nodeX[curNode])
   envVol = nodeY[curNode];
else
   envVol = nodeY[curNode] +
      ((nodeY[nextNode] - nodeY[curNode]) *
       (tick - nodeX[curNode]) /
       (nodeX[nextNode] - nodeX[curNode]));

Check for the divide by 0 there for the times when curNode and nextNode both point to the same node, like a 0-length loop, or when you hit the end and don't loop.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#37595 - ProblemBaby - Mon Mar 14, 2005 12:02 am

Thanks for the information.[/code]

#37600 - ProblemBaby - Mon Mar 14, 2005 1:26 am

In ModPlugTracker it seems like it updates the first tick as well
so The very first volume will actually be 1 in my case.