#!/bin/bash

noise_profile=/data/recording/noise_profile.sox

target=${1}

if [ -z "$target" ]; then
    echo "Missing mandatory argument"
    echo "Usage: $0 file"
    echo "noise profile file: $noise_profile"
    ecit 1
fi

[ -n "$2" ] && noise_profile=${2}

if ! [ -f "$noise_profile" ]; then
    echo "Missing noise profile file $noise_profile"
    echo "Exiting"
    exit 1
fi

fmt=$(echo $target|sed 's/.*\.\([^\.]*\)/\1/g')
new_target=$(echo $target | sed "s/.${fmt}$//")
new_target=${new_target}_reduced.${fmt}


sox ${target} ${new_target} noisered ${noise_profile} 