# cellphone

Phonetic sonification of a cellular automaton.

# 1 Listen

# 1.1 Live

mathr.co.uk/cellphone

Click button to play.

Total size 3.3 MiB gzipped, 5.2 MiB unzipped. Requires WASM, SharedArrayBuffer, Web Audio, etc, i.e. a modern web browser.

Tested with:

  • Firefox ESR (Debian Bookworm)
  • Chromium (Debian Bookworm)
  • Fennec F-Droid (Android 7 F-Droid)
  • Google Chrome (Android 7)

# 1.2 Stream

M3U (http) / M3U (https)

14 MiB / hour. Requires streaming server to be online, an internet connection and an MP3 streaming client.

Tested with:

  • mpv (Debian Bookworm)
  • VLC (Android 7 F-Droid)

# 1.3 Recording

MP3

14 MiB, 1 hour. 32kbps 16kHz mono.

# 2 Source

code.mathr.co.uk/cellphone

git clone https://code.mathr.co.uk/cellphone.git

# 3 Build

# 3.1 Linux

Dependencies can be installed via package manager (e.g. Debian):

sudo apt install build-essential make libsdl2-dev, libsndfile-dev flite1-dev

Requires support for C11 threads.h.

make

# 3.2 Windows

For cross-compilation from Debian. Dependencies (sdl2, sndfile, flite) can be installed via build-scripts or similar.

Requires support for C11 threads.h. Not yet supported by gcc-mingw as found in Debian Bookworm. Not yet supported by llvm-mingw based on clang-15. Workaround: use Web version.

make SYSTEM=x86_64-w64-mingw32

# 3.3 Web

For cross-compilation from Debian. Dependencies (flite) can be installed via build-scripts or similar.

Requires support for C11 threads.h. Requires emsdk activated in your shell.

make SYSTEM=emscripten

# 4 Run

# 4.1 Linux and Windows

./bin/cellphone [seed [api]]

Seed (a number) controls the pseudo-random number generator. Same seeds generate same output.

API controls the sound generation backend. Valid values are:

  • sdl2 uses default SDL2 audio API (e.g. ALSA on Linux, WebAudio on Web, …).
  • oss uses OSS (/dev/dsp on Linux and similar systems).
  • wav uses libsndfile to (over)write cellphone.wav.

With the WAV backend you will want to stop the program quickly to avoid filling your hard drive. For example:

timeout 1 ./bin/cellphone `date +%s` wav

# 4.2 Web

You need to serve (possibly also gzipped versions of):

www/index.html
www/cellphone.js
www/cellphone.worker.js
www/cellphone.wasm
www/cellphone.tar.gz

Serve the source code corresponding to the compiled code to comply with the license terms.

You need to set some Cross-Origin-*-Policy headers in the web server configuration to enable SharedArrayBuffer etc in modern web browsers (these APIs are requied for Emscripten’s multithreading). Configuration for Nginx:

location /cellphone/ {
    add_header Cross-Origin-Opener-Policy 'same-origin';
    add_header Cross-Origin-Embedder-Policy 'require-corp';
}

# 5 Stream

Tested streaming from a Raspberry Pi 3, where it uses about 20MiB RAM and 3.5% CPU.

Requires ALSA loopback kernel module:

modprobe snd-aloop
echo snd-aloop >> /etc/modules

This will be hw:2 or similar at first, but after reboot the soundcard identifier may change: on my system it became hw:0.

Create a system user to run the stream source. Make sure it is in the audio group.

adduser cellphone
adduser cellphone audio

Choose an unused subdevice ID (by default 8 are available) and configure ~/.asoundrc following cellphone/etc/asoundrc, as hw:x,0,y where x is the snd-aloop card (0 on my Pi after reboot), 0 is the device, and y is the subdevice ID (0-7). Set the same card x and subdevice ID y in cellphone/etc/darkice.cfg following cellphone/etc/darkice.cfg.sample, but set the device to 1 like hw:x,1,y.

Set your own streaming server details in cellphone/etc/darkice.cfg, not forgetting the password. Remember to run

chmod 600 cellphone/etc/darkice.cfg

for security, so that other users can’t see the credentials.

If your cellphone/ directory is not directly under the home directory, configure the directory in cellphone/bin/cellphone-stream.

Run make to build the audio generator program cellphone/bin/cellphone. See the build instructions above for dependencies.

To start streaming, run cellphone/bin/cellphone-stream. You need the darkice audio streamer.

If you made an own user, you can stop streaming with

killall -u cellphone

This terminates all processes running as that user.

You can start streaming automatically on boot by adding to the user’s crontab:

crontab -e
@reboot /home/cellphone/cellphone/bin/cellphone-stream