Roger B. Dannenberg

Home Publications Videos Opera Audacity
Dannenberg playing trumpet.
Photo by Alisa.

Using O2host as an OSC Relay


Summary

O2host provides a simple way to connect browsers and microcontrollers to OSC, MIDI, and other browsers and microcontrollers. This installment shows how the o2host program can be used to send OSC around the globe.

About the Author

Roger B. Dannenberg is Emeritus Professor of Computer Science at Carnegie Mellon University and a Fellow of the Association for Computing Machinery. He is known for a broad range of research in Computer Music, including the creation of interactive computer accompaniment systems, languages for computer music, music understanding systems, and music composing software. He is a co-creator of Audacity, perhaps the most widely used music editing software.

Additional References

O2 source code is open and free.

A video prepared for ICMC 2022 demonstrates location independence and discovery features of O2.

Building Music Systems with O2 and O2lite is an introduction to O2.

Using O2host with O2lite and MicroPython is the first article in this series on o2host.

Articles on O2 are listed in my bibliography.

Continuing our discussion of the o2host program, one application is to serve as a relay, taking advantage of O2’s ability to form connections from anywhere to anywhere, even globally and through home routers with firewalls. Of course, if you are sending O2 messages from point A to point B, O2 can already do that, so a potentially interesting case is: What if I want to send OSC messages reliably from A to B? What if I want to connect to a host using NAT (Net Address Translation, where ports within the local network are not accessible from the public network)?

We have done some work with Soundcool controlled by remote participants over OSC. The participants all use a phone running the Soundcool App to send OSC over UDP to the Soundcool computer. Then, we use a group video call over Zoom or Microsoft Teams to share the Soundcool control interface and sound with all the participants.

This practice requires the network to allow UDP messages though its firewall, and this typically means manually configuring a home router to “open” some port numbers, which would otherwise be filtered. In practice, transcontinental connections drop a lot of OSC messages, so it may be necessary to change a variable control slowly or wiggle it, causing it to send multiple messages, knowing that at least some will get through. On/off controls are risky because you never know if a single message will get through.

O2host to the Rescue

With a couple of o2host programs, one at the sender’s computer and one at the receiver’s, we can turn local OSC messages (pretty reliable) into O2 for the long-haul transmission (done reliably over TCP) and back into OSC for a short hop to the destination computer (which could be the same computer running the application, thus nearly lossless).

Let’s see how this works with Soundcool. Figure 1 shows the configuration we want. We will send OSC from a Soundcool App to a remote computer running Soundcool.

Figure 1. Forwarding OSC messages over O2.

Configuring the Sender

On the sender side, we are going to receive OSC messages via Wi-Fi from the Soundcool App (available at Apple Store and Google Play Store) and forward them to the remote o2host, so let’s use screlay as the ensemble name, receive on port 8080 and send to service soundcool. We will set networking to wide-area discovery to give us the ability to connect anywhere. (Note that your work might conflict with anyone else using the same ensemble name, so if you enable wide-area-discovery, you should use a unique ensemble name instead of screlay.) Here's what the screen will look like:

Navigate with the TAB key to the Rename to: field and type screlay for the configuration name; then, in the Save_ field, type "x" to save the configuration.

Configuring the Receiver

On the receiver side, we want to forward O2 to OSC, forwarding service soundcool to localhost (127.0.0.1) port 8081. Here's what the screen will look like:

As before, use Rename to: to enter the configuration name (use screlayrecv this time) and Save_ to save it.

Configuring Soundcool

We will need something in Soundcool to control, so let’s make a simple patch with a controllable SignalGen module. (You can get Soundcool free here.) Notice the port specification on SignalGen is 8081 to match the OSC port to which o2host will forward incoming O2 messages:

Local Test

Start the Soundcool App on your phone or tablet. Enter the IP address of your laptop and Port 8080. Tap the Audio button and select the Player/Effect control. Now you can send OSC messages from phone to laptop.

On the laptop, start a terminal or cmd window and run o2host. Select the screlay configuration and type "x" in the Load_ field to install the configuration. You might want to set Debug flags: to rs to view the received and sent messages. Then type the ESC to start O2.

Open another terminal or cmd window and run another instance of o2host. This will be the receiver, so select the screlayrecv configuration and type "x" in the Load_ field to install the configuration. You might want to set Debug flags: to rs to view the received and sent messages. Then type the ESC to start O2.

Returning to the Soundcool App, when you change controls, OSC messages should be received by the first o2host, relayed via O2 to the second o2host, converted back to OSC and delivered to Soundcool. You should be able to control the SignalGen module there to make sound.

Global Testing

This should work globally as well as locally. Just run the screlay o2host configuration on the same local area network as the Soundcool App. And run the screlayrecv o2host configuration on the same machine as Soundcool so that OSC messages send to “localhost” (127.0.0.1) will find Soundcool. O2 will take care of connecting the two o2hosts.

Here is a video of the system in operation:


Bi-directional connections should be possible too! Just make a second service, e.g. soundcool2, pick some different OSC ports and extend the configurations to forward in the reverse direction.

Summary

This post shows how you can use the o2host program to send OSC messages anywhere in the world. Even if the receiver is behind a firewall that blocks direct OSC over UDP messages, O2 will get through via an MQTT server. This will be some additional speed-of-light delay routing through the MQTT server, but the setup is simple and the transmission is lossless, which is not the case for direct OSC over UDP.

In the last 4 posts, I have described various applications of o2host supporting intercommunication between microcontrollers, web browsers and distant computers. I hope this approach to modular networked music systems will inspire and enable lots of interesting and creative work. Let me know if you find it useful or need help.

Additional references appear in the left sidebar (scroll up).