diff --git a/architecture/portaudio.jl b/architecture/portaudio.jl new file mode 100644 index 0000000000..164409277b --- /dev/null +++ b/architecture/portaudio.jl @@ -0,0 +1,89 @@ +# ************************************************************************ +# FAUST Architecture File +# Copyright (C) 2021 GRAME, Centre National de Creation Musicale +# --------------------------------------------------------------------- + +# This is sample code. This file is provided as an example of minimal +# FAUST architecture file. Redistribution and use in source and binary +# forms, with or without modification, in part or in full are permitted. +# In particular you can create a derived work of this FAUST architecture +# and distribute that work under terms of your choice. + +# This sample code is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# ************************************************************************ + +const FAUSTFLOAT = Float32 + +# Architecture +abstract type UI end + +# One can override the behavior by defining another set of function that takes a different concrete UI type + +# -- widget's layouts +function openTabBox(label::String) +end +function openHorizontalBox(label::String) +end +function openVerticalBox(label::String) +end +function closeBox() +end + +# -- active widgets +function addButton(ui_interface::UI, label::String, param::Symbol) +end +function addCheckButton(ui_interface::UI, label::String, param::Symbol) +end +function addHorizontalSlider(ui_interface::UI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT) +end +function addVerticalSlider(ui_interface::UI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT) +end +function addNumEntry(ui_interface::UI, label::String, param::Symbol, init::FAUSTFLOAT, min::FAUSTFLOAT, max::FAUSTFLOAT, step::FAUSTFLOAT) +end + +# -- passive widgets +function addHorizontalBargraph(ui_interface::UI, label::String, param::Symbol, min::FAUSTFLOAT, max::FAUSTFLOAT) +end +function addVerticalBargraph(ui_interface::UI, label::String, param::Symbol, min::FAUSTFLOAT, max::FAUSTFLOAT) +end + +# -- soundfiles +function addSoundfile(ui_interface::UI, label::String, filename::String, soundfile::Symbol) +end + +# -- metadata declarations +function declare(ui_interface::UI, key::String, val::String) +end + +# Generated code +<> +<> + +# Testing +samplerate = Int32(44100) +block_size = Int32(512) + +# Using PortAudio +# import Pkg; Pkg.add("PortAudio") +using PortAudio + +devices = PortAudio.devices() +#dev = filter(x -> x.maxinchans == 2 && x.maxoutchans == 2, devices)[1] + +# Selecting a Duplex device here +dev = devices[10] + +PortAudioStream(dev, dev) do stream + dsp = mydsp{Float32}() + println("getNumInputsmydsp ", getNumInputsmydsp(dsp)) + println("getNumOutputsmydsp ", getNumOutputsmydsp(dsp)) + initmydsp(dsp, samplerate) + outputs = zeros(Float32, block_size, getNumOutputsmydsp(dsp)) + while true + inputs = convert(Matrix{Float32}, read(stream, block_size)) + computemydsp(dsp, block_size, inputs, outputs) + write(stream, outputs) + end +end diff --git a/tools/faust2appls/faust2portaudiojulia b/tools/faust2appls/faust2portaudiojulia new file mode 100755 index 0000000000..549884a89d --- /dev/null +++ b/tools/faust2appls/faust2portaudiojulia @@ -0,0 +1,57 @@ +#! /bin/bash -e + +##################################################################### +# # +# Compiles Faust programs to PortAudio and Julia binary # +# (c) Grame, 2021 # +# # +##################################################################### + +. faustpath +. faustoptflags +. usage.sh + +SRC="0" +ARCHFILE=$FAUSTARCH/portaudio.jl + +#PHASE 2 : dispatch command arguments +while [ $1 ] +do + p=$1 + + if [ $p = "-help" ] || [ $p = "-h" ]; then + usage faust2portaudiojulia "[options] [Faust options] " + require PortAudio + echo "Compiles Faust programs to PortAudio and Julia binary" + option + option -source "only generates the source project." + option "Faust options" + exit + fi + + if [ $p = "-source" ]; then + SRC="1" + elif [ ${p:0:1} = "-" ]; then + OPTIONS="$OPTIONS $p" + elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then + FILES="$FILES $p" + else + OPTIONS="$OPTIONS $p" + fi + +shift + +done + +#------------------------------------------------------------------- +# compile the *.dsp files +# + +for p in $FILES; do + + f=$(basename "$p") + + # compile Faust DSP and put in the cargo folder + faust -a $ARCHFILE -lang julia "$f" -o "${f%.dsp}.jl" + +done