ebook img

LAC 2015 - Paper: MobileFaust: a Set of Tools to Make Musical Mobile Applications with the Faust Programming Language PDF

2015·0.42 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview LAC 2015 - Paper: MobileFaust: a Set of Tools to Make Musical Mobile Applications with the Faust Programming Language

MobileFaust: a Set of Tools to Make Musical Mobile Applications with the Faust Programming Language Romain Michon Julius O. III. Smith Yann Orlarey CCRMA CCRMA GRAME Stanford University Stanford University Lyon CA 94305-8180 CA 94305-8180 France USA USA [email protected] [email protected] [email protected] Abstract This paper presents a series of tools that can turn Faust code into various elements rang- This work presents a series of tools to turn Faust ing from fully functional applications to multi- code into various elements ranging from fully func- tional applications to multi-platform libraries for platformlibrariesforreal-timeaudiosignalpro- real time audio signal processing on iOS and An- cessing on iOS and Android. Technical details droid. Technicaldetailsabouttheiruseandfunction abouttheiruseandfunctionareprovided,along are provided along with audio latency and perfor- with audio latency and performance compar- mance comparisons, and examples of applications. isons, and examples of applications. Keywords 2 Faust2api Faust, iOS, Android, DSP The main idea of faust2api is to provide iOS andAndroiddeveloperswithasystemthatgen- 1 Introduction erates custom high-level APIs for real-time au- dio signal processing. Even though the APIs Mobile platforms offer a great opportunity to work quite differently “under the hood” on iOS the world of open source audio to make sound than on Android, they are accessed similarly on synthesis and processing accessible to a wider the two platforms. audience[YiandLazzarini, 2012; Brinkmannet The faust2api script operates as a al., 2011]. The use of smartphones and tablets command-line tool in a shell. A Faust as musical instruments is now accepted by a source file is provided as an argument, along large number of musicians. Not only are mobile with the option -ios or -android specifying deviceswidespreadandownedbymany,theyof- the desired architecture, and one or more fer a higher level user interface paradigm than source files are created as output (a single computers,whichoftenmakesthemmorestable C++ header file for iOS, and a directory and simpler to use. In particular, Android de- containing both Java and C++ source files for vices, which are more open than iPhones and Android). The library takes care of starting iPads (§3) offer a good compromise between the audio engine and instantiating the DSP open-source, stability, and ease of use. code, as well as connecting them together. Faust1 [Orlarey et al., 2002] is a functional At the API level, this is all done by the programming language for real-time digital sig- C++ method init(sr,bs) which takes the nal processing (DSP) that generates highly effi- desired sampling-rate and audio buffer-size as cient DSP code in a variety of languages (C, arguments. Computing of the audio process is C++, LLVM, asmjs, and more) that can be launched by a start() method. Finally, the compiled into a variety of forms using a sys- audio engine can be closed and the memory tem of wrappers. These wrappers, called ar- freed by simply calling stop().2 chitecture files, describe how to adapt the DSP On both iOS and Android, the audio pro- computation to the external world [Fober et al., cess runs in its own high-priority thread. The 2011]. Therefore, it is easy to go from Faust various parameters of the Faust object can be to standalone applications for different kinds of accessed and written via getParam(path) and platforms,Webapplications,audioplug-ins,ex- setParam(path) where the parameter path is ternals for music programming languages, and so on. 2Detailed documentation of the API can be found here: https://ccrma.stanford.edu/~rmichon/ 1http://faust.grame.fr mobileFaust/#ref the parameter’s path in the user-interface tree was placed at the top of the screen of the de- defined in the Faust code (as discussed further vice. The latency measurements were carried below in §3.3 on OSC and MIDI support). out by measuring the time difference between If the Faust object provided to faust2api the “acoustic” impulse detected by the micro- has no inputs, and has freq, gain, and gate phone and the synthesized one (Fig. 2). parametersdefined,itisconsideredasaninstru- ment and automatically made polyphonic. The different voices (eight by default, but this can be changed) can be triggered using a keyOn() method that takes a MIDI note number and MIDI velocity as an argument. This method is ADC Time Difference linked to the freq, gain, and gate parameters (§3.1) and allocates a new voice every time it is iPad called. The keyOff() method sets the gate pa- rameter of the voice to zero and waits until the levelofthevoicefallsbelow-60dBtodeallocate Audio Jack Out it. 2.1 iOS Figure 2: Touch to Sound Audio Latency Mea- The command “faust2api -ios surement Set-Up. faustCode.dsp” will generate a single C++ header file that can be included in 2.2 Android any iOS app project. The API relies on the AVAudioSession3 framework to connect to the faust2api is slightly more complex to use audio engine. on Android than iOS. Indeed, Android apps “Touch to sound” and “round-trip” latency are primarily programmed in Java. However, measurements for iOS audio applications gener- this language is not very well suited for real atedbyfaust2apiwerecarriedoutonaniPad2 time DSP so most of the library generated by and an iPhone5 (Fig. 1). faust2api is written in C++ with a Java in- terface. Device Touch to Sound Round-Trip The audio engine is accessed, controlled and iPhone5 36 ms 13 ms connectedtotheDSPcodegeneratedby Faust iPad2 45 ms 15 ms on the “native” side of the library where ev- erything is computed in a high-priority thread. Thisallowsthesignalprocessingpartoftheapp Figure 1: Audio Latency for Different iOS De- to be fully independent from the Java side. vices Using the Faust Library. The native portion of the library is compiled “Round-trip”latencywasmeasuredbycreat- asasharedlibraryusingtheAndroidNDK5 and ing a simple app that just plays back any sound can be controlled in Java using a JNI6 interface that comes to its audio input (in our case, the generated by SWIG.7 More details about the audio input jack) and by comparing how long it way this system works can be found in [Michon, takesfortheiOSdevicetoplaybackanimpulse 2013]. sent to this app. In practice, faust2api will generate the An- “Touch to sound” latency was measured by droidAPIbyusingthe-androidoptioninstead creating a simple test app where a button on of -ios (cf. previous section) and will provide the screen is used to trigger an impulse. The a set of Java and C++ files to be copied in the audio output jack of the iOS device was con- Android app project.8 nected to an ADC4 in order to be able to record the impulse on a computer. A microphone con- 5Native Development Toolkit: https://developer.android.com/tools/sdk/ndk/ nected to the same ADC on a different channel 6Java Native Interface 3https://developer.apple.com/library/ios/- 7Simplified Wrapper and Interface Generator: documentation/AVFoundation/Reference/- http://www.swig.org/ AVAudioSession ClassReference/index.html#//- 8A tutorial on how to do this can be found apple ref/occ/cl/AVAudioSession here: https://ccrma.stanford.edu/~rmichon/ 4Analog to Digital Converter mobileFaust/#f2apAndroid Latency measurements using the same tech- niques presented in the previous section were carried out on a Samsung Galaxy S5, a Google Nexus 5, and a Google Nexus 7 that were all runningonAndroid5.0(Lollipop). Itisdifficult tomakeacompletecomparisonhereinthesame way as for iOS because latency varies greatly between devices and manufacturers. The main observation that can be made though is that audio latency is much larger on Android than iOS. Device Touch to Round- Sound Trip Samsung Galaxy S5 72 ms 78 ms Google Nexus 5 90 ms 92 ms Google Nexus 7 130 ms 130 ms Figure 3: Audio Latency of Different Android Devices Using the Faust Library. Figure 5: Example of interface generated Core Audio by faust2android containing groups, sliders, knobs and checkboxes. Custom Audio Library Faust Poly iOS Architecture 3.1 Keyboard and Multitouch Interface (C++ Wrapper) Wrapping (iOS) IOS C++ Library Faust Program Faust Compilation C++ DSP Code faust2android allows assignment of more in- Wrapping (Android) teractive interfaces to the Faust process. For OpenSL ES that, three different metadata items can be Shared Library Custom Audio Library added to the top-level group of a Faust pro- JAVA Interface to Faust Poly The Shared Library gram. In Faust, a metadata item consists Android Architecture (C++ Wrapper) of a key:value pair, specified between square brackets within a title string, i.e., "Some Title Figure 4: faust2api Overview. [key:value]...". The [style:keyboard] metadata item spec- ifies that the freq, gain, and gate parameters 3 Faust2android in the Faust code should be assigned to a pi- ano keyboard that can be opened by touching While a preliminary version of faust2android the “keyboard icon” in the top right corner of was presented in [Michon, 2013] it has been to- the app. Also, these three parameters will be tallyrewrittensincethenandoffersalargenum- automatically removed from the main interface ber of new functionalities. for controlling the other parameters. faust2android is built on top of faust2api The following example program illustrates a (Fig. 9). Its user interface is constructed using simple usage: the JSON description provided by the shared library generated by faust2api. All the stan- import("music.lib"); dard Faust UI elements are available: horizon- s = button("gate"); tal and vertical groups, horizontal and vertical g = hslider("gain",0.1,0,1,0.001); sliders, numerical entries, knobs, checkboxes, f = hslider("freq",100,20,10000,1); buttons, drop-down menus, radio buttons, bar- process = vgroup("[style:keyboard]", graphs, etc. Some examples are shown in figure s*g*osc(f)); 5. The values of the parameters of the audio process running on the native side are changed This interface uses the polyphonic capabili- using the setParam() function of the API. ties of faust2api. Touching a key on the key- boarddeterminesthereferencepitchofthenote that can be opened by holding the label of a but sliding the finger across the X axis of the parameter for more than one second (Fig. 7). screen allows the user to continuously control Fromhere,themappingofanaccelerometertoa it. The Y axis determines the gain of the note. parameter can be configured precisely to create If a MIDI keyboard is plugged into the Android complex linear and non-linear behaviors. For device, it will be able to control the keyboard instance, the user can choose which axis will interface (§3.3). control the parameter (x, y, or z), its motion The [style:multi] metadata item will cre- orientation, and sensitivity. ate a simple interface in which parameters are Three different modes can be used to control represented by moveable dots on the screen. theorientationoftheaccelerometer,normal,in- Each dot can have two parameters assigned to verted, and bell. In bell mode, the maximum it, corresponding to x and y screen coordinates. value of the accelerometer is output when it is This interface can also be opened by touching in center position and the minimum value when the keyboard icon on the top right corner of the it is fully inclined to the left or right. screen. Parameters are linked to the interface Sensitivity can be configured with three dif- via [multi:x] metadata where x is the ID of ferent parameters, min, max, and center, that the parameter in the interface. For example, are all expressed in m/s2 ×10−1. As an exam- the Faust program ple, setting min to -1, max to 1, and center to 0 will create a linear behavior where the mini- import("music.lib"); mum value of the parameter being controlled is freq = hslider("freq[multi:0]", given at position -90 degrees and the maximum 440,50,2000,0.1); value at position +90 degrees. Any acceleration process = hgroup("[style:multi]", beyond these limits will be clipped. osc(freq)); All these parameters can be configured from creates an app in which the frequency param- the Faust code using metadata by specifying eter of a sine oscillator is controlled by the X [acc: a b c d e], where a is the axis (0 for axis of the dot in the multitouch interface. Pa- x, 1 for y, 2 for z), b the orientation (0 for nor- rameters that have the accelerometer assigned mal, 1 for inverted, 2 for bell), c the minimum, to them (cf. §3.2) will continue to be driven by d the maximum and e the center. the accelerometer in the interface. Raw data from the accelerometers are passed Finally, the [style:multikeyboard] meta- directly to the Faust audio process. Filtering data combines the keyboard and multitouch in- can be carried out in Faust which is better terface into one (Fig. 6). suited for that kind of task than Java. Finally, the accelerometer parameters win- dow is only accessible if the app is unlocked by touching the “lock” icon on the top right cor- ner of the screen (Fig. 5). Apps can be locked to prevent users from opening a configuration window or rotating the screen during a perfor- mance. Figure 6: Example of “Multi-Keyboard” Interface of an Application Generated by faust2android. 3.2 Using the Built-In Accelerometer The Accelerometer can be used to control some Figure 7: Accelerometer Configuration Panel of elements of the user interface. Assignments are an Application Generated by faust2android. made in the Accelerometer Parameters panel 3.3 OSC and MIDI Support Faust Program (.dsp file) OSC support is enabled by default for all Faust Compilation (cf. faust2api diagram) the parameters of applications generated by Audio Out Shared Library Com through JNI thJAe VSAh Ianrteedrf aLciber atory faust2android. TheOSCaddressofaparame- Native Thread tercorrespondstothepathtothisparameterin User Interface Controller Interfaces the Faust code. For example, the OSC address of the freq parameter of the Faust code Sensors OSC/MIDI JAVA Thread freq = hslider("freq", 440,50,2000,0.1); Figure 9: faust2android Overview. process = hgroup("Main",osc(freq)); 3.5 Easy App Generation will be /Main/freq. MIDI support is also enabled by default While it is relatively simple to use in apps generated by faust2android. MIDI faust2android, it requires the programmer Key Number is automatically mapped to the to have an important number of dependencies freq parameter by converting it to frequency installed (Android SDK and NDK, etc.). in Hz, and similarly MIDI velocity → gain. However, FaustLive [Denoux et al., 2014] Note on/off events control the gate parame- and the Faust Online Compiler [Michon and ter, just like the keyOn() and keyOff() func- Orlarey, 2012] make the process of turning tions of faust2api. Synthesizer apps gener- Faust code into an Android application very ated with faust2android all have eight voices simple. Indeed, when the user chooses to of polyphony. compile a Faust program as an Android app, a MIDIcontrolnumberscanbeassignedtospe- QR code pointing to the generated app package cific parameters from the Faust code using the is displayed that can be scanned by the device [midictl:x] metadata where x is the MIDI where the user want the app to be installed. control number. 4 Applications 3.4 Audio IO Configuration The Faust distribution contains a collection of Android applications generated with librariesthatimplementalargenumberofcom- faust2android automatically choose the mon and less-common audio effects, filters, and best sampling rate and buffer size as a function synthesizers. With faust2api, iOS and An- of the device that is running them (for Nexus9 droid programmers who don’t know signal pro- devices only). Indeed, it was explained during cessing or who never worked with real-time au- the Google I/O 2013 conference on High dio can easily integrate any of the pre-written Performance Audio10 that Android phones and Faust modules into their project without hav- tablets achieve better audio latency perfor- ing to write a single line of DSP code. On mance if they run with a specific buffer size and the other hand, this tool also gives the op- sampling rate (see Fig. 8). Users may override portunity to Faust developers to have their these default values in the settings menu of the work used by more people. A concrete use of app. this tool was made this year in the Music 256b Device Sampling Rate Buffer Size class11 “Mobile Music” offered at Stanford Uni- versity’s Center for Computer Research in Mu- Nexus S 44100 880 sic and Acoustics (CCRMA)12 where students Galaxy Nexus 44100 144 were given the opportunity to use faust2api in Nexus 4 44100 240 their final projects. Nexus 7 44100 512 Another use of applications generated by Nexus 10 44100 256 faust2android and faust2ios is the Smart- Others 44100 512 Faust13 project led by Xavier Garcia and Christophe Lebreton at GRAME. The idea was Figure 8: Preferred Buffer Sizes and Sampling 11https://ccrma.stanford.edu/courses/ Rates for Various Android Devices. 256b-winter-2015/ 12http://ccrma.stanford.edu 9http://www.google.com/nexus/ 13http://www.grame.fr/anything_slides/ 10http://youtu.be/d3kfEeMZ65c concert-smartfaust to make a series of concerts where the music is Sarah Denoux, Stephane Letz, Yann Orlarey, madebytheaudiencewiththeirmobilephones. and Dominique Fober. 2014. FaustLive: just- SeveralapplicationswereputontheAppleStore in-time Faust compiler and much more. In and the Google Play Store that people could Proceedings of the Linux Audio Conference download prior to the concert. This project led (LAC-14), pages 102–107. ZKM, Karlsruhe to more metadata for controlling the user in- (Germany), May. terfaces; for example, it is possible to choose to Dominique Fober, Yann Orlarey, and notintegrateaUIelementtotheinterface. This St´ephane Letz. 2011. Faust architecture enables the Faust programmer to control some design and OSC support. In Proceedings specific parameters with the accelerometer (us- of the Conference on Digital Audio Effects ing metadata too) without displaying them in (DAFx-11), pages 213–216, IRCAM, Paris, the interface. faust2android can also generate France. “concert apps”, where the user can switch be- tween different Faust objects within the same RomainMichonandYannOrlarey. 2012. The application. Faust online compiler: a web-based IDE for theFaustprogramminglanguage. InProceed- 5 Conclusions ings of the Linux Audio Conference (LAC- 12), pages 111–116. CCRMA, Stanford Uni- Several tools that use Faust to help design versity (USA). or make ready-to-use Android and iOS appli- cations were presented. We believe that they Romain Michon. 2013. Faust2android: a make the development of musical applications Faust architecture for Android. In Pro- on mobile platforms easier and that they will ceedings of the 16th International Confer- contribute to making the use of Faust objects ence on Digital Audio Effects (DAFx-2013), more accessible to musicians and performers. pages 98–102. National University of Ireland While iOS real-time audio applications pro- (Maynooth), September. vide much better (smaller) audio latency than Yann Orlarey, Dominique Fober, and Android, the various restrictions imposed by Stephane Letz. 2002. An algebra for block Apple on their deployment makes them less ac- diagram languages. In Proceedings of the cessible which is a big issue for the use that we International Computer Music Confer- make of them with Faust. Therefore, we hope ence (ICMA), pages 542–547. Gothenburg, thatGooglewillresolvetheaudiolatencyissues Sweden. for Android applications in the near future. FaustLive and the Online Compiler provide StevenYiandVictorLazzarini. 2012. Csound for Android. In Proceedings of the Linux easy ways to use the tools presented in this pa- Audio Conference (LAC-12), pages 233–239. per. However, we think that enhancing them with an online platform where Faust develop- CCRMA, Stanford University (USA). ers can easily share their work with others in order to create a repository of Faust resources would be a great addition. 6 Acknowledgments Part of this work has been implemented un- der the FEEVER project [ANR-13-BS02-0008] supported by the Agence Nationale pour la Recherche. References Peter Brinkmann, Peter Kirn, Richard Lawler, Chris McCormick, Martin Roth, and Hans-Christoph Steiner. 2011. Embedding Pure Data with libpd. In Proceedings of the Pure Data Convention. Bauhaus U., Weimar (Germany).

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.