I am playing with the Chapter 10 sampler for doppler effect (UFO). Its intent seems to be to put a sphere in a circular orbit at a distance from the camera, and to implement a doppler effect on the sound by playing with the sound’s velocity.

The UFO does not appear to follow a circular orbit, and the sound does not shift in an expected manner.

Recommendation: remove the call to setReverbEnabled. (a) It has nothing to do with a doppler effect, and (b) it masks the effect.

Defect repair: Update simpleUpdate as noted below:

public void simpleUpdate(float tpf) {

// this formula calculates coordinates of the UFOs orbit

float dx = (float) (Math.sin(angle) * xDist);

float dz = (float) (-Math.cos(angle) * zDist);

//x += dx * tpf; // NO! angle is already based on tpf…

//z += dz * tpf;

// technically x = (float)(Math.cos(angle) * xDist, same for z,

// but we’ve already computed these in dx, dz

// (taking advantage of velocity being pi/2 out of phase with position…)

x = -dz;

z = dx;

angle += tpf * rate;

if(angle>FastMath.TWO_PI) angle=0;

/* Delete this code…

if (angle > FastMath.TWO_PI) {

angle = FastMath.TWO_PI;

rate = -rate;

} else if (angle < -0) {

angle = -0;

rate = -rate;

}

*/