   # Example PVC script file >> harmonizer2-1 << : 
# ECMC PVC example script "harmonizer2-1" :
# Input soundfile "vln.g3" is "harmonized" as a dyad with pitches
# at b1 (g3 transposed down 20 semitones) and bf5 (g3 transposed up
# 27 semitones). The lower note is resynthesizewd using only frequencies# between g5 (9.07) and g7 (11.07) from the source soundfile. The high
# note is resynthesized using only the first 4 harmonics (7.07 to 9.07). 
# The amplitudes of the 2 notes are boosted, respectively, by 30 and 20 dB.
# 
#echo \
#-20         9.07  11.07   30 \
#27          7.07 9.07  20\
#> $SFDIR/harmonizermap
#HARMONIZER_shift_file=harmonizermap

# The source tone (g3) is suppressed in resynthesis:
# SOURCE_gain_in_dB=-96 # -0  # int,float or FUNC

# An amplitude envelope that increases and then decreases in intensity
# linearly is applied to both harmonized notes:
# gen3 -L100 -24 -8 -24 > $SFDIR/gainfunc
# MASTER_gain_in_decibels=$SFDIR/gainfunc  # int,float or FUNC

#******************************************************
#................ HARMONIZER ..........................
#******************************************************
     # ******ECMC CHANGES & ADDITIONS: ***************
#******** INPUT & OUTPUT SOUNDFILES *************
cd $SFDIR # all files will be written to your current working soundfile directory
inputsf=/sflib/string/vln.g3.wav 
outputsf=harmonizer2-1.wav  # output soundfile
# ********************* #

   ##### Cmusic function file generator tempates #####
#   gen0  normalizes function files previously created with other gen routines
# gen0 -Llength  max < inputfuncfile > outputfuncfile
#   gen1 creates linear {straight line} segments, like Csound gen 7
# gen1 -Llength t1 v1 ... tN vN
#   gen2 generates harmonic waveforms from sine {a} & cosine {b} amps
# gen2 -Llength [-o (default) or -c] a1 ... aN b0 ... bM N
#  gen3 generates amp values & linear connections at equally spaced time points
# gen3 -Llength v1 v2 ... vN
#   gen4 generates exponenetial segments; "a" values determine shape &
#  depth of curve: 0 = linear, neg. = exponential, pos. = inverse expo.
# gen4 -Llength t1 v1 a1 ... tN vN
#  gen5 is like Csound gen 9 : harmonic1/amp/phase harmonic2/amp/phase
# gen5 -Llength h1 a1 p1 ... hN aN pN
#     gen6 generates a table of random numbers between +1 and -1
# gen6 -Llength
#    cspline: smooth curve {cubic spline} interpolator
# cspline len_flag [flags] x0 y0 x1 y1 ... xN yN
#   genraw reads in a previously created function file
# genraw -LN filename    (where N is the length of the output function.)
# For a usage summary of "reshape" type  "reshape"  with no arguments.
   ##### End of gen routine function generator tempates #####

#******************** OUTPUT **************************
output_data_format=1
   #  0=  Same as input file, 1 = integers 2 = rescaled floats 

#........ BEGIN/END TIMES .............................
begintime=0
endtime=0
# (0 end time defaults to end of file)
#======================================================
#*** 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
frames_per_second=200   # generally 200, occasionally 400 or 600 when time stretching
#======================================================
#........... OUTPUT CHANNEL(S) .......................

output_channel=0
   # channels are numbered from 1 to the maximum; 0 = all channels

#.............OSCIL THRESHOLD ........................

oscillator_resynthesis_threshold_in_dB=-80

#****************** MODIFICATIONS *********************

#.................. TIME ..............................
time_expansion_contraction_factor=1
     # (Adjust frames_per_second in proportion to keep a constant rate.)

#.................. DECIBELS ..........................
gen3 -L100 -24 -8 -24 > $SFDIR/gainfunc
MASTER_gain_in_decibels=$SFDIR/gainfunc  # in dB, int, float or FUNC

#********** SOURCE ************************************

#.................. DECIBELS ..........................
SOURCE_gain_in_dB=-96  # in dB, int, float or FUNC

#.................. PITCH .............................

SOURCE_frequency_shift=0 # int,float or FUNC
SOURCE_pitch_transposition_in_semitones=0 # int,float or FUNC

#********** HARMONIZER ********************************
#.................. DECIBELS ..........................
HARMONIZER_gain_in_dB=-0 # int,float or FUNC

