openAl sound

There's only need for one forum for now. Discuss development. No advertising or thinly veiled attempts at advertising. Create a single thread for your project and be prepared to show and tell.
Mckl
Posts: 20
Joined: Wed Mar 04, 2020 12:09 am

Re: openAl sound

Post 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?
User avatar
Deckhead
Site Admin
Posts: 128
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: openAl sound

Post 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.
Developer of The Last Boundary and webmaster of IndieGameDev.net
Mckl
Posts: 20
Joined: Wed Mar 04, 2020 12:09 am

Re: openAl sound

Post 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.
Mckl
Posts: 20
Joined: Wed Mar 04, 2020 12:09 am

Re: openAl sound

Post by Mckl »

And by the way what is AL_PITCH is?
User avatar
Deckhead
Site Admin
Posts: 128
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: openAl sound

Post 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.
Developer of The Last Boundary and webmaster of IndieGameDev.net
Mckl
Posts: 20
Joined: Wed Mar 04, 2020 12:09 am

Re: openAl sound

Post 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?
User avatar
Deckhead
Site Admin
Posts: 128
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: openAl sound

Post 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.
Developer of The Last Boundary and webmaster of IndieGameDev.net
User avatar
Deckhead
Site Admin
Posts: 128
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: openAl sound

Post by Deckhead »

Developer of The Last Boundary and webmaster of IndieGameDev.net
Mckl
Posts: 20
Joined: Wed Mar 04, 2020 12:09 am

Re: openAl sound

Post 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?
User avatar
Deckhead
Site Admin
Posts: 128
Joined: Fri Feb 21, 2020 5:44 am
Location: Sydney, Australia
Contact:

Re: openAl sound

Post 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.
Developer of The Last Boundary and webmaster of IndieGameDev.net
Post Reply