+static void millisleep(int ms)
+{
+ struct timespec ts;
+
+ PARA_INFO_LOG("sleeping %dms\n", ms);
+ if (ms < 0)
+ return;
+ ts.tv_sec = ms / 1000,
+ ts.tv_nsec = (ms % 1000) * 1000 * 1000;
+ nanosleep(&ts, NULL);
+}
+
+/*
+ * This implements the inverse function of t -> t^alpha, scaled to the time
+ * interval [0,T] and the range given by old_vol and new_vol. It returns the
+ * amount of milliseconds until the given volume is reached.
+ */
+static unsigned volume_time(double vol, double old_vol, double new_vol,
+ double T, double alpha)
+{
+ double c, d, x;
+
+ if (old_vol < new_vol) {
+ c = old_vol;
+ d = new_vol;
+ } else {
+ c = new_vol;
+ d = old_vol;
+ }
+
+ x = T * exp(log(((vol - c) / (d - c))) / alpha);
+ assert(x <= T);
+ if (old_vol < new_vol)
+ return x;
+ else
+ return T - x;
+}
+