Skip to content

Commit

Permalink
Add faust2portaudiojulia tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Jul 23, 2021
1 parent a147671 commit c1b5259
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
89 changes: 89 additions & 0 deletions architecture/portaudio.jl
Original file line number Diff line number Diff line change
@@ -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
<<includeIntrinsic>>
<<includeclass>>

# 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
57 changes: 57 additions & 0 deletions tools/faust2appls/faust2portaudiojulia
Original file line number Diff line number Diff line change
@@ -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] <file.dsp>"
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

0 comments on commit c1b5259

Please sign in to comment.