输入滞后测试仪

时间:2013-07-01 12:12:10

标签: c++ c openmp latency

我创建了一个应该能够测试输入延迟的简单程序。

我的意思是计算机发送到屏幕的内容与按下与之关系的密钥之间的延迟。这是用于测试在线第一人称射击游戏的设置。

该程序通过以特定节奏以黑白方式闪烁控制台窗口,并要求用户按空格键或任何其他键来达到该节奏。它使用getch来确定何时按下了键,并使用OpenMP运行与闪烁控制台并行处理getch的函数。

这是否可以用作基本的自由输入滞后测试,或者如果不是这样的话我应该做些什么呢?

//Fdisk's input lag tester
#include <omp.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;

//My global variables. My functions run in parallel so it's easier to use global variables here.
    int i=0;
    long int outp[11];
    long int inpu[11];

//This function takes the input
int inputfunc() {
while(i<11) {
    getch();  //Takes the key input
    inpu[i]=clock(); //Marks the time the key was pressed
    if(inpu[i]-outp[i]>=0 && inpu[i]-outp[i]<5000) //Checks if result is valid
    i++; //Moves the program along so it doesn't blink for eternity
}
return 0;
}

//This function causes the screen to change color
int outputfunc() {
while(i<11) {
    system("color F0"); //Changes screen to white
    outp[i]=clock(); //Marks the time when screen became white
    usleep(400000); //Pause a bit here
    system("color 0F"); //Make the screen black again
    usleep(400000); //Pause again
}
return 0;
}
int main() {
    printf("Fdisk's Input Lag Tester\n\nPress any key when the screen flashes WHITE.     Let it flash a few times before pressing anything, so you can get used to the     rhythm. Using the spacebar is recommended. Be as precise as possible with what you     see on screen. A multicore or multithreading processor is required.\n");
    system("pause"); //Sorry my coding is bad
    system("cls"); //Again
 #pragma omp parallel sections //Parallel sections, these run in parallel on a dual core or dual threading machine
 {
     #pragma omp section
     {
         outputfunc(); //The output function, changes the screen's color
     }
     #pragma omp section
     {
         inputfunc();  //The input functions, waits for keypresses
     }
 }
 long int x;
 for(i=0;i<11;i++) {
x=x+(inpu[i]-outp[i]); //Difference between input and output=latency. This adds them up so we can take a mean value.
}
 x=x/11; //This takes the mean value
 x=x*(1000/CLOCKS_PER_SEC); //I think clock is always set to milliseconds but in case it's not
 printf("Your input latency: %ims\n",x); //Gives the input latency to the user
 system("pause"); //Pauses the program so it doesn't exit in case not running it from a command line
 usleep(10000000); //Prevents someone from mindlessly pressing space to exit
 system("pause"); //Another redundancy to prevent accidental quitting
 }

1 个答案:

答案 0 :(得分:0)

我相信您的测试程序不太可能提供您尝试测量的滞后的粗略估计。这取决于用户的输入,他是否有任何节奏感,他的手眼协调能力,如果他有咖啡等等......同时请记住,人类很难区分两个较少的事件相距约30ms,这会对结果的精确度产生影响。

我必须在不同的环境中对计算机的延迟进行类似的评估,但我相信我使用的程序可以根据您的情况进行调整。我需要测量系统的端到端延迟:数码相机 - &gt;图像采集和处理硬件 - &gt;窗口应用 - &gt;显示。用相机我拍摄了相机闪光灯。然后,我使用第二台相机(高速)拍摄显示器上的闪光灯及其显示屏。通过第二个摄像机的视频,我可以测量原始闪光灯与显示器上显示屏之间经过的帧数。

在您的情况下,您可以拍摄任何相机并拍摄键盘和显示器,并将视频保存到文件中。您可以按键盘并在显示器上观看结果。使用任何视频编辑软件,您可以测量结果可见的帧数。当然,精度取决于相机的帧速率,例如,如果您有标准的30 fps相机,那么您的测量延迟将是33 ms的倍数。如果您需要更高的精度,您可以随时使用帧率更高的相机。