# Example PVC script used to create /sflib/x soundfile >> plainpv5 << 
# ECMC pvc example  plainpv5: illustrates a time varying mplitude
# function, using only a portion of an input soundfile,  and EQ

# parameters changed from the defaults include:
# (1) Time varying amplitude changes
#  gen4 -L1000 0 -90 0 \                         
# .1 12  0 \
# .8 3 0    1 -90 > $SFDIR/ampfunc
# An amplitude function table with 1000 values is created, moving
# linearly from -90 dB to +12 dB over the first 10 % of the
# output soundfile, then to +3 dB, then to -90 dB over the last
# 20 % of the soundfile. This table is written to file "ampfunc" in
# the user's current working soundfile directory. Note that since the
# values in this table are applied to logarithmic dB values we create
# linear, not exponential, transitions.

# gain_in_decibels=$SFDIR/ampfunc   # in dB, int, float or FUNC

 # (The values in function file "ampfunc" are applied to the resynthesis
 # output amplitude, creating a new amplitude envelope.)
# (2) Only a portin of the input soundfile is used
# begintime=1.    # begin reading one second into the soundfile
# endtime=5.5      # ( stop analysis/resynthesis at 5.5 seconds into original soundfile

# (3) EQ is applied
# LOW_SHELF_EQ_gain_in_decibels=6   # -96
# LOW_SHELF_EQ_frequency=100
   # (All frequencies 100 herz & below are boosted by 6 dB)
# HIGH_SHELF_EQ_gain_in_decibels=-60
# HIGH_SHELF_EQ_frequency=1000
   # (All frequencies 1000 herz & above are attenuated by 60 dB)

# The following line is added at the very end of the file to remove
# the function file:
# rm $SFDIR/ampfunc


#******************************************************
#.................... PLAINPV .........................
#******************************************************

     # ******ECMC CHANGES & ADDITIONS: ***************
#******** INPUT & OUTPUT SOUNDFILES *************
cd $SFDIR # all files will be written to your current working soundfile directory
inputsf=/sflib/env/tunroom.wav
outputsf=$SFDIR/plainpv5.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


## HERE IS WHERE WE CREATE THE AMPLITUDE FUNCTION from the line above
 gen4 -L1000 0 -90 0 \
.1 12  0 \
.8 3 0    1 -90 > $SFDIR/ampfunc


#  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_data_format=1
   #  0=  Same as input file, 1 = integers 2 = rescaled floats 

#******** BEGIN/END TIMES *****************************
   # beginning and end times within input soundfile for analysis/resynthesis
begintime=1.    # begin reading one second into the soundfile
endtime=5.5      # ( stop analysis/resynthesis at 5.5 seconds into original soundfile
#======================================================
#*** 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
#======================================================
#*** RESYNTHESIS PARAMETERS ***************************

#........... 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
     #( Usually -60 to -80 unless dropouts become audible. )

#******** RESYNTHESIS  MODIFICATIONS *********************

#.................. DURATION ..............................

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

gain_in_decibels=$SFDIR/ampfunc    # in dB, int, float or FUNC

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

frequency_shift_in_Hz=-0  # detune partials, in herz; int, float or FUNC 
pitch_transposition_in_semitones=0   # int, float or FUNC

#............ AMPLITUDE RESPONSE ......................

release_time_in_seconds=0   # int, float or FUNC
attack_time_in_seconds=0    # int, float or FUNC

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

#............ BRICKWALL FILTER ........................

FILTER_TYPE=0
   # 0 = bandpass, 1 = bandreject

BRICKWALL_FILTER_window_low_frequency=-1
BRICKWALL_FILTER_window_high_frequency=-1
     # (-1 selects respective lowest or highest frequency)

#======================================================
#*************** LOW/HIGH SHELF EQ *********************
LOW_SHELF_EQ_gain_in_decibels=6
LOW_SHELF_EQ_frequency=100

HIGH_SHELF_EQ_gain_in_decibels=-60
HIGH_SHELF_EQ_frequency=1000
#======================================================
#........... 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
#********** AMPLITUDE STATISTICS ********************** 
print_amplitude_statistics_0_no__1_yes=1
amplitude_statistics_time_interval=.25


#====================================================
# COMMAND LINE SETUP -- OFFICE USE ONLY
#   (DO NOT WRITE BELOW THIS LINE EXCEPT TO DELETE FUNCTION FILES AT VERY END)
#====================================================
# *****  TKLA CHANGES: ******* #
  SR=`/usr/local/bin/sfsr $inputsf | awk '{print $1}'`
if ( ( [ `expr "$SR" \> "48000"` == 1 ] ) &&  ( [ "$windowsize" == "0" ] ) ) ; then 
       # if SR is > 48000 & windowsize is set to 0 increase default windowsize
  windowsize=`expr $FFT_length \* 4`
fi
# Determine if input soundfile is 24 bit. If so, compile 32 bit float outputs, then 
# convert to 24 bit ints
WORDSIZE=`/usr/local/bin/sfbits "${inputsf}" | awk '{print $1}'`  
if [ "$WORDSIZE" == "24" ] ; then rm -f pvcin ; 24tofloat $inputsf pvcin ; input_file=pvcin
  if  [ "$output_data_format" != 2 ] ; then
    output_file=pvcout  # temporary floating point output soundfile for 24-bit inputs
    rm -f  pvcout;  output_data_format=2
  else  # 24 bit input but float output requested
    output_file=$outputsf ; fi
else # not 24 bit input ; 16 bit int or 32 bit float input
    input_file=$inputsf ;  output_file=$outputsf
fi
#  ****** end of TKLA changes & additions ****** #
pvroutine=plainpv 
PVFLAGS="\
\
-N$FFT_length \
-M$windowsize \
-w$window_type \
-D$frames_per_second \
-I$time_expansion_contraction_factor \
\
-a$frequency_shift_in_Hz \
-P$pitch_transposition_in_semitones \
-A$gain_in_decibels \
\
-C$output_channel \
-t$oscillator_resynthesis_threshold_in_dB \
\
-b$begintime \
-e$endtime \
\
-H$LOW_SHELF_EQ_gain_in_decibels \
-m$LOW_SHELF_EQ_frequency \
\
-X$HIGH_SHELF_EQ_gain_in_decibels \
-R$HIGH_SHELF_EQ_frequency \
\
-L$release_time_in_seconds \
-l$attack_time_in_seconds \
\
-W$spectrum_warpshape_index \
\
-T$FILTER_TYPE \
-f$BRICKWALL_FILTER_window_low_frequency \
-F$BRICKWALL_FILTER_window_high_frequency \
\
-_$output_data_format \
-=$rescale_level_in_decibels \
\
\
-p$print_amplitude_statistics_0_no__1_yes \
-i$amplitude_statistics_time_interval \
"
echo "\n\n$pvroutine $PVFLAGS $input_file $output_file "
$pvroutine  $PVFLAGS $input_file $output_file 
   # *****  TKLA CHANGES & ADDITIONS: ******* #
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
    if (  ( test -f "pvcin" ) ) ; then   rm -f pvcin ; fi
   echo " -------------------------------------------------------"
fi
   #  ****** end of TKLA changes & additions ****** #
# If you have created any gen function files above delete them below:


# If you have created any gen function files above delete them below:
rm $SFDIR/ampfunc  # here we delete the amplitude function file

 

