8D Audio In Python

RaghavaKV
4 min readApr 16, 2021

Panning and Pygame….

Photo by Alexey Ruban on Unsplash

Let me start with a harsh truth, ‘There is no such thing called 8D Audio.In fact sound does not have any dimension at all’. But one should also consider the fact that the humans are conferred with a powerful analytic engine known as Brain.This three-pound organ is the seat of intelligence, interpreter of the senses, initiator of body movement, and controller of behavior. It can process various degree of signals that are received from the senses.The human brain interprets the incoming sounds from ears in three dimensions, the same dimensions that are inhabited in our day to day to life namely, Height, Width and Length. The human brain can distinguish between the sound that emerges from rear and the sound that is from front ,this is the exact idea on which the 8D Audio is based on . But how does the human brain figure out the direction of the sound. To know more one should know the basics of the Audio Mastering Techniques.

“There is no such thing called 8D Audio.In fact sound does not have any dimension at all”

Artists and Singers uses many techniques to enrich the experience of the listeners, the basic techniques are Echo,Reverb and Delay,(of course they are many other techniques like EQ, Imaging ). Generally, Reverb is basically echo except the distance between the echoes is exponentially smaller and there are exponentially more instances of the echo.This results in a realistic audio. Delay is an audio effect often called an echo and sometimes confused with reverb. Delay is a lag that postpones the audio signal from playing for a number of milliseconds based on the tempo of the song.It is not useful by itself but when combined with other techniques it can make sound more realistic. Panning is achieved by decreasing the sound from one of the speaker and increasing in the other. It can be mastered with Echo, Reverb and Delay to make the audio more lively. All these technique are the cues for the human brain to determine the direction of the sound also height,width and length.Panning is the technique which is used extensively in 8D Audio Creation.

Now the idea is very clear, it’s time to implement them in Python. Pygame is the dedicated module for developing games, it has a wide range of functionalities from collision detection to handle user inputs like key press and mouse events. There is something called pygame.mixer. It takes care of all the audio of that are used in the game, the documentation can be found here. Pygame. mixer deals with audio using two main objects called Sound and Music, even though they sound similar, each has a different purpose. Music object is a stream that is not loaded at once and seek-able, where as Sound object is loaded once and is non seek-able. Most importantly, when the Music object is used there is no concept of channel at all. Channel is an object which controls the playback of the sound that is being played.By default there are 16 channels. This channel object has a method set_volume(),which takes a float value between 0 and 1. this method sets the loudness of the playing sound.If one argument is passed, it will be the volume of both speakers. If two arguments are passed and the mixer is in stereo mode, the first argument will be the volume of the left speaker and the second will be the volume of the right speaker.Just like Sound object,Channel object also has all methods like pause(),play(),mute()etc.

channel = pygame.mixer.find_channel()#Getting a Free Channel
channel.set_volume(1.0,0.0)#1.0 volume for left and 0.0 for right
channel.set_volume(0.5)#Volume for both speakers is set to 0.5
channel.play(pygame.mixer.Sound('Sample.mp3'))

Now, it is important to note that whenever the volume is changed using channel.set_volume(), the change is reflected immediately in the playback. So in order to create the 8D illusion, one should just manipulate the values of left and right, the idea is to make complement of each other.Say if right is 0.6 then left value will be 0.4 and vice-versa, thus creating the Panning effect.

This idea is implemented with GUI, named as PyEuphony, can found here.

PyEuphony

--

--

RaghavaKV

Trying to master JavaScript among other things...