Debian Codegraph @

tools/sound2faust/sound2reader

raw
1 #!/bin/bash
2
3 #-------------------------------------------------------------------
4 # Analyze command arguments :
5 # existing *.wav files -> FILES
6 #
7
8 LLVM="false"
9 FAUSTFLOAT="float"
10 LOCAL="false"
11 EMBED="false"
12 INTERLEAVED="false"
13 WAVEFORM="false"
14
15 for p in $@; do
16 if [ $p = "-help" ] || [ $p = "-h" ]; then
17 echo "sound2reader [-a] [-d] [-l] [-e] [-i] [-w] <file.wav> (or <file.aif>) or sound2reader ... *.wav (or *.aif) for a set of files"
18 echo "sound2reader -w <file.wav> (or <file.aif>) or sound2reader -w *.wav (or *.aif) for a set of files"
19 echo "Use '-a' to use an absolute path to localize the sound file"
20 echo "Use '-d' to use double samples"
21 echo "Use '-l' to compile the sound reader code as a LLVM module"
22 echo "Use '-e' to embed the sound in the C produced program"
23 echo "Use '-i' to embed the sound in the C produced program in interleaved format"
24 echo "Use '-w' to convert the 'foo' soundfile as 'foo.dsp' waveform"
25 elif [[ -e "$p" ]]; then
26 FILES="$FILES $p"
27 elif [ $p = "-l" ]; then
28 LLVM="true"
29 elif [ $p = "-d" ]; then
30 FAUSTFLOAT="double"
31 elif [ $p = "-a" ]; then
32 LOCAL="true"
33 elif [ $p = "-e" ]; then
34 EMBED="true"
35 elif [ $p = "-i" ]; then
36 INTERLEAVED="true"
37 elif [ $p = "-w" ]; then
38 WAVEFORM="true"
39 fi
40 done
41
42 #-------------------------------------------------------------------
43 # compile the *.wav files
44 #
45
46 for f in $FILES; do
47
48 if [[ $f =~ \.aif$ ]]; then
49 name=${f%.aif}
50 else
51 name=${f%.wav}
52 fi
53
54 if [ $WAVEFORM = "true" ]; then
55 echo "Generates the .dsp waveform"
56 sound2faust $f -o $name"_waveform.dsp"
57 elif [ $EMBED = "false" ]; then
58 echo "Generates the C soundfile reader"
59 # compose the soundfile reader C code
60 echo "// SoundFile API" > $name.c
61 if [ $FAUSTFLOAT = "double" ]; then
62 echo -n "#define FAUSTFLOAT " >> $name.c
63 echo $FAUSTFLOAT >> $name.c
64 fi
65 echo "#include \"faust/sound-file.h\"" >> $name.c
66 echo "// Generated API" >> $name.c
67 echo "#ifdef __cplusplus" >> $name.c
68 echo "extern \"C\" {" >> $name.c
69 echo "#endif" >> $name.c
70 echo -n "static SoundFileReader* " >> $name.c
71 echo -n $name >> $name.c
72 echo "_reader = 0;" >> $name.c
73
74 echo -n "int " >> $name.c
75 echo -n $name >> $name.c
76 echo -n "_size()" >> $name.c
77 echo -n " { if (!" >> $name.c
78 echo -n $name >> $name.c
79 echo -n "_reader) " >> $name.c
80 echo -n $name >> $name.c
81 echo -n "_reader = createSFR(\"" >> $name.c
82 if [ $LOCAL = "true" ]; then
83 echo -n $(cd $(dirname $f); pwd)/$(basename $f) >> $name.c
84 else
85 echo -n $f >> $name.c;
86 fi
87 echo -n "\"); return sizeSFR(" >> $name.c
88 echo -n $name >> $name.c
89 echo "_reader); }" >> $name.c
90
91 echo -n "FAUSTFLOAT " >> $name.c
92 echo -n $name >> $name.c
93 echo -n "_sample(int channel, int index) { return sampleSFR(" >> $name.c
94 echo -n $name >> $name.c
95 echo "_reader, channel, index); }" >> $name.c
96
97 echo -n "int " >> $name.c
98 echo -n $name >> $name.c
99 echo -n "_channels() { return channelsSFR(" >> $name.c
100 echo -n $name >> $name.c
101 echo "_reader); }" >> $name.c
102 echo "#ifdef __cplusplus" >> $name.c
103 echo "}" >> $name.c
104 echo "#endif" >> $name.c
105 else
106 echo "Generates the C embedded sound table"
107 if [ $FAUSTFLOAT = "double" ]; then
108 if [ $INTERLEAVED = "true" ]; then
109 sound2file $f -i -d -o $name.c
110 else
111 sound2file $f -d -o $name.c
112 fi
113 else
114 if [ $INTERLEAVED = "true" ]; then
115 sound2file $f -i -o $name.c
116 else
117 sound2file $f -o $name.c
118 fi
119 fi
120 fi
121
122 if [ $LLVM = "true" ]; then
123 echo "Generates the LLVM module from the C code"
124 clang -emit-llvm -O3 -c $name.c
125 fi
126
127 done