File: faust2sam

package info (click to toggle)
faust 2.14.4~repack2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 276,136 kB
  • sloc: cpp: 231,578; ansic: 15,403; sh: 10,871; java: 6,917; objc: 4,085; makefile: 3,002; cs: 1,077; ruby: 951; python: 885; xml: 550; yacc: 516; lex: 233; lisp: 201
file content (149 lines) | stat: -rwxr-xr-x 5,029 bytes parent folder | download
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash

#************************************************************************
# Copyright (c) 2017 Analog Devices, Inc.  All rights reserved.
#************************************************************************

#####################################################################
#     Generates inline faust objects for the SHARC Audio Module     #
#           Gregory Pat Scandalis, moForte, ADI                     #
#           based on faust2api by Romain Michon                     #
#####################################################################

. faustpath
. faustoptflags

# change if you want to get the log of what's happening
LOG="/dev/null"
#LOG="log"

# exit if a command fails
set -e

# global option variables

NVOICES="0"
#PACKAGENAME="0"
POLY2="0"
MIDI="0"
NODOC="0"
EFFECT=""

echoHelp ()
{
    echo ""
    echo "faust2sam can be used to generate faust-based dsp objects for the ADI SHARC Audio Module board"
    echo ""
    echo ""
    echo "Global options:"
    echo "   -midi"
    echo "   -nvoices <num> : creates a polyphonic object with <num> voices."
    echo "   -effect <effect.dsp>: adds an effect to the polyphonic synth (this option is ignored if -nvoices is not specified)."
    echo "" 
}

createAPI ()
{
    cp -r $FAUSTLIB/sam/fast_pow2.h $APIFOLDER
    cp -r $FAUSTLIB/sam/samFaustDSP.h $APIFOLDER
    faust -i -a sam/samFaustDSP.cpp $OPTIONS "$FILE" -o "$APIFOLDER/samFaustDSP.cpp" || exit 1
    if [ "$POLY2" = "1" ]; then
        faust -i -cn effect -a minimal-effect.cpp $EFFECT | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp" || exit 1
        echo "#define POLY2 1" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    fi
    if [ "$NVOICES" -gt "0" ]; then
        echo "#define NVOICES $NVOICES" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    fi
    if [ "$MIDI" = "1" ]; then
        echo "#define MIDICTRL 1" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    fi
    # These are things that always need to be at the top and bottom
    echo "#if USE_FAUST_ALGORITHM" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    echo "#include \"./samFaustDSPCore.h\"" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    echo "#include \"common/audio_system_config.h\"" | cat - "$APIFOLDER/samFaustDSP.cpp" > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
    echo "#endif" >> "$APIFOLDER/samFaustDSP.cpp"

    echo "#if USE_FAUST_ALGORITHM" | cat - "$APIFOLDER/samFaustDSP.h" > temp && mv temp "$APIFOLDER/samFaustDSP.h"
    echo "#include \"./samFaustDSPCore.h\"" | cat - "$APIFOLDER/samFaustDSP.h" > temp && mv temp "$APIFOLDER/samFaustDSP.h"
    echo "#include \"common/audio_system_config.h\"" | cat - "$APIFOLDER/samFaustDSP.h" > temp && mv temp "$APIFOLDER/samFaustDSP.h"
    echo "#endif" >> "$APIFOLDER/samFaustDSP.h"
    
    echo "#if USE_FAUST_ALGORITHM" | cat - "$APIFOLDER/fast_pow2.h" > temp && mv temp "$APIFOLDER/fast_pow2.h"
    echo "#include \"./samFaustDSPCore.h\"" | cat - "$APIFOLDER/fast_pow2.h" > temp && mv temp "$APIFOLDER/fast_pow2.h"
    echo "#include \"common/audio_system_config.h\"" | cat - "$APIFOLDER/fast_pow2.h" > temp && mv temp "$APIFOLDER/fast_pow2.h"
    echo "#endif" >> "$APIFOLDER/fast_pow2.h"
    
    # fix things that won't compile on the sharc
    cat "$APIFOLDER/samFaustDSP.cpp"  | \
    sed     -e 's/\(std::cerr.*;\)/\/* \1 *\/ /' \
	    -e 's/std::cout/\/\/std::cout/' \
	    -e 's/getCPULoad(void/faustGetCPULoad(void/' \
	    -e 's/std::stringstream/std::ostringstream/' \
	    -e 's/dynamic_cast/static_cast/' \
	    > temp && mv temp "$APIFOLDER/samFaustDSP.cpp"
}

# dispatch command arguments
while [ $1 ]
do
	p=$1

    if [ $p = "-help" ] || [ $p = "-h" ]; then
        echoHelp
        exit
    elif [ "$PACKAGENAME" = "-1" ]; then
		PACKAGENAME="$p"
    elif [[ -f "$p" ]]; then
		FILE="$p"
    elif [ "$p" = "-effect" ]; then
        POLY2="1"
		shift
		EFFECT=$1
    elif [ "$p" = "-midi" ]; then
        MIDI="1"
    elif [ $p = "-nvoices" ]; then
		shift
		NVOICES=$1
    elif [ $p = "-package" ]; then
        PACKAGENAME="-1"
    elif [ ${p:0:1} = "-" ]; then
        OPTIONS="$OPTIONS $p"
    elif [[ -f "$p" ]]; then
        FILES="$FILES $p"
    else
        OPTIONS="$OPTIONS $p"
    fi

shift

done

if [ -z $FILE ]; then
    echoHelp
    exit 1
fi

###################################
# GENERATING API
###################################

APIFOLDER="${FILE%.*}-sam"

rm -r "$APIFOLDER" 2> /dev/null || true
mkdir "$APIFOLDER"

    echo "Your $APIFOLDER.zip package is being created"
    createAPI

###################################
# POST PROCESSING
###################################

ZIPOUT="$APIFOLDER.zip"

rm $ZIPOUT 2> /dev/null || true
zip -r $ZIPOUT $APIFOLDER > /dev/null || exit 1
rm -r $APIFOLDER || exit 1

# echos generated files for FaustWorks
echo "$ZIPOUT;"