Created
June 7, 2010 02:17
-
-
Save danpaluska/428136 to your computer and use it in GitHub Desktop.
abstract audio layering and panning with sox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# layer_audio.sh | |
# http://gist.github.com/428136 | |
# | |
# take an input file, $1 | |
# find length on input file | |
# snip short pieces of length $2 | |
# layer all those pieces on top of each other | |
# | |
# USAGE = layer_audio.sh filename 150 | |
# this will make a 2m and 30 second file. | |
# | |
#echo "this will work with mp3 files but it's much faster with .wav" | |
#echo "convert to wav first, then run this script" | |
# PUBLIC DOMAIN | |
# NORI | |
# GHTS | |
# RESE | |
# RVED | |
if [ "$3" == "" ]; then | |
echo "Usage: layer_audio.sh filename 300 1.2 80" | |
echo "layer_audio.sh filename lengthinseconds inittremspeed trm depth" | |
exit 1 | |
fi | |
filename=$1 | |
snip_length=$2 | |
tremspeed=$3 | |
tremdepth=$4 | |
#crossfade_duration=$4 | |
# (| cut -d"." -f1) gets rid of the decimal value of seconds | |
length_seconds=`sox --info -D ${1} | cut -d"." -f1` | |
echo "original length=${length_seconds}" | |
echo "Pls enter anything:\c" | |
read name | |
echo "You entered $name." | |
pancount=0 | |
tremcount=1 | |
#tremdepth=85 | |
number_snips=length_seconds/snip_length | |
let "number_snips+=1" | |
# generate the snippets | |
for (( i = 0 ; i <= number_snips ; i++ )) | |
do | |
let "pancount%=5" | |
if [ "$pancount" == "0" ] | |
then | |
a=0.5; b=0.0;c=0.5;d=0.0; | |
echo $pancount means all left | |
#tremspeed=tremspeed/3 | |
tremspeed=$(echo "scale=2; $tremspeed/1.2" | bc) | |
fi | |
if [ "$pancount" == "1" ] | |
then | |
echo $pancount means all right | |
a=0; b=0.5;c=0;d=0.5; | |
#tremspeed=tremspeed/2 | |
tremspeed=$(echo "scale=2; $tremspeed/1.3" | bc) | |
fi | |
if [ "$pancount" == "2" ] | |
then | |
echo $pancount means 1/2 left | |
a=0.75; b=0;c=0.25;d=0.5; | |
#tremspeed=tremspeed/2 | |
tremspeed=$(echo "scale=2; $tremspeed/1.25" | bc) | |
fi | |
if [ "$pancount" == "3" ] | |
then | |
echo $pancount means 1/2 right | |
a=0.5; b=0.25;c=0;d=0.75; | |
#tremspeed=tremspeed/2 | |
tremspeed=$(echo "scale=2; $tremspeed/1.12" | bc) | |
fi | |
if [ "$pancount" == "4" ] | |
then | |
echo $pancount means centered | |
a=0.5; b=0;c=0;d=0.5; | |
#tremspeed=tremspeed/2 | |
tremspeed=$(echo "scale=2; $tremspeed/1.1" | bc) | |
fi | |
let "counter=10000+$i" | |
let "pancount+=1" | |
let "tremcount%=9" | |
let "tremcount+=1" | |
#let "tremspeed=1/$tremcount" | |
echo tremspeed is $tremspeed | |
let "snip_start=${snip_length}*${i}" | |
sox $1 -c2 snip${counter:1}.wav trim $snip_start $2 mixer ${a},${b},${c},${d} tremolo $tremspeed $tremdepth | |
echo "sox $1 snip${counter:1}.wav trim $snip_start $2" | |
done | |
echo "${counter:1} snippets generated" | |
# create dummy file | |
#sox $1 mix2.wav trim 0 1 | |
sox -m snip*.wav --norm mix2.wav | |
new_length=`sox --info -D mix2.wav | cut -d"." -f1` | |
# you can change this part of the code to name the file differently. | |
# just change tla_ to whatever you want. | |
#mv mix2.wav lyrd_${1}_${2}_${3}_${4}.wav | |
sox mix2.wav lyrd_${1}_${2}_${3}_${4}.mp3 | |
#sox lyrd_${1}_${2}_${3}_${4}.wav lyrd_${1}_${2}_${3}_${4}.mp3 | |
echo "assembled snippets" | |
echo "old length = ${length_seconds}, new length =${new_length}" | |
let "shortening_ratio=${length_seconds}/${new_length}" | |
echo "shortening factor = ${shortening_ratio}" | |
rm snip*.wav | |
echo "deleted snippets" | |
# fade in | |
# sox cutoff_file.wav improved_file.wav fade t 3 0 0 | |
# fade out | |
# sox cutoff_file.wav improved_file.wav fade t 0 242 3 | |
# | |
# so left pan of 0.5 is 1-0.5*(1-X),0,0.5(X),1-(0.5)? | |
# | |
# sox input.wav -c2 output.wav mixer l->l,l->r,r->l,r->r | |
# sox input.wav -c2 unchanged.wav mixer 1,0,0,1 #unchanged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment