audio: Fix time diff to always return positive numbers

Change-Id: I62f835f95fc1d1a671cfdb2e6e6ac1758524235f
tirimbino
Andreas Schneider 8 years ago
parent 5b75c5763c
commit 58735a9cf9
  1. 15
      audio/audio_hw.c

@ -248,7 +248,6 @@ static const struct string_to_enum out_channels_name_to_enum_table[] = {
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));
@ -262,14 +261,8 @@ struct timespec time_spec_diff(struct timespec time1, struct timespec time0) {
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;
}
@ -817,8 +810,8 @@ static int enable_snd_device(struct audio_device *adev,
#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;

Loading…
Cancel
Save