use a temp dir
[xonotic/mediasource.git] / sound / weapons / tuba_loopnote_maker.sh
1 #!/bin/sh
2
3 set -ex
4
5 (
6         cd loopfinder
7         gcc -o findloop findloop.c -lfftw3 -Wall -Wextra -ffast-math -lsndfile -O3
8 )
9
10 t=`mktemp -dt loopfinder.XXXXXX`
11 trap 'rm -rf "$t"' EXIT
12
13 synth=$1; shift
14 program=$1; shift
15 velocity=$1; shift
16 transpose=$1; shift
17 tubaid=$1; shift
18
19 delta=2
20 fftsize=512
21 loopmin=1.1
22 loopmax=1.5
23 len=1.8
24
25 perl tuba_loopnote_maker.mid.pl "$t"/tuba_loopnote_maker.mid $delta $program $velocity $transpose -18 -12 -6 0 6 12 18 24
26
27 case "$synth" in
28         timidity)
29                 timidity -Ow "$@" -o "$t"/out.wav "$t"/tuba_loopnote_maker.mid
30                 ;;
31         fluidsynth)
32                 fluidsynth -v -n -i -l -T wav -F "$t"/out.wav "$@" "$t"/tuba_loopnote_maker.mid
33                 ;;
34 esac
35 normalize "$t"/out.wav
36
37 start=$delta
38 step=$(($delta*2))
39 for note in -18 -12 -6 0 6 12 18 24; do
40         sox "$t"/out.wav "$t"/n$note.wav \
41                 trim $start $step \
42                 silence 1 1s 0
43
44         fn=tuba"$tubaid"_loopnote"$note".ogg 
45
46         # now find loop point
47         loopfinder/findloop "$t"/n$note.wav $fftsize $len $loopmin $loopmax "$t"/t$note.wav | while read -r SAMPLES SECONDS; do
48                 oggenc -q9 -o "$fn" -c "LOOP_START=$SAMPLES" "$t"/t$note.wav
49         done
50
51         # next!
52         start=$(($start+$step))
53 done
54
55 exit 0