function newi = NewDelay(i,v)
%compute the resampled (delayed) value for sample i
% given the parameters in the voice array for voice v.
    %  Here delay goes from min to max, and the specified  delay time
% affects the re-indexing.  We think about this as an 'additive'
    % effect, in the sense that a constant delay value will result
% in a constant value being added to each index.
    % when the sweep is a sine wave, the delay and pitch effects
%  thus seem similar tho they have different semantics.


global N Fs;
global DEL_ABS DEL_E DEL_HZ DEL_MIN DEL_MAX DEL_PH DEL_AMP;
global PIT_E PIT_HZ PIT_SWAMP PIT_PH PIT_AMP;
global VIB_HZ VIB_SWAMP VIB_PH VIB_AMP;
global DELAYS PITCHES VIBS;


d = DELAYS(v,DEL_ABS);
if  d > eps
    newi = i + time2ind(d);
    return
end
   


e = DELAYS(v, DEL_E);
hz = DELAYS(v, DEL_HZ);
amp = DELAYS(v, DEL_AMP);
p = DELAYS(v, DEL_PH);
min = DELAYS(v, DEL_MIN);
max = DELAYS(v, DEL_MAX);
s = cbexp(sin(ind2ang(i,hz,p)),e);  % just a sine wave
newi =  i+ time2ind( (min+max)/2 + (((max -min)/2) *s));
end
