clear
close all

%filename = 'data_wav\Zager and Evans - In The Year 2525_mono_22050_58940-74070.wav';
filename = 'data_wav\Sys_tonleiter_CDur_langsam_BB_F.wav';
%filename = 'data_wav\BM02A_meinard_se.wav';

windowLength= 8192;
stepSize = 4096;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

f_audio = wav_to_audio('','',filename);

parameter.win_len = windowLength;
parameter.win_ov = windowLength - stepSize;
parameter.window = @hanning;   % @rectwin;   
parameter.useMatlabSpectrogram = 1;
parameter.applySpectralWhitening = 0;  % spectral whitening is non-standard
parameter.SWamountOfSpecWhite = 0.33;
parameter.vis = 1;
parameter.visSpectralWhitening = 0;
[f_magstft,f_phase,sideinfo] = audio_to_STFT(f_audio,parameter);
f_powerstft = f_magstft.^2;

clear parameter
parameter.vis = 0;
parameter.midi_min = 21;
parameter.midi_max = 108;
parameter.refTuning = 440;
parameter.bandradius = 0.4;
parameter.peakPickInBands = 0;  % if set to 0 it will sum the energy
[f_pitchSTFT,sideinfo] = STFT_to_pitchSTMSP(f_powerstft,sideinfo.STFT.freqInfo,sideinfo.STFT.featureRate,parameter,sideinfo);

% for the sake of simplicity, f_audio has NOT been paded with zeros and
% therefore the center-time of the first feature is not 0
parameterVis.featureRate = 22050 / stepSize;  % sample rate is 22050Hz here
visualize_pitchSTMSP(f_pitchSTFT,parameterVis);

