struct timespec time_spec_diff(struct timespec time1, struct timespec time0) {
struct timespec ret;
int xsec = 0;
- int sign = 1;
if (time0.tv_nsec > time1.tv_nsec) {
xsec = (int) ((time0.tv_nsec - time1.tv_nsec) / (1E9 + 1));
time0.tv_sec -= xsec;
}
- ret.tv_sec = time1.tv_sec - time0.tv_sec;
- ret.tv_nsec = time1.tv_nsec - time0.tv_nsec;
-
- if (time1.tv_sec < time0.tv_sec) {
- sign = -1;
- }
-
- ret.tv_sec = ret.tv_sec * sign;
+ ret.tv_sec = abs(time1.tv_sec - time0.tv_sec);
+ ret.tv_nsec = abs(time1.tv_nsec - time0.tv_nsec);
return ret;
}
#ifdef DSP_POWEROFF_DELAY
clock_gettime(CLOCK_MONOTONIC, &activation_time);
- elapsed_time = time_spec_diff(mixer_card->dsp_poweroff_time,
- activation_time);
+ elapsed_time = time_spec_diff(activation_time,
+ mixer_card->dsp_poweroff_time);
if (elapsed_time.tv_sec == 0) {
long elapsed_usec = elapsed_time.tv_nsec / 1000;