Real-time audio in praxis

Praxis features an audio engine that allows your program to synthesize audio in real time. A demonstration of this can be seen in the Synthbench program, which synthesizes audio and renders the waveforms it generates. It emulates the style of the Reactable system, where you arrange widgets on a table to generate a sound. Some widgets emit a waveform, some widgets apply an effect to the waveform they have been placed on top of and some widgets emit a low frequency waveform for controlling a parameter of the widgets it is connected to. Once again, I made this because when I saw the Reactable I thought it looked really fun, so I wanted to make a version of this “toy” for myself so I could play with it. That’s what praxis is all about – making your own universe of play where any toy you care to describe can be brought to life.

The version of Synthbench that exists in praxis only features the node audio generation behaviours and rendering. What is missing is being able to place new nodes and move them around with the mouse: you need to use code to add new nodes and move them. This is purely due to laziness. I chose to write the part of Synthbench that I wrote mainly to test that real time audio generation could be done fast enough in Lua. That is, each node needs to generate and render enough samples per second to satisfy the audio pipeline while maintaining 50 frames per second. After I was satisfied that it works, I let my attention drift to other things.

The reason for praxis

When I saw what was possible with Lisp Machines, Smalltalk environments (Squeak, Croquet) and Emacs, I realized that what I loved most about those systems I could create for myself very easily just with an embeddable language and a render loop. The most valuable ingredient that makes this work really are the embeddable languages, so thank you so much to the makers of Lua, FICL Forth and s7 scheme for making these beautiful languages accessible through a C API.

I’m surprised that systems like praxis aren’t more common considering how fun it is and how easy it is to set up, or maybe its just that while this style is perfectly suited to my taste, its not necessarily what other people prefer.

One way of looking at praxis is as a repl augmented with a graphical and audio engine to use as you see fit. The socratic dialogue you have with your world as you define it and build it is enhanced by visualizations you are free to add in any form and at any stage. For instance, say you are making a simulation, and part of it calls for an implementation of AI strategy which involves exploring a complex algorithm. You can change the render function to not run the usual simulation, and instead temporarily focus on the behaviour of the AI algorithm. When you are satisfied, you can swap your old simulation render and state back in and pick up where you left off.

Although the primary intended way of interacting with your world with praxis is through the programs you write in the editor, there are many Lua calls that are generated from input events that you can redefine. In addition, the graphical engine has features such as a pick cursor and a non-banking mouse camera movement model with the ability to change the ground plane (orbiting, panning, moving in and out) which when combined with the introspection facilities of Lua and commands that allow you to modify the text edit buffer, allow you to add powerful customized editing features to your environment. For example, at the press of a button you can have praxis perform a simple behaviour such as inserting the pick position into the program, or something more complex such as inserting the definition of the update function for the object the mouse is currently hovering over so it can be edited. This was inspired by the “code gun” idea in the “Code Hero” project, where a piece of code can be “fired” at an object in the world and it would be applied to the object that was hit. The same thing can be achieved in praxis for example by setting the definition of LMBDown to be: find the object the pick position is nearest to, then run the code in the “code gun” with this object as a parameter.

So praxis is the result of me implementing all the various things I’ve seen in other live coding environments that I thought was cool. The Lua files that come with praxis are a little messy, because I make something and then get distracted by the next shiny trinket I want to make. I’ve added things like portals you can peer through (the sort you see in the Croquet Smalltalk project) which I’ve implemented with stencils, midi recording, a modifiable camera ground plane, being able to draw to textures and use them and other assorted bits and pieces. When I added s7 scheme, I got some SICP code that I liked working with it (I like all of it naturally, but specifically, the symbolic algebra stuff). I added Forth just because I like it. In praxis, another key idea is that you can recover from any fault, including an infinite loop, or even a fault deep inside the call to render. The editor and a basic ground grid is always available so you can see where the problem occurred, fix it, and continue the render/update loop with minimal disruption to the state of the system you are making.

Please enjoy praxis, and I hope you create many wonderful universes with it.