# ECMC PVC example >> pitchtracker1 <<
# This files creates a pitch analsyis file of /sflib/voice/sop1.b3.wav
# Defaults are used for all parameters except the following:
# (1) The "reference pitch" for the analysis is set to 245 herz (the precise
                         # equal tempered pitch for b3 is 246.9421
# reference_frequency=245 # changed from the default 440
# (2) The "lowest possible" and "highest possible" fundamentals are set to
#  fs3 (7.06 in octave pitch class) and cs4 (8.01 in oct. pitch class), allowing
# a wide range for the note attack
# boundary_data_type__freq_0__octavepitchclass_1=1
# low_freq_or_pitch_boundary=7.06 # Lowest possible pitch
# high_freq_or_pitch_boundary=8.01 # Highest possible pitch
# The output pitch track analysis created here is used in ECMC PVC example plainpv8

#******************************************************
#*********** PITCHTRACKER *****************************
#******************************************************
# ( THIS IS A WORK-IN-PROGRESS. IT WORKS RATHER WELL,  
#   BUT LIKE ALL PITCH TRACKING,  HAS ITS INEXPLICABLE MOMENTS

     # ******ECMC CHANGES & ADDITIONS: ***************
#******** INPUT SOUNDFILE & OUTPUT ENVELOPE ANALYSIS FILE  ************* 
cd $SFDIR # all files will be written to your current working soundfile directory
inputsf=/sflib/voice/sop1.b3.wav  
envelope_file=pvc.sop1.b3.ptrack # output pitch track analysis file

#******************************************************
#************ OUTPUT SETTINGS ************************

#......... OUTPUT FORMAT ............................ 

output_format=2 # # default 2 usually recommended
# 0: freq # 1: octdec # 2: semitones # 3: invertsemitones

#.........REFERENCE FREQUENCY ............................ 

reference_frequency=245 # changed from the default 440 to 245 (b3  246.942 hz)
#( for use with output format 3: inverted semitones)

#........OUTPUT SAMPLE RATE ............................ 
ouput_sample_rate=1000      #( only used for non soundfile data types)

#........OUTPUT DATA TYPE ............................ 

output_data_type=1  # default 1 usually recommended
# 0: ascii   # 1: 32-bit floats )
# 2: integer soundfile with:
#     freq track in left, and
#     freq/amp modulated sine in right. 

#........ BEGIN/END TIMES .............................

begintime=0
endtime=0
#======================================================
#*** ANALYSIS PARAMETERS ******************************
FFT_length=1024 # must be power-of-2, usually 1024, 512 or 2048
      # do not set FFT_length lower than 1024 if samp. rate = 96000
window_type=2
    # window type: 0 = Hamming,1 = rectangular, 2 = Blackman (DEFAULT),
    #  3 = Bartlett triangular, 4-12 = Kaiser windows for alpha = 4-12
    # generally recommended: 2 or 8
windowsize=0    # default 0 sets windowsize (in samples) to 2 * FFT_length if
  #  samp. rate <= 48000 or to 4 * FFT_length if samp. rate > 48000
analysis_frames_per_second=200
#======================================================

#*************** CHANNELS ****************************
analysis_channel_1_to_max=1

method_on_multiple_channels__average_0__peak_1=0
#******************************************************

#======================================================
#*********** DETECTION PARAMETERS *********************
#======================================================

#......... DETECTION METHOD ........................... 

detection_method_0_or_1=0

# 0 = the strongest harmonic collection
#	formants (optimal comb)
#	(This method finds up to 12 of the strongest formants
#	 and determines which is the logical fundamental
#	 based on the reinforcement of its harmonic spectrum
#	 by the other formants.)
# 1 = the strongest formant
#	( This method selects the strongest formant between
#	  the low-high boundaries.)
# 2 = band-limited centroid
#	(This method takes the amplitude (squared) weighted
#	 average of the spectrum between the low-high boundaries.)

#******************************************************

