Hello guys, I’m creating a small two-dimensional audio game, and I’m using the setPosition function to create a more real soundstage.
Something that I still cannot solve is taking into account the x and y position of the character and the other elements of the stage, how to calculate that distance with respect to the audio.
I was thinking about taking out the module and the angle between the two coordinates, and passing those values to the SetPosition function of the angle and distance respectively.
what do you think?
is there a way to do it better?
Thanks so much for reading.
Hello and welcome to the forum.
Out of curiosity, what audio library are you using for handling the audio? Are you using the one built-in into SDL or some external library like SDL_Mixer etc?
Are you trying to create a game similar to Bit Trip Runner, where the gameplay are synced with the background music and sounds?
If you’re trying to have positional audio, then use something like OpenAL. @icculus created a simple OpenAL implementation called MojoAL that only requires one C file (plus the OpenAL headers) so you can easily add it to your project.
Thanks for replying, I am using sdl mixer 2.6.3 with setPosition function.
I don’t know the game you mention, my idea is to create a small game that people can play without the need for images, that is why positional audio is so important.
Thanks mate for the suggestion, but I’m in the same situation, how to calculate the distance and orientation?
I think there must be some formula to do it, but with open al everything becomes much more complex.
OpenAL does it for you. You set the position and orientation of the listener, and the position and orientation of the sound sources. It does the rest.
If you really want to do it yourself, you could always look at the MojoAL source code I linked earlier. Or look at the custom mixer that phoboslab wrote for his Wipeout rewrite (look at the function
Ultimately, just use some method of fading out the samples the further away the source is; it doesn’t have to be physically correct so long as it sounds the way you want.