public void calculatePitch()
    {
        if( channel != null && channel.attachedSource == this &&
            channelJavaSound != null )
        {
            // If not using Doppler effect, save some calculations:
            if( SoundSystemConfig.getDopplerFactor() == 0 )
            {
                channelJavaSound.setPitch( pitch );
            }
            else
            {
                float SS = 343.3f;

                Vector3D SV = velocity;
                Vector3D LV = listener.velocity;
                float DV = SoundSystemConfig.getDopplerVelocity();
                float DF = SoundSystemConfig.getDopplerFactor();
                Vector3D SL = listener.position.subtract( position );

                float vls = SL.dot( LV ) / SL.length();
                float vss = SL.dot( SV ) / SL.length();

                vss = min( vss, SS / DF );
                vls = min( vls, SS / DF );
                float newPitch = pitch * ( SS * DV - DF * vls ) /
                                         (SS * DV - DF * vss );
                
                if( newPitch < 0.5f )
                    newPitch = 0.5f;
                else if( newPitch > 2.0f )
                    newPitch = 2.0f;

                channelJavaSound.setPitch( newPitch );
            }
        }
    }