History

Fadeout bugfix and new crossfade script

cbagwell committed 22 years ago

Commit af257fc1 parent c58705f5 files · +142 −48Browse files

Showing the changes to scripts (1 of 5 files). Show all

Unified · Split

scripts/crossfade_cat.sh+85−0
@@ -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
22SOX=/home/cbagwell/sox/src/sox
23SOXMIX=/home/cbagwell/sox/src/soxmix
24
25if [ "$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
30fi
31
32fade_length=$1
33first_file=$2
34second_file=$3
35
36fade_first="yes"
37if [ "$4" != "" ]; then
38 fade_first=$4
39fi
40
41fade_second="yes"
42if [ "$5" != "" ]; then
43 fade_second=$5
44fi
45
46fade_first_opts=
47if [ "$fade_first" == "yes" ]; then
48 fade_first_opts="fade h 0 0:0:$fade_length"
49fi
50
51fade_second_opts=
52if [ "$fade_second" == "yes" ]; then
53 fade_second_opts="fade h 0:0:$fade_length"
54fi
55
56echo "crossfade and concatenate files"
57echo
58echo "Finding length of $first_file..."
59first_length=`$SOX "$first_file" 2>&1 -e stat | grep Length | cut -d : -f 2 | cut -d . -f 1 | cut -f 1`
60echo "Length is $first_length"
61
62trim_length=`expr $first_length - $fade_length`
63
64# Get crossfade section from first file and optionally do the fade out
65echo "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
68echo "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
71echo "Crossfading..."
72$SOXMIX -v 1.0 fadeout.wav -v 1.0 fadein.wav crossfade.wav
73
74echo "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
80echo -e "Removing temporary files...\n"
81rm fadeout.wav fadein.wav crossfade.wav song1.wav song2.wav
82mins=`expr $trim_length / 60`
83secs=`expr $trim_length % 60`
84echo "The crossfade in mix.wav occurs at around $mins mins $secs secs"
85

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t