#!/bin/sh # ShellBeat: a Busybox-compatible Bytebeat player with purely shell arithmetic syntax # depends on xxd only # By default, SoX is also required, or change the PLAYCMD variable to your engine # (see some commented examples, some of them only accept 8Khz sample rate) # Usage: shellbeat.sh 'formula'[ samplerate=8000] # Example test on "42 melody": sh shellbeat.sh 't * (42 & (t >> 10))' # Created in 2023 by Luxferre, released into public domain FORMULA="$1" SAMPLERATE="$2" [ -z "$FORMULA" ] && printf 'No formula!\n' && exit [ -z "$SAMPLERATE" ] && SAMPLERATE=8000 PLAYCMD="play -q -tu8 -r${SAMPLERATE} -c1 -" # most universal option with SoX play command # or else uncomment one of these if you don't have SoX: #PLAYCMD="tee /dev/dsp" # if you have bare OSS (only 8KHz input) #PLAYCMD="aplay -q -f U8 -r ${SAMPLERATE}" # if you have ALSA #PLAYCMD="pacat --raw --format=u8 --rate=${SAMPLERATE} --channels=1" # if you have PulseAudio #PLAYCMD="pw-play --format=u8 --rate=${SAMPLERATE} --channels=1 -" # if you have PipeWire printf 'ShellBeat by Luxferre\nPlaying formula: %s\nSample rate: %d Hz\n' "$FORMULA" "$SAMPLERATE" (t=0; while true; do printf '%02X\n' "$((255&(${FORMULA})))"; t=$((t+1)); done) | xxd -r -p | $PLAYCMD > /dev/null