SDL_GetTicks() goes backwards

And in gentoo you would simply

emerge libsdlOn Thursday 26 December 2002 12:31, Adilson Oliveira wrote:

Daniel Phillips wrote:

Most of the developers I know are on Debian, there is a reason for
this. For example (bringing this back to marginally on-topic), to
install SDL:

apt-get install sdl1.2 --fix-missing

Just to add a note: Conectiva Linux uses apt-get too.

The Linux kernel has been suitable for pro audio use for a couple of
years now – and the app support is really reaching critical mass.
Check out http://ardour.sf.net for a really high-quality Pro Tools
workalike (and it’s usable even as an alpha).

'Cept Ardour doesn’t do any MIDI sequencing, nor does it support
instrumentation plugins. It’s simply a DAW, and calling it a Pro Tools
workalike is like calling a handheld computer an advanced supercomputer.
Ardour needs quite a bit more time and effort before it’ll even start to
touch Pro Tools, Nuendo/Cubase SX, etc…

–>Neil-------------------------------------------------------------------------------
Neil Bradley In the land of the blind, the one eyed man is not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898

Hey David,
I’m having the same prob with SDL_GetTicks() once the NTP synchronize the timer stop counting in other words goes backward !
so i was looking at what RDTSC is doing here .
your code is to replace this ?
" gettimeofday(&now, NULL);
ticks=(now.tv_sec-start.tv_sec)*1000 +
(now.tv_usec-start.tv_usec)/1000;
return(ticks);"
"

18 YEARS LATER

That just might be a world record or something! :smiley:

RDTSC is CPU specific, and requires inline assembly language. I’ve used in in the past, but can’t seem to find it in any of my… less ancient code. Closest would be Audiality 2 (audio engine), which implements a2_GetMicros() via QueryPerformanceCounters() on Windows:

If you’re using SDL, you should probably be using SDL2, which has SDL_GetPerformanceCounter() for this purpose.

Is there a solution for integrating RDTSC with SDL1.2.15 !

Well, yes; inline asm, compiler intrinsics, or system calls, depending on compiler and platform.

Since you’re mentioning gettimeofday(), I’m assuming you’re on some Un*x, and using GCC…? There are various examples of that around, but I can’t seem to find a clean one that also includes figuring out the CPU clock rate.

Something like this for reading the actual counter - though this is so old that one couldn’t even assume that GCC knew about the rdtsc instruction!

inline unsigned long long int rdtsc(void)
{
        unsigned long long int x;
        __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
        return x;
}

Here’s a less ancient variant, in macro form:

#define rdtscll(ret) \
{ \
        unsigned int low, high; \
        asm volatile("rdtsc" : "=a"(low), "=d"(high)); \
        ret = (low) | ((uint64_t) (high) << 32); \
}

Another, more portable, option is clock_gettime(CLOCK_MONOTONIC, ...). This is a POSIX API, and CLOCK_MONOTONIC is a clock that doesn’t go backwards when the civil time changes (for example, through NTP).

On Windows you can use QueryPerformanceCounter.