[phpBB Debug] PHP Warning: in file [ROOT]/ext/alfredoramos/seometadata/event/listener.php on line 126: Trying to access array offset on value of type null
IndieGameDev.net Forums • openAl sound - Page 2
Page 2 of 4

Re: openAl sound

Posted: Tue Apr 07, 2020 4:47 am
by Mckl
Hey it's me again. Now we want to make sounds from other cars(non players one) in our game. I am thinking to load each car with acceleration breaking and collision source sound like the one I made for players car and change and for each car volume based on distance from player car like the further the car the lesser the sound. Is it a good way or there is better way to do this?

Re: openAl sound

Posted: Wed Apr 08, 2020 8:51 am
by Deckhead
Mckl wrote: Tue Apr 07, 2020 4:47 am Hey it's me again. Now we want to make sounds from other cars(non players one) in our game. I am thinking to load each car with acceleration breaking and collision source sound like the one I made for players car and change and for each car volume based on distance from player car like the further the car the lesser the sound. Is it a good way or there is better way to do this?
It's fine for simple things, like a 2D game. You can basically say something like:
  • After 200 units, you can't hear a car. So this is how far away a car fades into silence. In this case, "units" could be pixels.
  • Calculate a distance vector between the player pos and the car you're playing a sound for.
  • Lerp the volume of the car based on how far away it is
  • Every frame, update the gain of the source based on your above lerping, so you'll need to calculate it every frame
Of course, there is also positioning audio sources options in OpenAL. That's the next guide for me to write, but you can have a go at that yourself if you look into the specification I linked to in the first guide.

Re: openAl sound

Posted: Thu Apr 09, 2020 12:40 am
by Mckl
I think what if we put source into class definition of the vehicle So each vehicle has it's source, make 3 buffers for acceleration breaking and collisions. Then in sound system go through list of vehicles and check if it's breaking accelerating and colliding it's position and velocity. and update each source accordingly.

Re: openAl sound

Posted: Thu Apr 09, 2020 1:41 am
by Mckl
And by the way what is AL_PITCH is?

Re: openAl sound

Posted: Fri Apr 10, 2020 12:21 am
by Deckhead
Mckl wrote: Thu Apr 09, 2020 1:41 am And by the way what is AL_PITCH is?
Changes the pitch of the original sound. Helpful for car engines, as you sort of rev the engine, you can modify the pitch to simulate faster revs.

Re: openAl sound

Posted: Fri Apr 10, 2020 10:25 am
by Mckl
So what do you think is it good way of doing that to make 3d sound? Or is the way to make 3d sound for bunch of cars just using one source?

Re: openAl sound

Posted: Sat Apr 11, 2020 7:35 am
by Deckhead
Well, for 3D sound, you can look into the positioning parts for the source. So each car is it's own source, and the source is positioned at different places.

That's really the best way to handle it. I will eventually write the next article to cover positioning.

Re: openAl sound

Posted: Sun Apr 12, 2020 3:51 am
by Deckhead

Re: openAl sound

Posted: Sun Apr 12, 2020 10:48 pm
by Mckl
I know I am a little bit ahead on your articles. I am wondering what I should look for when I am making audio sources move?

Re: openAl sound

Posted: Mon Apr 13, 2020 12:04 pm
by Deckhead
There's a velocity vector for sources just like the position vector. If you set the position and velocity every frame to match the objects position and velocity, it will give you good results.