sure! basically what iām doing is running jack_capture from the Go program running on the norns. jack_capture does the hard part of streaming the audio from jack. i just run it in the background, using this command run from the temp dir (/dev/shm):
> jack_capture -f flac --port system:playback_1 --port system:playback_2 --recording-time 36000 -Rf 96000 -z 4
basically it captures all output and routes it to a file. the -Rf 96000 means that it will create a new file every 96000 samples (at 48k, thatās 2 seconds). the Go program senses the newly made file, reads it and then deletes it (important! so you donāt run out of memory). then the Go program takes the data and converts it to base64 and sends it through the websocket as a string (relevant lines of code):
// b = bytes from reading file
mp3data := base64.StdEncoding.EncodeToString(b)
n.ws.WriteJSON(Message{
MP3: mp3data,
})
browsers are amazingly smart now so you can simply use this javascript function to play base64 encoded audio data:
currentPlayingFinished = 0;
function playMP3(mp3data) {
audioCtx.decodeAudioData(base64ToArrayBuffer(mp3data), function(buffer) {
console.log(buffer);
// Get an AudioBufferSourceNode.
// This is the AudioNode to use when we want to play an AudioBuffer
var source = audioCtx.createBufferSource();
// set the buffer in the AudioBufferSourceNode
source.buffer = buffer;
// connect the AudioBufferSourceNode to the
// destination so we can hear the sound
source.connect(audioCtx.destination);
// start the source playing
console.log(currentPlayingFinished);
if (currentPlayingFinished <= audioCtx.currentTime) {
currentPlayingFinished = audioCtx.currentTime + 1
}
source.start(currentPlayingFinished);
currentPlayingFinished = currentPlayingFinished + buffer.duration;
})
}
that code will automatically buffer by 1 second. the decodeAudioData is part of the web audio api and it automatically detects wav/mp3/flac!
incepted norns! basically norns.online extends the norns to the internet so you can play it / hear it from a browser. like teamviewer but for norns. of course, its not practical for replacing the physical interface. but the website-based interface can be useful for other things - like streaming to multiple computers (w/o twitch!), having someone remote control your norns for fun/education, or experimentation with crowdsourced music, or ?!??!