#!/usr/bin/perl

# ------------------------------------------------------------------- FILES ---
$input_file = "/snd/Public_Sounds/vccm_old/ah.snd";
$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_eq.snd";

# ---------------------------------------------------------------- ANALYSIS ---
$fft_length = 1024;
$frames_per_second = 200;

# -------------------------------------------------- SPECTRUM MODIFICATIONS ---
# Brickwall filter (before freq/pitch shift)
#
# Filter type is either bandpass (0) or bandreject (1). If bandpass, then
# all frequency components *outside* the band defined below will be removed.
# If bandreject, frequencies *inside* this band will be removed.
# (Happens before freq/pitch shift.)
$brickwall_type = 0;                       # 0: bandpass, 1: bandreject

# Define the band, giving low and high frequencies in Hz. Give -1 to set
# the high frequency to Nyquist (the highest frequency).
$brickwall_low_freq = 0;
$brickwall_high_freq = -1;

# Frequency shift in Hz
$frequency_shift = 0;

# Pitch transposition in semitones
$pitch_transposition = 0;

# Low / high shelf EQ
#
# Gain sets the level of each shelf, in dB. 0 dB means no change; positive
# gain amplifies; negative gain attenuates. The freq. params (in Hz) set the
# width of each shelf. A straight line connects the two shelves. So the
# settings below specify a frequency response curve like this: 90 dB of
# attenuation between 0 Hz and 200 Hz; 3 dB of boost between 1000 Hz and
# Nyquist. A ramp connects the shelves, from 200 to 1000 Hz.
# (Happens after freq/pitch shift.)
$low_shelf_eq_gain = -90;             # near-total attenuation
$high_shelf_eq_gain = 3;              # slight boost
$low_shelf_eq_freq = 200;
$high_shelf_eq_freq = 1000;

# 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" .
" -H$low_shelf_eq_gain" .
" -m$low_shelf_eq_freq" .
" -X$high_shelf_eq_gain" .
" -R$high_shelf_eq_freq" .
" -T$brickwall_type" .
" -f$brickwall_low_freq" .
" -F$brickwall_high_freq" .
" -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`;

