7c1d55aa79c2f02991a86fb2625cf8a9b9111c68
[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 synth=$1; shift
11 program=$1; shift
12 velocity=$1; shift
13 transpose=$1; shift
14 tubaid=$1; shift
15
16 delta=2
17 fftsize=512
18 loopmin=1.1
19 loopmax=1.5
20 len=1.8
21
22 perl tuba_loopnote_maker.mid.pl tuba_loopnote_maker.mid $delta $program $velocity $transpose -18 -12 -6 0 6 12 18 24
23
24 case "$synth" in
25         timidity)
26                 timidity -Ow "$@" -o out.wav tuba_loopnote_maker.mid
27                 normalize out.wav
28                 ;;
29         fluidsynth)
30                 fluidsynth -v -n -i -l -T wav -F out.wav "$@" tuba_loopnote_maker.mid
31                 normalize out.wav
32                 ;;
33 esac
34
35 start=$delta
36 step=$(($delta*2))
37 for note in -18 -12 -6 0 6 12 18 24; do
38         sox out.wav n$note.wav \
39                 trim $start $step \
40                 silence 1 1s 0
41
42         fn=tuba"$tubaid"_loopnote"$note".ogg 
43
44         # now find loop point
45         loopfinder/findloop n$note.wav $fftsize $len $loopmin $loopmax t$note.wav | while read -r SAMPLES SECONDS; do
46                 oggenc -q9 -o "$fn" -c "LOOP_START=$SAMPLES" t$note.wav
47         done
48
49         # next!
50         start=$(($start+$step))
51 done