Sampling Rate

Official forum for open source FreePIE discussion and development.
Post Reply
User avatar
brantlew
Petrif-Eyed
Posts: 2220
Joined: Sat Sep 17, 2011 9:23 pm
Location: Menlo Park, CA

Sampling Rate

Post by brantlew »

One thing that I recently noticed is that the sampling/update frequency in FreePIE is much higher than GlovePIE. This is great for things like head-tracker emulation but has some unintended consequences elsewhere. In particular with mouse emulation the GlovePIE command

mouse.DirectInputX += 5;

and the FreePIE command

mouse.DeltaX = 5;

act very differently. The FreePIE mouse will "fly" across the screen super fast. Even setting DeltaX = 1 (the lowest value) moves the mouse so quickly that it is sometimes difficult to aim it and stop precisely on screen elements like title-bars and menu items.

I am not even sure if the frequency is capped. If not, then the same script on one machine may act differently on a slower machine. We should consider picking a default frequency (60Hz ?), allowing a configurable polling frequency, and enforcing that frequency so that scripts will act the same from machine to machine.

User avatar
brantlew
Petrif-Eyed
Posts: 2220
Joined: Sat Sep 17, 2011 9:23 pm
Location: Menlo Park, CA

Re: Sampling Rate

Post by brantlew »

Other possibilities in regards to mouse emulation:

- It might be useful to accept and process fractional values for mouse.DeltaX, so that at high sampling frequencies you can easily generate slow mouse movements.

- It might be useful to provide frequency normalized functions. For example, "mouse.XPixPerSec = 50" would set a fixed motion rate regardless of the sampling frequency. Also "mouse.XInchPerSec = 1" would set a fixed motion rate for all frequencies and for all monitor resolutions.

Maybe there is a more elegant way to accomplish this using the filters() library? Like "mouse.DeltaX = filters:InchesPerSec(1)" or something like that?

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Sampling Rate

Post by CyberVillain »

Hmm pretty complex, right now the lua worker sleeps one ms per iteration to avoid starving a CPU core. That's means around about 16ms which means a freq of 1000/16. To get a stable and reliable frequency we would need to utilize the real time clock and that introduces a lot of complexity also could create problems if the game running In foreground uses it.


I will think some on this topic :)

User avatar
brantlew
Petrif-Eyed
Posts: 2220
Joined: Sat Sep 17, 2011 9:23 pm
Location: Menlo Park, CA

Re: Sampling Rate

Post by brantlew »

Not sure about the C# syntax but I do things like this in C to maintain a processing frequency.

Code: Select all

#include <time.h>

void main() {

   long FREQUENCY = 30;
   
   while (true) {
      clock_t start = clock();   // returns milliseconds
            
      // Do some processing 

      long processing_time = (long)(clock() - start);
      long delay = (1000 / FREQUENCY) - processing_time;    // precision can be improved with sub-millisecond timers
      Sleep(delay);
   }
}


** The algorithm can be improved since it doesn't take into account inaccuracies in the Sleep() call and inconsistencies in thread scheduling.

CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Sampling Rate

Post by CyberVillain »

Problem with sleeping a thread is that its not accurate enough, it will sleep a minimum of ~16ms, but how long it will sleep is not guaranteed. When the time has elapsed it will be put in the OS ready queue and idle their until its turn to be resumed. Its not language specific but OS specific.

but maybe its good enough, could have it as an option under settings

edit: Lol didnt see your comment under the code example, you state the very exact thing :D

edit2: Btw, using the Update event on the Plugin will enforce the same update frequence on the emulation as on the input. I use this with Freetrack > Mouse and it works very well

Post Reply

Return to “FreePIE”