function [t,f0,pvx] = ptrack_swipe(d,sr)
% [t,f0,pvx] = ptrack_swipe(d,sr)
%    Run the Camacho 08 Swipe-prime pitch tracker on the waveform d 
%    (at sampling frequency sr).
%    Returns three 1D vectors.  
%      t is the sample times at which pitches are estimated 
%          (typically uniformly spaced every 0.010 sec).  
%      f0 is the corresponding pitch value in Hz (which can be 
%          zero for unvoiced frames). 
%      pvx is the corresponding probability of voicing for each
%          frame (between 0 and 1).  Generally, a threshold of 0.5
%          is the best guess for actual voiced-unvoiced threshold.
%    This is supposed to be a generic framework for pitch trackers,
%    but in this case we'll run Swipe-prime
% 2013-02-03 Dan Ellis dpwe@ee.columbia.edu

if ~isdeployed() && exist('swipep','file') ~= 2
  addpath('swipe')
end

frange = [60 650];
dt = 0.010;
octdiv = 1/48;
derbs = 0.1;
[f0,t,s] = swipep(d, sr, frange, dt, octdiv, derbs);

% s is pitch strength, but a good threshold is around 0.25.
% Also, some values are NaN.

s(find(isnan(s))) = 0;
s(find(s < 0)) = 0;
pvx = s.^0.5;  % so s = 0.25 -> pvx = 0.5

