💾 Archived View for drawk.cab › projects › floatbeat › index.gmi captured on 2023-11-04 at 11:43:28. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

-=-=-=-=-=-=-

Floatbeat

Fun and fast live-coded music!

Introduction

In the early 2010s there was a brief thing for "bytebeat", which was about writing extremely short programs which produced more-or-less musical output. There was one called IBNIZ which also produced visuals and had a more-or-less impenetrable syntax. It was weird and a bit magic. I think 'live coding' is still going on in some parts, mostly using javascript, but it seems to be less experimental and seat-of-the-pants than bytebeat was.

This is what IBNIZ looks like.

Bytebeat

IBNIZ, by Ville-Matias Heikkilä

Floatbeat is a sound and music generator for fast live coding in a Forth-like language I've called Diminished Forth, because it's missing a lot of the standard Forth words. And because it's a pun!

Like the bytebeat programs it is based on a single time counter, which increments for every sample it needs to output, about 20,000 times a second. Floatbeat runs your program in full for each sample. This need for decent performance is why I chose Forth (and golang) for this project. Any value that gets 'printed' during execution (with the Forth word `.`) is sent to the sound library. Floatbeat expects the stack to be empty at the end, and rejects the program if it isn't.

When you run Floatbeat, you can supply a program as an input file, or you can connect to its web server. This uses web sockets to allow you to edit the program while the sound is being output.

Here's a sample d4 program which outputs a looping tune with a vibrato effect:

    :: scale ticks;                           (This line loads some supplied libraries: )
                                              (  scale defines the standard note names, )
                                              (  and ticks divides time up into bars.   )

    8 280bpm ticks swap                       (Sets up 8-beat bars of 280bpm ticks. )
    from G low, B', G, D, D', C, E, G choose  (Sets the pitch based on the beat in the bar. )
    lfo.                                      (Runs the subroutine below and outputs the result. )

    :lfo (age freq -- signal)                 (This subroutine provides the synth sound. )
        over * swap
        6Hz * sin
        +tr
    ;

You can change the tune, sound or modulation with a few keystrokes and immediately hear the result.

Floatbeat uses Gorilla for websockets and portaudio for sound. I've only tested it on my Linux machine, and that not recently. You need to build it yourself to run it, which involves setting up golang.

The code is here on github

Diminished Forth is a separate library

Conclusions

In 2015 my computer was just about fast enough to produce simple sounds using Floatbeat. This is the main reason I moved on to other things. Also I wasn't massively happy with portaudio either, for reasons I have now forgotten.

I also hit a fundamental problem with doing this stuff in the time domain: at some point your time counter loops, or gets uncomfortably large for whatever arithmetic your code is doing, and you get an audible click. I don't know what a frequency-domain live coding app would look like. Maybe it would be awesome?

Practically, live coding is very easy to mess up. This probably isn't limited to Forth. There's only one program buffer and it's unforgiving if you make a mistake. Too many or too few items on the stack will cause the program to be rejected, so floatbeat will continue running the last program that worked. At best this means you don't hear your changes; at worst you've left it in some weird but valid state that sounds bad. Two compatible approaches to this problem might be

I still think there are places live coding, or live production, can go, and I definitely support bringing more of the process of production onstage. Maybe Sonic Pi is the answer, it looks pretty good, though I think it mostly works with samples.

Sonic Pi