Click here to Skip to main content
15,849,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How Can I set Noise In Image ? Pin
nv316-Mar-13 3:16
nv316-Mar-13 3:16 
QuestiontimeGetTime() is unreliable on my computer too, not monotonic! Pin
Robert Inventor14-Mar-13 19:04
Robert Inventor14-Mar-13 19:04 
AnswerMessage Closed Pin
14-Mar-13 19:15
Robert Inventor14-Mar-13 19:15 
GeneralMessage Closed Pin
14-Mar-13 19:20
Robert Inventor14-Mar-13 19:20 
GeneralMessage Closed Pin
14-Mar-13 19:53
Robert Inventor14-Mar-13 19:53 
GeneralMessage Closed Pin
14-Mar-13 20:19
Robert Inventor14-Mar-13 20:19 
AnswerRe: timeGetTime() is unreliable on my computer too, not monotonic! Pin
Robert Inventor19-Mar-13 8:31
Robert Inventor19-Mar-13 8:31 
QuestionQueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor14-Mar-13 16:50
Robert Inventor14-Mar-13 16:50 
Hi there,

I'm using the high performance counter for timing musical notes - and have run into a problem. It doesn't time them accurately. What should be a regular rhythm is irregular.

When I debug to find out what is happening, then the numbers returned by QueryPerformanceCounter(..) sometimes change direction - in this code below, if I put a break point on the
C++
if(ddwt<ddwt_was)
 ddwt=ddwt;

then it gets triggered.

As you see, I have requested that the thread runs on core 1 of dual core machine. I'm testing it on a laptop with two processors and two cores in each processor.

Is SetThreadAffinityMask(..) perhaps not enough to ensure that the thread runs on a single core? Or is there some other reason for it?

Is there any way to fix it so I can get sub-millisecond timing working accurately on any computer?

Thanks for your help.

C++
LARGE_INTEGER HPT_PerformanceCount,HPT_PerformanceFrequency;
int found_HighPerformanceTimer_capabilities;
BOOL bHasHighPerformanceTimer;
double HighPerformanceTimer(void)
{
 // http://www.seethroughskin.com/blog/?p=133
 DWORD threadAffMask=SetThreadAffinityMask(GetCurrentThread(),1);
 DWORD threadAffMaskNew=0;
  if(found_HighPerformanceTimer_capabilities==0)
 {
  bHasHighPerformanceTimer=QueryPerformanceFrequency(&HPT_PerformanceFrequency);
  found_HighPerformanceTimer_capabilities=1;
 }
 if(HPT_PerformanceFrequency.QuadPart==0)
 {
  SetThreadAffinityMask(GetCurrentThread(),threadAffMask );
  return timeGetTime();
 }
 QueryPerformanceCounter(&HPT_PerformanceCount);
 threadAffMaskNew=SetThreadAffinityMask(GetCurrentThread(),threadAffMask );
 {
  __int64 count=(__int64)(HPT_PerformanceCount.QuadPart);
  __int64 freq=(__int64)(HPT_PerformanceFrequency.QuadPart);
  double dcount=(double)count;
  double dfreq=(double)freq;
  double ddwt=dcount*1000.0/dfreq;
#ifdef _DEBUG
  static double ddwt_was;
  if(ddwt_was!=0)
  if(ddwt<ddwt_was)
   ddwt=ddwt;
  ddwt_was=ddwt;
#endif
  return ddwt;
 }
}

AnswerRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor14-Mar-13 19:07
Robert Inventor14-Mar-13 19:07 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex15-Mar-13 1:24
dusty_dex15-Mar-13 1:24 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor18-Mar-13 15:44
Robert Inventor18-Mar-13 15:44 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex18-Mar-13 23:08
dusty_dex18-Mar-13 23:08 
AnswerRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor19-Mar-13 7:19
Robert Inventor19-Mar-13 7:19 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex19-Mar-13 9:34
dusty_dex19-Mar-13 9:34 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 11:10
Robert Inventor20-Mar-13 11:10 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 12:12
Robert Inventor20-Mar-13 12:12 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex20-Mar-13 12:18
dusty_dex20-Mar-13 12:18 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 13:15
Robert Inventor20-Mar-13 13:15 
QuestionHelp in Win32 programming with c++ Pin
naseer86114-Mar-13 9:44
naseer86114-Mar-13 9:44 
AnswerRe: Help in Win32 programming with c++ Pin
NotPolitcallyCorrect14-Mar-13 9:50
NotPolitcallyCorrect14-Mar-13 9:50 
GeneralRe: Help in Win32 programming with c++ Pin
naseer86118-Mar-13 10:41
naseer86118-Mar-13 10:41 
AnswerRe: Help in Win32 programming with c++ Pin
Maximilien14-Mar-13 9:54
Maximilien14-Mar-13 9:54 
AnswerRe: Help in Win32 programming with c++ Pin
Captain Price16-Mar-13 3:55
professionalCaptain Price16-Mar-13 3:55 
QuestionNeed a free image library, png, Visual Studio 6.0 Pin
Andrlage14-Mar-13 6:52
Andrlage14-Mar-13 6:52 
AnswerRe: Need a free image library, png, Visual Studio 6.0 Pin
Richard MacCutchan14-Mar-13 7:22
mveRichard MacCutchan14-Mar-13 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.