maxdistance = 1000
mindistance = 10
minpitch = 15
maxpitch = 90

distance = distance - 25*direction

if (distance < mindistance)
 distance = mindistance
 pitch = minpitch
else if (distance > maxdistance)
 distance = maxdistance
 pitch = maxpitch
endif 