#.................. PITCH .............................
HARMONIZER_frequency_shift=0  # int, float or FUNC
HARMONIZER_pitch_transposition_in_semitones=0 # int,float or FUNC

#............ SPECTRUM WARPSHAPE ......................
spectrum_warpshape_index=0  # int, float or FUNC

#********* AMPLITUDE STATISTICS **********************
print_amplitude_statistics_0_no__1_yes=1
amplitude_statistics_time_interval=.25

#================ DATA FILE: =========================

HARMONIZER_data_file=$SFDIR/harmonizermap

#................. SHIFT METHOD ....................... 
HARMONIZER_shift_method=2
#( 0 = frequency multipler )
#( 1 = frequency adder )
#( 2 = semitones of transposition )

#............... BOUNDARY FORMAT ...................... 
HARMONIZER_boundary_data_format=1
#( 0 = frequency )
#( 1 = octave.pitchclass )

#=====================================================

#*************** DATA FILE FORMAT ********************
# (1) transposition multiplier/semitone transpose  
# (2) low freq boundary (octave.pclass or freq)
# (3) high freq boundary (octave.pclass or freq)
# (4) dB
#*****************************************************
#EDIT THE LINES BELOW, for harmonizer "notes" 1 & 2, and add similar additional
# lines for additional harmonizer "notes" 
# Example: 
# Transposition = 1 semitone up, freqs. between c3 (7.00) and b4, -3 dB
# 1      7.00  8.11   -3  \

echo \
-20         9.07  11.07   30 \
27          7.07 9.07  20 \
> $SFDIR/harmonizermap

#........... RESCALE for floating point only ......
rescale_level_in_decibels=0
   # set to 1 to rescale to peak of input file; do not do this if input amplitude
   # is low

#====================================================
# 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; input_file=pvcin; 
  24tofloat $inputsf pvcin ; output_data_format=2
fi
if  ( ( [ "$outputformat" == 3 ] ) || ( [ "$WORDSIZE" == "24" ] && [ "$outputformat" == 0 ] ) ) ; then
 rm -f pvcout; output_file=pvcout # temporary floating point output soundfile for 24-bit output
output_data_format=2
fi
#  ****** end of TKLA changes & additions ****** #
pvroutine=harmonizer 

PVFLAGS="\
\
-N$FFT_length \
-M$windowsize \
-w$window_type \
-D$frames_per_second \
-I$time_expansion_contraction_factor \
\
-C$output_channel \
-t$oscillator_resynthesis_threshold_in_dB \
\
-b$begintime \
-e$endtime \
\
-A$MASTER_gain_in_decibels \
\
-G$SOURCE_gain_in_dB \
-a$SOURCE_frequency_shift \
-P$SOURCE_pitch_transposition_in_semitones \
\
-W$spectrum_warpshape_index \
\
-Z$HARMONIZER_boundary_data_format \
-z$HARMONIZER_shift_method \
\
-m$HARMONIZER_gain_in_dB \
-q$HARMONIZER_frequency_shift \
-X$HARMONIZER_pitch_transposition_in_semitones \
-F$HARMONIZER_data_file \
\
-p$print_amplitude_statistics_0_no__1_yes \
-i$amplitude_statistics_time_interval \
\
-_$output_data_format \
-=$rescale_level_in_decibels \
\
"
echo "\n$pvroutine $PVFLAGS  $input_file $output_file"

$pvroutine  $PVFLAGS $input_file $output_file   ; 
   # *****  TKLA CHANGES & ADDITIONS: ******* #
if (  ( test -f "pvcin" ) ) ; then   rm -f pvcin ; fi
if ( ( [ "$WORDSIZE" == "24" ] ) &&  ( [ "$output_file" == "pvcout" ] ) ) ; then
      echo "Converting temporary float output file pvcout to $outputsf"
      echo " -------------------------------------------------------"
      floatto24 pvcout $outputsf 2> /dev/null  ; rm -f pvcin pvcout 
   echo " -------------------------------------------------------"
else
   echo " -------------------------------------------------------"
    echo -e -n "Output soundfile: " ;  sfinfo -s $outputsf
   echo " -------------------------------------------------------"
fi
   #  ****** end of TKLA changes & additions ****** #
# If you have created any gen function files above delete them below
rm $SFDIR/harmonizermap $SFDIR/gainfunc

