#!/usr/bin/perl

# ------------------------------------------------------------------- FILES ---
$input_file = "/snd/Public_Sounds/JF4Scat.aiff";
$input_chan = 0;              # numbered from 1; 0: use all input chans
$begintime = 0;
$endtime = 0;                 # 0 means end of file

$output_file = "/snd/myuserid/simple_pitch_shift.snd";

# ---------------------------------------------------------------- ANALYSIS ---
# fft_length must be a power of two. If you increase it, you improve
# resolution in frequency at the expense of resolution in time (meaning
# that transients will smear). You can leave these set the way they are.
$fft_length = 1024;
$frames_per_second = 200;

# -------------------------------------------------- SPECTRUM MODIFICATIONS ---
# Frequency shift (constant added to all frequency components) in Hz
# (happens before pitch transposition).
$frequency_shift = 0;

# Pitch transposition in semitones
$pitch_transposition = -3;

# Tell PVC to resynthesize only those frequency bins with power above the
# given threshold, in dBFS. This can reduce processing time. Try -60 to -70.
$osc_resynth_threshold = -70;

# ------------------------------------------------------------- RESYNTHESIS ---
$gain = 0;                    # Gain change in dB

# Time compression / expansion factor
$time_scale_factor = 1.0;

# ----------------------------------------------------------------- DISPLAY ---
$print_amp_stats = 1;                # 0: no, 1: yes
$amp_stats_time_interval = .25;


#==============================================================================
# COMMAND LINE SETUP -- OFFICE USE ONLY

# Adjust frame rate by scale factor, but can't be > sampling rate.
$frames_per_second = $time_scale_factor * $frames_per_second;
if ($frames_per_second > 44100) {
   $frames_per_second = 44100;
}

# Build argument string from vars defined above.
$pvflags = 
" -N$fft_length" .
" -M0" .
" -w2" .
" -D$frames_per_second" .
" -I$time_scale_factor" .
" -a$frequency_shift" .
" -P$pitch_transposition" .
" -A$gain" .
" -C$input_chan" .
" -t$osc_resynth_threshold" .
" -b$begintime" .
" -e$endtime" .
" -p$print_amp_stats" .
" -i$amp_stats_time_interval";

# Build command line.
$cmd = "plainpv $pvflags $input_file $output_file";

# Print command line for reference.
print $cmd, "\n\n";

# Execute command.
`$cmd`;

