~pbatch/SKIM-proof-of-concept

Proof of concept implementation for the Sndkit Intermediate Machine Protocol

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~pbatch/SKIM-proof-of-concept
read/write
git@git.sr.ht:~pbatch/SKIM-proof-of-concept

You can also use your local clone with git send-email.

#SKIM proof of concept

This is a small proof-of-concept implementation of the Sndkit Intermediate Machine, or SKIM. This implementation demonstrates what can be done using a handful of files from the sndkit project, and an partially implemented SKIM parser in C.

#What is SKIM?

SKIM is (will be?) a serial protocol that can be used to communicate with the sndkit API to build up and control patches, and is intended to be used inside of stack-based environments like Uxn or RetroForth.

In other words, the idea is to treat sndkit as some kind of synthesizer soundcard that can be plugged into systems as an external device (like an Uxn device). These systems would then send bytes to it to build up patches. Sndkit would then do the heavy lifting of DSP and rendering blocks of audio.

#Building and Usage

SKIM uses pre-tangled sndkit files from the mnolth project, included here as a git submodule. Make sure to initialize those with:

git submodule init
git submodule update

To build the SKIM parser, run:

sh build.sh

Which will produce the SKIM parser program skim, and a program that writes a test patch mkpatch.

The test program writes bytes to standard output, which can be fed to the skim program to be parsed:

$ ./mkpatch | ./skim -v
param 63
mtof zz
param 0.533333
sine zz zz
wavout zz test.wav
param 10
computes zz

With any luck, a 10 second file called "test.wav" should be produced, containing a sine tone.

The -v flag enables verbose output, useful for debugging purposes. It generates the equivalent LIL code that could be parsed using the sndkit parser. It's important to note here that LIL code is not used in SKIM, the underlying sndkit C API calls are being made directly from the bytestream.

#SKIM and Uxn

The main goal of SKIM is to make it easier to embed sndkit into stack-based environments like Uxn. Sndkit itself is very stack oriented, and sounds can be elegantly notated using stack-based systems.

The program mkpatch.tal is a program written in uxntal that produces a patch similar to the one in mkpatch.c.

To use it, first build the rom:

uxnasm mkpatch.tal mkpatch.rom

Then, run the rom using uxncli, and pipe the output to the skim program.

$ uxncli mkpatch.rom | ./skim -v
param 60
mtof zz
param 0.533333
sine zz zz
wavout zz test.wav
param 10
computes zz

The important bit of this uxntal program can be seen here:

#3c uint8 mtof #08 fixed8 sine ;filename string wavout
#0a uint8 computes

It's still a little clunky, but the overall structure vaguely resembles the equivalent Sporth syntax, which is cool!

60 mtof 0.5 sine "test.wav" wavout
10 computes