Showing the changes to scripts (1 of 5 files). Show all
Unified · Split
| @@ -0,0 +1,85 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # | ||
| 3 | # crossfade_cat.sh | ||
| 4 | # | ||
| 5 | # Original script from Kester Clegg. Mods by Chris Bagwell to show | ||
| 6 | # more examples of sox features. | ||
| 7 | # Concatenates two files together with a crossfade of $1 seconds. | ||
| 8 | # Filenames are specified as $2 and $3. | ||
| 9 | # | ||
| 10 | # By default, script fades out first file and fades in second file. | ||
| 11 | # This makes sure that we can mix the two files together with | ||
| 12 | # no clipping of audio. If that option is overridden then the | ||
| 13 | # user must make sure no clipping can occur themselves. | ||
| 14 | # | ||
| 15 | # $4 is optional and specifies if a fadeout should be performed on | ||
| 16 | # first file. | ||
| 17 | # $5 is optional and specifies if a fadein should be performed on | ||
| 18 | # second file. | ||
| 19 | # | ||
| 20 | # Crossfaded file is created as "mix.wav". | ||
| 21 | |||
| 22 | SOX=/home/cbagwell/sox/src/sox | ||
| 23 | SOXMIX=/home/cbagwell/sox/src/soxmix | ||
| 24 | |||
| 25 | if [ "$3" == "" ]; then | ||
| 26 | echo "Usage: $0 crossfade_seconds first_file second_file [ fadeout ] [ fadein ]" | ||
| 27 | echo | ||
| 28 | echo "If a fadeout or fadein is not desire then specify \"no\" for that option" | ||
| 29 | exit 1 | ||
| 30 | fi | ||
| 31 | |||
| 32 | fade_length=$1 | ||
| 33 | first_file=$2 | ||
| 34 | second_file=$3 | ||
| 35 | |||
| 36 | fade_first="yes" | ||
| 37 | if [ "$4" != "" ]; then | ||
| 38 | fade_first=$4 | ||
| 39 | fi | ||
| 40 | |||
| 41 | fade_second="yes" | ||
| 42 | if [ "$5" != "" ]; then | ||
| 43 | fade_second=$5 | ||
| 44 | fi | ||
| 45 | |||
| 46 | fade_first_opts= | ||
| 47 | if [ "$fade_first" == "yes" ]; then | ||
| 48 | fade_first_opts="fade h 0 0:0:$fade_length" | ||
| 49 | fi | ||
| 50 | |||
| 51 | fade_second_opts= | ||
| 52 | if [ "$fade_second" == "yes" ]; then | ||
| 53 | fade_second_opts="fade h 0:0:$fade_length" | ||
| 54 | fi | ||
| 55 | |||
| 56 | echo "crossfade and concatenate files" | ||
| 57 | echo | ||
| 58 | echo "Finding length of $first_file..." | ||
| 59 | first_length=`$SOX "$first_file" 2>&1 -e stat | grep Length | cut -d : -f 2 | cut -d . -f 1 | cut -f 1` | ||
| 60 | echo "Length is $first_length" | ||
| 61 | |||
| 62 | trim_length=`expr $first_length - $fade_length` | ||
| 63 | |||
| 64 | # Get crossfade section from first file and optionally do the fade out | ||
| 65 | echo "Obtaining $fade_length seconds of fade out portion from $first_file..." | ||
| 66 | $SOX "$first_file" -s -w fadeout.wav trim $trim_length $fade_first_opts | ||
| 67 | # Get the crossfade section from the second file and optionally do the fade in | ||
| 68 | echo "Obtaining $fade_length seconds of fade in portion from $second_file..." | ||
| 69 | $SOX "$second_file" -s -w fadein.wav trim 0 $fade_length $fade_second_opts | ||
| 70 | # Mix the crossfade files together at full volume | ||
| 71 | echo "Crossfading..." | ||
| 72 | $SOXMIX -v 1.0 fadeout.wav -v 1.0 fadein.wav crossfade.wav | ||
| 73 | |||
| 74 | echo "Trimming off crossfade sections from original files..." | ||
| 75 | |||
| 76 | $SOX "$first_file" -s -w song1.wav trim 0 $trim_length | ||
| 77 | $SOX "$second_file" -s -w song2.wav trim $fade_length | ||
| 78 | $SOX song1.wav crossfade.wav song2.wav mix.wav | ||
| 79 | |||
| 80 | echo -e "Removing temporary files...\n" | ||
| 81 | rm fadeout.wav fadein.wav crossfade.wav song1.wav song2.wav | ||
| 82 | mins=`expr $trim_length / 60` | ||
| 83 | secs=`expr $trim_length % 60` | ||
| 84 | echo "The crossfade in mix.wav occurs at around $mins mins $secs secs" | ||
| 85 | |||