Non-Apophantic Sounds & Silences

Compositions for infinite sox bash loops.

handsandnumbers 2026

Instructions

Step 1. Install SoX

sudo apt install sox

Step 2. Play the composition.

  1. Copy the code available below:
  2. Paste it into the Terminal
  3. Hit Enter to start the composition
  4. Ctrl + C to stop it

na-001

Composition for infinite sox bash loops.

set +m
stop=""
trap 'stop=1; kill $(jobs -p) 2>/dev/null' INT TERM QUIT
silence_pct=25
min_gap=350
min_silence=900
note_name() { awk -v m="$1" 'BEGIN{n=split("C C# D D# E F F# G G# A A# B",a," "); printf "%s%d", a[(m-12)%12+1], int((m-12)/12)}'; }
new_tonic() { echo $(( 33 + RANDOM % 13 )); }
# gaussian-weighted degree pick: weight = exp(-d^2 / 2*sig^2), d = semitones to nearest triad tone {0,3,7}
pick_deg() { awk -v u=$RANDOM 'BEGIN{
  split("0 2 3 5 7 8 11", s, " "); split("0 3 7", tr, " "); sig=1.2; tw=0
  for (i=1;i<=7;i++){ d=99; for (j=1;j<=3;j++){ dd=s[i]-tr[j]; if (dd<0) dd=-dd; if (dd<d) d=dd } w[i]=exp(-(d*d)/(2*sig*sig)); tw+=w[i] }
  uu=u/32768.0*tw; acc=0
  for (i=1;i<=7;i++){ acc+=w[i]; if (uu<=acc){ print s[i]; exit } }
  print 7 }'; }

