     digitalWrite(LED_BUILTIN, LOW);
 }
 
-void durationgliss(int duration, float startpitch, float endpitch, bool dir, bool recentre) {
-    unsigned long glissTime;
-    unsigned long startTime = millis();
+long durationgliss(int duration, float startpitch, float endpitch, bool dir, bool recentre) {
     int startpulse = pitchToPulse(startpitch);
     int endpulse = pitchToPulse(endpitch);
-    int glisssteps;
+    unsigned long glissTime = max(0, (duration * 1000L) -
+        (((maxPulse + startpulse) * (accelSteps / 2)) +
+         ((endpulse + maxPulse) * (accelSteps / 2))) -
+        (durationGlissCompensation * 1000L));
+    int glisssteps = glissTime / ((startpulse + endpulse) / 2);
     digitalWrite(LED_BUILTIN, HIGH);
     digitalWrite(dirPin, dir);
     delayMicroseconds(pulseWidth);
     for (int i=0; i<accelSteps; i++) {
         onestep(map(i, 0, accelSteps, max(maxPulse, startpulse), startpulse));
     }
-    // TODO this is only an approximation, basing deccel time on accel time
-    // deccel time should be accelSteps * avg(endpulse, max(maxPulse, endpulse))
-    glissTime = (duration - (millis() - startTime)) * durationGlissFactor;
-    glisssteps = (glissTime * 1000) / ((startpulse + endpulse) / 2);
     for (int i=0; i<glisssteps; i++) {
-        // TODO log map
         onestep(map(i, 0, glisssteps, startpulse, endpulse));
     }
     for (int i=0; i<accelSteps; i++) {

    float i = ((71 - constrain(pitch, 36, 72)) * 71) / 33;
    float p = 1 - log10(((72 - i) * 0.125) + 1);
    return 500 + (3500 * p);
}

void flashled() {

    }
    if (recentre) findsensor(max(maxPulse, endpulse));
    digitalWrite(LED_BUILTIN, LOW);
    return glissTime;
}

void test(int style) {
