A little Go program that listens for data on
stdin
, forwards that data via a Web socket, and serves up a little
HTML page that uses the
Web Audio API for rendering the
data as sound.
Usage
Pipe data with lines of the form seriesid frequency duration value
.
Seriesid is an opaque string, which can't contain a space, to
identify a time series. Frequency is in Hertz, duration is in
seconds (a float). Value is an optional float that will be
displayed in a graph on the HTML page.
When a line arrives at listeners' Web pages, the series frequency is
set to frequency for duration seconds. If a value is given,
it'll be displayed on the series graph. Otherwise the frequency is
added to the graph.
Then look at http://localhost:9080/
.
Example
See demo.sh
.
make # (or go generate && go build)
(while true; do
FREQ="$((80 + RANDOM % 400))"
echo a $FREQ 3
sleep 2
FREQ="$((200 + RANDOM % 300))"
echo b $FREQ 0.5
sleep 0.5
FREQ="$((180 + RANDOM % 400))"
Y="$((FREQ/10))"
echo a $FREQ 1 $Y
sleep $(echo "scale=3;1 + $((RANDOM % 4000))/1000.0" | bc -l)
done) | ./soundofdata
# http://localhost:9080/
Notes
- With Firefox, the audio pops some. Doesn't on Chrome. I don't
know what's going on.
- Named pipes make good input
rendezvous points.
- Watch out for
stdio
buffering
with your pipes.