Announcing purescript-wags: a library for rendering web audio
Mike Solomon
Posted on April 14, 2021
I'm thrilled to announce the successor to purescript-audio-behaviors
: purescript-wags
. WAGS is short for "Web Audio Graphs as a Stream", and stream-based computation is at the heart of its design.
Why another library?
When I created purescript-audio-behaviors
, it suffered from three issues from the get-go.
- It didn't render audio fast enough, causing audible jank and laggy instruments.
- It required giving each audio unit a tag, which made the code suffer from the same problem as all stringly-typed APIs.
- Complex feedback loops were impossible to achieve.
The second two problems were livable, but the first one proved to be really annoying. There were too many clicks, stutters, pops and lags. Responsive instruments were impossible to create, and I had to slow down the rendering engine in all but the most trivial works, which made attacks and releases less crisp.
The library's fundamental problem was that it needed to do multiple graph traversals, whereas any real rendering engine has a YOLO philosophy that avoids needless computations. Over the past month, I embarked on a new adventure: creating a second library from the ground-up, aka purescript-wags
.
Show me the sound!
Here is some sound made with purescript-wags
.
How it works
Under the hood, purescript-wags
uses a combination of Functional Reactive Programming, Type-Level Programming, Linear types and comonads to achieve ultra-fast web audio rendering.
Over the next few months, I'll do my best to write up articles on the points below, all of which contribute to the library in one way or another.
- a
MemoizedState
monad that is conceptually close to theEnv
comonad - simulated linear types using a proof system
- inductive types using typelevel Peanos to efficiently represent changing audio
- the use of typeclasses for overloaded audio unit constructors
- type-level lenses into audio graphs (ie creating audio, connecting audio, disconnecting audio, etc).
- indexed applicative functors
- indexed cofree comonads
- bitwise arithmetic in the type system
- type-level loops using rebasing
- Using events and behaviors for JIT scheduling
- the Well-Typed Klavier, which was the reason I started this whole thing.
I hope you make some great web-art with purescript-wags
! If you have any questions, please don't hesitate to ask on this page or on the GitHub repo πΉπ€πΌπ.
Posted on April 14, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.