#!/usr/bin/perl

# ------------------------------------------------------------------- FILES ---
$input_analysis_file = "/snd/myuserid/jimiPopDN.anal";
$input_chan = 0;                  # numbered from 1; 0: use all input chans

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

# --------------------------------------------------------------- TRAVERSAL ---
# Output sound will last this long, unless traversal exceeds a time boundary
# and autostop is on. (See below.)
$output_duration = 8;

# Set time point to initial position in analysis file, in seconds.
$time_point = 0.0;

# Rate multiplier sets speed and direction of read.
# 1: original rate, 2: twice as fast, 0: stationary, negative: reverse
$rate_multiplier = .5;

# Set segment of analysis file to traverse.
$lower_time_boundary = 0;         # in seconds
$upper_time_boundary = -1;        # -1: end of file

# Autostop terminates the job if a time boundary is crossed
# 1 is on; 0 is off.
$autostop = 1;

# Normally the traversal moves smoothly at the rate given above. You can
# introduce small random variations in the time point "cursor" as it moves
# through the analysis file. This can make the result sound less mechanical
# (and can sometimes help reduce phase vocoder artifacts).
$timepoint_dither_window = 0;         # maximum time point deviation (seconds)
$timepoint_change_response_time = 0;  # how smoothly dither changes (seconds)

# -------------------------------------------------- SPECTRUM MODIFICATIONS ---
# Frequency shift in Hz
$frequency_shift = 0;

# Pitch transposition in semitones
$pitch_transposition = 0;

# Low / high shelf EQ
$low_shelf_eq_gain = 0;
$high_shelf_eq_gain = 0;
$low_shelf_eq_freq = 0;
$high_shelf_eq_freq = 10000;

$osc_resynth_threshold = -70;

# ------------------------------------------------------------- RESYNTHESIS ---
$gain = 0;                           # in dB
$frames_per_second = 200;            # should be >= frame rate of analysis

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


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

# Build argument string from vars defined above.
$pvflags = 
" -M0" .
" -w2" .
" -D$frames_per_second" .
" -d$output_duration" .
" -C$input_chan" .
" -P$pitch_transposition" .
" -a$frequency_shift" .
" -A$gain" .
" -F$input_analysis_file" .
" -u1" .         # data access mode
" -Q$time_point" .
" -g$lower_time_boundary" .
" -G$upper_time_boundary" .
" -Y$rate_multiplier" .
" -S$autostop" .
" -T$timepoint_dither_window" .
" -K$timepoint_change_response_time" .
" -b0" .
" -e0" .
" -H$low_shelf_eq_gain" .
" -X$high_shelf_eq_gain" .
" -m$low_shelf_eq_freq" .
" -R$high_shelf_eq_freq" .
" -t$osc_resynth_threshold" .
" -p$print_amp_stats" .
" -i$amp_stats_time_interval";

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

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

# Execute command.
`$cmd`;