while [ -z "$stop" ]; do
  T=$(( 180 + RANDOM % 421 ))
  t0=${EPOCHREALTIME:-$(date +%s.%N)}
  tonic=$(new_tonic); kphase=0
  echo "composition loop: ${T}s starting in $(note_name $tonic) harmonic minor" >&2
  while [ -z "$stop" ]; do
    now=${EPOCHREALTIME:-$(date +%s.%N)}
    # env: tri loudness envelope over the whole composition loop: 0 -> 0.8 across first 80%, 0.8 -> 0 across last 20%
    read t_ms b60 b80 T_ms env <<< $(awk -v n=$now -v s=$t0 -v T=$T 'BEGIN{t=(n-s)*1000; b80=int(0.8*T*1000); Tms=T*1000; if (t<=b80) e=0.8*t/b80; else e=0.8*(Tms-t)/(Tms-b80); if (e<0) e=0; printf "%d %d %d %d %.3f", t, int(0.6*T*1000), b80, Tms, e}')
    [ $t_ms -ge $T_ms ] && break
    if [ $t_ms -ge $b80 ] && [ $kphase -lt 2 ]; then tonic=$(new_tonic); kphase=2; echo "  t=${t_ms}ms (80%): modulate -> $(note_name $tonic) hm" >&2
    elif [ $t_ms -ge $b60 ] && [ $kphase -lt 1 ]; then tonic=$(new_tonic); kphase=1; echo "  t=${t_ms}ms (60%): modulate -> $(note_name $tonic) hm" >&2
    fi
    read r int_ms <<< $(awk -v t=$t_ms -v b80=$b80 -v T=$T_ms -v u=$RANDOM 'BEGIN{ if (t<=b80) r=0.5+3.5*t/b80; else r=4-3.5*(t-b80)/(T-b80); if (r<0.5) r=0.5; uu=u/32768.0; if (uu<0.001) uu=0.001; printf "%.4f %d", r, int(-log(uu)/r*1000.0) }')
    [ $int_ms -lt $min_gap ] && int_ms=$min_gap
    if [ $(( RANDOM % 100 )) -lt $silence_pct ]; then
      gap_ms=$(( int_ms * (2 + RANDOM % 3) ))
      [ $gap_ms -lt $min_silence ] && gap_ms=$min_silence
      echo "  t=${t_ms}ms rate=${r}/s silence gap=${gap_ms}ms" >&2
    else
      gap_ms=$int_ms
      thz=$(awk -v m=$tonic 'BEGIN{printf "%.2f", 440*2^((m-69)/12)}')
      semi=$(( (RANDOM % 2)*12 + $(pick_deg) ))
      b=$(awk -v t=$thz -v s=$semi 'BEGIN{printf "%d", t*2^(s/12)}')
      # pluck amp: two-band split -> 60% uniform in [0.7,1] (loud), 40% uniform in [0.2,0.69] (genuinely quiet)
      amp=$(awk -v u=$RANDOM 'BEGIN{ uu=u/32768.0; if (uu<0.6) a=0.7+0.3*(uu/0.6); else a=0.2+0.49*((uu-0.6)/0.4); printf "%.3f", a }')
      p_ms=$(awk -v r=$r -v u=$RANDOM 'BEGIN{ x=9000-700*r; if (x<4000) x=4000; if (x>9000) x=9000; x+=int(u/32768.0*200); printf "%d", x }')
      p=$p_ms
      ps="$((p/1000)).$(printf '%03d' $((p%1000)))"
      # tri wave: starts d seconds after the pluck, swells in/out over ~35% of the ring each way
      d=$(awk -v u=$RANDOM 'BEGIN{printf "%.2f", 0.3+u/32768.0*0.5}')
      fi=$(awk -v p=$ps 'BEGIN{printf "%.2f", p*0.35}')
      # tri interval: random octave up (2x), minor third (6/5x) or fifth (3/2x) of b
      case $(( RANDOM % 3 )) in 0) mult=200;; 1) mult=120;; 2) mult=150;; esac
      tf=$(awk -v b=$b -v m=$mult 'BEGIN{printf "%.2f", b*m/100}')
      # tri volume = per-note gaussian amp * composition-wide envelope env (0->0.8->0)
      tamp=$(awk -v a=$amp -v e=$env 'BEGIN{printf "%.3f", a*e}')
      # headroom: per-note peaks are normalized low (-12 pluck / -20 tri) so the sum of many
      # overlapping reverb tails at high density stays below 0 dBFS in pacat -> no clipping
      # pluck stream starts FIRST and gets a 0.2s head start, so its pacat is connected and its
      # attack buffer is filled before the tri's sox starts competing for CPU (protects the attack)
      sox -r 44100 -c 3 -n -t raw -r 44100 -e signed-integer -b 16 -c 2 - \
          synth "$ps" pluck "$b" pluck "$((b*600/100))" pluck "$((b*900/100))" \
          remix 1,2v0.4,3v0.2 1,2v0.4,3v0.2 gain -8 \
          reverb 90 50 100 100 fade t 0 "$ps" 1 gain -n -12 vol $amp \
        | pacat --playback --format=s16le --rate=44100 --channels=2 --latency-msec=250 &
      sleep 0.2
      # tri stream is mono (pulse duplicates it to both speakers) - half the CPU of the stereo version
      sox -r 44100 -n -t raw -r 44100 -e signed-integer -b 16 -c 1 - \
          synth "$ps" tri "$tf" delay "$d" \
          fade t "$fi" "$ps" "$fi" gain -8 \
          reverb 90 50 100 100 gain -n -20 vol $tamp \
        | pacat --playback --format=s16le --rate=44100 --channels=1 --latency-msec=250 &
      sleep 0.2
      echo "  t=${t_ms}ms rate=${r}/s bell b=$b semi=$semi key=$(note_name $tonic) amp=$amp tri=$tf(${mult}%) env=$env tamp=$tamp d=$d fi=$fi gap=${gap_ms}ms" >&2
    fi
    sleep $(awk -v ms=$gap_ms 'BEGIN{printf "%d.%03d", ms/1000, ms%1000}')
  done
done
kill $(jobs -p) 2>/dev/null
na-001 image

Copy the code above into your Terminal and press Enter.