#......... DETECTION BOUNDARIES ....................... 
# if 0, XXX & YYY below are frequencies; if 1, XXX & YYY are in oct. pch class
boundary_data_type__freq_0__octavepitchclass_1=1

# VERY IMPORTANT : YOU ***MUST*** EDIT THE 2 LINES BELOW and
# SUPPLY LOWEST AND HIGHEST POSSIBLE INPUT PITCH, either
# in frequency or octave pitch class as determined by
# the boundary_data_typ argument (0 or 1) above
low_freq_or_pitch_boundary=7.06 # Lowest possible pitch
high_freq_or_pitch_boundary=8.01 # Highest possible pitch


#......... DETECTION TIME WINDOW ....................... 

detection_window_size_minimum=.05
detection_window_size_maximum=.2
# (Keep range between .05 and .2, "I guess".....)

#......... DETECTION THRESHOLD ....................... 

detection_threshold_in_decibels=-20
#( -10 to -20, perhaps? ) ; 

#******************************************************

#......... DETECTED ENVELOPE SMOOTHING ................. 

frequency_response_time=0
# (This is a lowpass filter which smooths the changes to the
#  tracked pitch trajectory. 0 = off, larger values smooth. )

#***** AMPLITUDE ENVELOPE *******************
#  RESPONSE TIME ###
release_time_in_seconds=0
attack_time_in_seconds=0

#........ COMPRESSOR ............................... 
compression_threshold_in_decibels=-0
decibels_of_compression=-0

#........GATE ..................................... 
gate_threshold_in_decibels=-80

#........WARP ....................................... 
amplitude_envelope_warp=0

#====================================================
# COMMAND LINE SETUP -- OFFICE USE ONLY
#      (DO NOT WRITE BELOW THIS LINE)
#====================================================
# *****  TKLA CHANGES: ******* #
input_file=$inputsf ; output_file=$outputsf
output_data_format=outputformat
WORDSIZE=`/usr/local/bin/sfbits "${inputsf}" | awk '{print $1}'`
if ( [ "$WORDSIZE" == "24" ] ) ; then rm -f pvcin; analysis_sndfile=pvcin; 
  24tofloat $inputsf pvcin 
fi
#  ****** end of TKLA changes & additions ****** #
# ANALYSIS
analysisroutine=pitchtracker

PVFLAGS="\
\
-N$FFT_length \
-M$windowsize \
-D$analysis_frames_per_second \
\
-b$begintime \
-e$endtime \
\
-C$analysis_channel_1_to_max \
\
-Q$boundary_data_type__freq_0__octavepitchclass_1 \
-f$low_freq_or_pitch_boundary \
-F$high_freq_or_pitch_boundary \
-L$release_time_in_seconds \
-l$attack_time_in_seconds \
-W$amplitude_envelope_warp \
-G$decibels_of_compression \
-T$compression_threshold_in_decibels \
-S$gate_threshold_in_decibels \
-r$ouput_sample_rate \
-g$output_data_type \
\
-m$detection_method_0_or_1 \
\
-j$detection_window_size_minimum \
-J$detection_window_size_maximum \
-d$detection_threshold_in_decibels \
\
-O$output_format \
-o$reference_frequency \
\
\
-a$frequency_response_time \
\
-X$method_on_multiple_channels__average_0__peak_1 \
-p1 \
\
"
echo "\n\n$analysisroutine $PVFLAGS $analysis_sndfile $envelope_file  "
$analysisroutine $PVFLAGS $analysis_sndfile $envelope_file ;
   # *****  TKLA CHANGES & ADDITIONS: ******* #
if ( ( `echo "${input_file}" ` == ${inputsf} ) && ( test -f "pvcin" ) ) ; then   rm -f pvcin ; fi
   echo " -------------------------------------------------------"
echo "Header information for PVC pitch track analysis file $envelope_file :"
ls -l  $envelope_file
   #  ****** end of TKLA changes & additions ****** #
# If you have created any gen function files above delete them below:

