Back in my college days I thought it would improve my chances with the ladies and also make some money by being the DJ at frat parties. But there was a problem. I didn’t have much money to buy equipment. Sound equipment isn’t cheap so I got to thinking. I had a desktop computer, a receiver that could drive 2 speakers and a subwoofer. That was a pretty loud setup for my room but not quite enough to get drunk people at a frat party excited. My friend Don also had a receiver, two speakers and a desktop. Neither of our receivers were powerful enough to drive all the speakers at the same time. So we wondered, what if it were possible to create a program that synchronized the two computers and had them play the same thing at the same time. If we could pull it off we wouldn’t have to buy any extra equipment and we could start playing parties right away!

So we got started writing some code. All we wanted the program to do would be to press play on both desktops at the same moment. There was a catch though. Even though the computers were wired together on a 10/100 switch there was still a small amount of latency between when the person on computer A hit play and when computer B actually got the packet and started playing. We found this out through testing the program. Even a small difference of when the two computers started playing caused a detectable dissonance that was really annoying to listen to. The idea then was so measure how long a packet took to get from computer A to computer B and have computer A wait that amount of time before starting to play. Ok so far so good. We thought we had taken everything into account here and we started testing. It worked pretty well and it was loud as heck! Success right? Well not so fast. There was still a problem that to this day I haven’t been able to figure out. After a certain amount of time, let’s say 2 minutes the one synchronized music started to drift. I would seem to build up and get worse and worse until finally the music sounded horrible and you had to move to the next song. If you take two nearly identical computers running Linux, put them on a switch, shutdown every program they’re running except our program and the music player they would still drift over time.

We ended up doing a few parties and I can’t remember if we made any money but it was a lot of fun. Both the coding and the performance was worth it. I suspect we uncovered something interesting about Linux that neither of us understood at the time.

Fast forward to today. I asked a friend of mine about this problem since he is into audio gear. My theory was that Linux was introducing small interrupts in the sound but we couldn’t detect it until it reached a certain threshold. I was thinking of the same thing where sufficiently fast frames on a screen can’t be seen individually because your mind is averaging them together without your awareness. My friend said that’s not at all what’s going on here. He explained that the cause of audio drift comes from no two computers having identical crystals. The crystals vibrate at slightly different frequencies and this causes audio playing from two computers to drift apart over time. My other friend Morgan came up with an idea of slicing the audio file into smaller 30 second chunks and then introducing a slight delay between each one playing so that the two computers could sync up with one another again. I think that’s a really interesting solution and I feel inspired to rewrite the application in Rust and give this a try.