Advertisement

Displaying Frame Rate

Started by October 20, 2000 09:22 PM
4 comments, last by Shannon Barber 24 years, 2 months ago
I always wondered why people posted asking about how to calculate and display the frame rate. Well I finally started displaying mine, and it was kinda hard to read and twiddled a god awful lot. So I applied a low-by-pass single pole digital filter @10.0Hz, and that wasn't enough filteration so I bumpped it to 0.5Hz and it looks ok. It then occured to me that most people probably don't know what a low-by-pass filter is, much less how easy it is to implement (for a single pole). You can lower the cut-off frequency (the 0.5f on the filter = line), to smooth the change more - but that makes it lag more too.
                    
		static float e = 2.718281828f;
		static float filter = (float)pow(e, -2.0f * 0.5f / 1000.0f); //0.5Hz filter, time in ms, so /1000.0
		static DWORD timesnap=clock();
		static float framerate= 33.3f;//guess at initial framerate, so it doesn't lag so bad on init
		DWORD now = clock();
		DWORD elapsed = now - timesnap;
		timesnap = now;
		float factor = (float)pow(filter, (float)elapsed);
		float ifactor = 1.0f - factor;
		if(elapsed==0.0f)
			framerate = 33.3f; //don't divide by zero, that's bad
		else
			framerate = framerate * factor + ifactor * 1000.0f / (float)elapsed;//1000.0f to convert ms to sec (again)
			//framerate = 1000.0f /(float)elapsed; //crappy framerate twiddle

		char stemp[80];
		sprintf(stemp,"FrameRate: %.2f", framerate);
		CString strfr(stemp);
		GetDlgItem(IDC_STATIC_FRAME)->SetWindowText(strfr);
                    
Edited by - Magmai Kai Holmlor on 10/20/00 9:26:02 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
May I ask were you learned that? Did you learn from a book or school if a book could you tell me the title?
Advertisement
Years of work in the computer command and control industry demands that you know how to apply a good filter But usually I use someone else's pre-canned filter (with all kinds of settings).

My boss gave me that algorithm some time ago. You would find a complete filter in a Digital Signal Processing book, advanced Electrical Engineering topic (masters level).

...

So is everyone part of the GD Net staff now, or did I get promoted? (me stinks das der bugggin en dar webbinworkins)

Edited by - Magmai Kai Holmlor on October 21, 2000 1:58:33 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I always wondered where i''d use the e^2.718 in real life.



Or, instead of giving the instantaneous FPS and trying to filter the predictably varying result, you can count the actual frames, per second.

Then you either could only update once per second, or you would effectively be applying a very low pass filter, and it would lag even worse than the algorithm above. If the framerate doesn''t change that much, it wouldn''t matter much... but my framerate has changed quite a bit (-10fps) depending on what else I was doing.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement