Klein bottle source by CuBeOwL ;)
[xonotic/mediasource.git] / sound / weapons / tuba_loopnote_maker.sh
1 #!/bin/sh
2
3 set -e
4
5 (
6         cd loopfinder
7         gcc -o findloop findloop.c -lfftw3 -Wall -Wextra -ffast-math -lsndfile -lm -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=2048
21 loopmin=0.5
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 cp "$t"/tuba_loopnote_maker.mid tuba$tubaid.mid
27
28 case "$synth" in
29         timidity)
30                 timidity -Ow "$@" -o "$t"/out.wav "$t"/tuba_loopnote_maker.mid
31                 ;;
32         fluidsynth)
33                 fluidsynth -v -n -i -l -T wav -F "$t"/out.wav "$@" "$t"/tuba_loopnote_maker.mid
34                 ;;
35         lmms)
36                 echo "Import $t/tuba_loopnote_maker.mid into LMMS, set instrument, and export as $t/out.wav"
37                 lmms
38                 [ -f "$t"/out.wav ]
39                 ;;
40 esac
41
42 normalize --peak "$t"/out.wav
43
44 start=0
45 step=$(($delta*2))
46 for note in -18 -12 -6 0 6 12 18 24; do
47         sox "$t"/out.wav "$t"/n$note.wav \
48                 channels 1 \
49                 trim $start $step \
50                 silence 1 1s 0
51
52         fn=tuba"$tubaid"_loopnote"$note".ogg 
53
54         # now find loop point
55         loopfinder/findloop "$t"/n$note.wav $fftsize $len $loopmin $loopmax "$t"/t$note.wav | while read -r SAMPLES SECONDS; do
56                 oggenc -Q -q9 -o "$fn" -c "LOOP_START=$SAMPLES" "$t"/t$note.wav
57         done
58
59         # next!
60         start=$(($start+$step))
61 done
62
63 exit 0