How to increase the regularity of the scrolling of the frames? How to have them with a precision of a perfect clock?

Hello everybody,
I’m trying to make music by trigging note each time I made a rotation.
To rise up in precision, I rise the frameRatio to 90. But it doesn’t change the regularity of note’s trigging.
I have a program computing the pride between each rotation and there is a better consistency between to period but is there an other solution?

Look at millis() please

Milliseconds

Search timer here in the forum

I already have a timer in my program. It calculates the period between two rotations. It’s pretty constant but sometimes I lose 30ms over a 1000ms period and you can hear it. My program doesn’t need to have a lot of memory or a big processor, the animation is simple. It calculates a rotation with a polar equation. I have phase x and phase y and I transform them into a virtual position between 0 and 6400. I need this position very consistently when I do not change the frequency.
Likewise, when you put a timer on a screen next to the frame scroll and stop the program, you may see a discrepancy between the elapsed time and the number of elapsed frames. How to gain consistency?

1 Like

Hi @bking, I made this sketch to record millis() on each execution of draw(). To avoid delays from printing it records a burst of results to an array and then prints them out. You can see how well your PC performs. I’ve included the results from myPC for frameRates 5 and 50. Ideally we’d expect 200 and 20 respectively. You can see it’s not very good. This is the simplest possible action within draw, not actually doing anything real. When you add real actions it will probably get worse.

You haven’t said what PC or OS you are using. I think it’s not good enough for your requirements, and you’ll have to move the critical part of the project to an Arduino or other dedicated hardware.


final boolean T = true;
final boolean F = false;

long results[] = new long[nof_results];
int result_ix;
boolean do_print = F;

void setup()
{
  frameRate(50);
  result_ix = 0;
}

long millis0 = 0;
long millis1;

void draw()
{
  if (frameCount > 10 && result_ix < nof_results)
  {
    millis1 = millis();
    results[result_ix++] = millis1 - millis0;
    millis0 = millis1;
  }
  
  if (result_ix >= nof_results)
  {  
    for (result_ix = 0; result_ix < nof_results; result_ix++)
    {
      print(results[result_ix++]);
      print(" ");
    }
    result_ix = 0;
    println();
    println();
  }
}

frameRate(5)

2537 200 198 200 214 201 213 204 209 190 199 195 199 198 203 204 210 189 186 195 187 200 192 186 193 202 207 200 186 195 197 186 190 212 201 188 205 202 202 199 204 209 201 208 206 202 211 199 193 203

frameRate(50)

463 20 25 32 24 19 13 32 24 31 22 29 19 8 19 9 33 20 20 24 20 11 20 12 20 20 5 12 19 13 31 23 30 14 6 17 9 19 20 32 12 6 16 8 18 16 19 11 19 12

Hello @bking ,

This topic may be of interest:

:)

Can’t help you here

Obviously when you using windows it’s not a
precise operating system. Not each frame has the same
amount of millis() even with frameRate(5000);