Trippr audio programming: Binaural beats (part 1)

December 8, 2018 - Jos van Tol

The initial idea to create an interactive binaural beats synthesizer dates back to about a year ago when I started talking to artist Seán Hannan. He asked me to write a hip hop inspired soundtrack for his upcoming artwork in New York city. It would be conspiracy themed and I remembered there were some conspiracies floating around about the US government influencing it's citizens brainwaves through their TV sets using binaural beats.

Actually I already used this effect back in 2013 when I was writing/programming the album Triumph Without Euphoria. It is the basis for every track on there.

If you would like to know more about this audio phenomenon and it's sound, you can check out this seminal article by Gerald Oster; Auditory Beats in the Brain (Scientific American, 1973)

What are these binaural beats?

I wrote my first version of the algorithm in Max. It basically generates two sine waves, one per channel, with a slight difference in frequency. There are two parameters, the frequency of the average tone and the difference between the left and right channel. Max being a real-time environment developed for live performers makes it pretty easy to implement this as a live synthesis. But it was far from portable. Max is a heavy and proprietary environment and you have to bring your expensive MacBook to let anyone hear your music. Not really a good fit for creating, let's say, a mobile app.

Digital audio basics.

Digital audio stands on three legs. Sampling rate, bit depth and channels. It uses these to translate a analog signal into a stream of values. (Or the other way around) The amount of values is the sampling rate.  The type of values is the bit depth. There is a channel per stream. In this case two, left and right, stereo.

The sampling rate is since the introduction of the CD standardised at 44,100 samples per second. Or 44.1 kHz. If this value doesn't tell how fast computers have become than this will: every sample can have a value of 16-bits. That means from -32,768 to 32,767. A crazy amount of resolution. This gives a quick look at the data we will have to deal with. The reason we need this fidelity is because our ears are very sensitive to any glitch or bump in the audio signal. We can hear every digital pin drop.

Since audio chips and files need their data in a one-dimensional array both channels are interlaced in the stream. L-R-L-R-L-... and so on. So in conclusion, our digital synthesizer will have to deal with 44,100 x 16 x 2 = 1,411,200 bits = 176,400 bytes per second (Nothing compared to 475 MB per second for 1080p video streams, but that has a lot more complications involved)

Push power button to start computer.

I started with a small offline command-line tool that exported a sample with binaural beats. I had lots of fun implementing the medieval WAV-file header. The command accepted the arguments on the command line and spitted out a WAV file. I used these on the album for Seán Hannan; When The Iron Bird Flies And Horses Run On Wheels.

In part 2 I will go in further and explain the code behind the synth. And how I implemented the algorithms that create the audio streams in real-time... We'll talk buffers!