-
Notifications
You must be signed in to change notification settings - Fork 0
/
MRaudioStitcher
executable file
·93 lines (66 loc) · 2.53 KB
/
MRaudioStitcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /opt/local/bin/bash
#-x
set -o errexit
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
#to be run in either /short[Start/End]...
#takes no arguments
#decides on a random fade time based on the length of the current file
#final file is named output.aiff and should be moved and renamed before running this script
#again or it will be overwritten!!
# https://github.com/MIB1700/MRaudioChopperStitcher/
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
num=1
sr=44100
sign=1
# touch fileOrder.txt
for file in *.aiff
do
eval "$(ffprobe -v quiet -show_format -of flat=s=_ -show_entries stream=duration "$file")";
duration=${format_duration%.*}; #bash can't do floating point math so truncate!
if (( "$num" > 1 )); then
#probability gate: change sign to negative 45% of the time
if (( $(( RANDOM % 100)) < 45 ));then
sign=$(( "$sign" * -1 ))
fi
crossTime=$(( (RANDOM % ("$duration" / 2)) + ("duration" / 2) + ((RANDOM % 5) * "$sign") ))
#calsulate num of samples
crossFormat=$(( "$crossTime" * "$sr" ))
fi
if (( "$num" == 1 ));then
lastFile="$file"
elif (( "$num" == 2 ));then
ffmpeg -y -i "$lastFile" -i "$file" -filter_complex acrossfade=ns="$crossFormat":c1=hsin:c2=hsin output.aiff
elif (( "$num" > 2 ));then
#make sure we don't use output.aiff as the second input file...
#don't need to check for output2.aiff since it gets destroyed at the end of each loop
if [[ "$file" != "output.aiff" ]] && [[ "$file" != "output2.aiff" ]]; then
ffmpeg -y -i output.aiff -i "$file" -filter_complex acrossfade=ns="$crossFormat":c1=hsin:c2=hsin output2.aiff
#overwrite output with output2... therefor allowing to keeping using output2
mv output2.aiff output.aiff
elif [[ "$file" = "output.aiff" ]] || [[ "$file" = "output2.aiff" ]]; then
echo ""
echo ""
echo ""
echo "DONE"
echo ""
echo ""
if mv output.aiff "$(date '+%Y_%m_%d_%H_%M_%S')_newStitchedAudio.aiff"; then
#double check that output.aiff is gone
if [[ -e "output.aiff" ]]; then
rm output.aiff
fi
fi
exit 0
fi
fi
((num++))
# lastDuration="$duration"
done
if mv output.aiff "$(date '+%Y_%m_%d_%H_%M_%S')_newStitchedAudio.aiff"; then
#double check that output.aiff is gone
if [[ -e "output.aiff" ]]; then
rm output.aiff
fi
fi