openAl sound
Re: openAl sound
And if listener moving with some velocity should I account for that?
Re: openAl sound
Ahh not sure how, should I combine velocities somehow?
- Deckhead
- Site Admin
- Posts: 128
- Joined: Fri Feb 21, 2020 5:44 am
- Location: Sydney, Australia
- Contact:
Re: openAl sound
You set the position and velocity of your listener and set the position and velocity of the sources. You set these every frame, independently of the others. That's all you need to do, you don't need to calculate anything else, OpenAL will understand what the distances between the objects are.
Developer of The Last Boundary and webmaster of IndieGameDev.net
Re: openAl sound
Oh so instead of calculation relative position between vehicle player and some car source(where car is relatively to listener) I can just put listener position and source position.
- Deckhead
- Site Admin
- Posts: 128
- Joined: Fri Feb 21, 2020 5:44 am
- Location: Sydney, Australia
- Contact:
Re: openAl sound
Yes, exactly. OpenAL will calculate relative distance between listener and source for you.
Developer of The Last Boundary and webmaster of IndieGameDev.net
Re: openAl sound
I am running into an issue in our vehicle class I ve put ALuint aiSource. In initialization function I ve put:
for (auto vehicle : vehicles)
{
if (vehicle->type == Component::Vehicle::Type::Player) { continue; }
ALuint source;
alCall(alGenSources, 1, &source);
alCall(alSourcef, source, AL_PITCH, 1);
alCall(alSourcef, source, AL_GAIN, volume);
alCall(alSourcei, source, AL_SOURCE_RELATIVE, AL_TRUE);
vehicle -> aiSource = source;
}
then in update function
alCall(alSource3f, vehicle -> aiSource, AL_POSITION, relativePosition.x, relativePosition.y, relativePosition.z);
alCall(alSource3f, vehicle -> aiSource, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
and it keeps telling me AL_INVALID_NAME: a bad name (ID) was passed to an OpenAL function
***ERROR*** (..\..\..\Engine\Systems\soundSystem\SoundSystem.cpp: right on those functions.
for (auto vehicle : vehicles)
{
if (vehicle->type == Component::Vehicle::Type::Player) { continue; }
ALuint source;
alCall(alGenSources, 1, &source);
alCall(alSourcef, source, AL_PITCH, 1);
alCall(alSourcef, source, AL_GAIN, volume);
alCall(alSourcei, source, AL_SOURCE_RELATIVE, AL_TRUE);
vehicle -> aiSource = source;
}
then in update function
alCall(alSource3f, vehicle -> aiSource, AL_POSITION, relativePosition.x, relativePosition.y, relativePosition.z);
alCall(alSource3f, vehicle -> aiSource, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
and it keeps telling me AL_INVALID_NAME: a bad name (ID) was passed to an OpenAL function
***ERROR*** (..\..\..\Engine\Systems\soundSystem\SoundSystem.cpp: right on those functions.
- Deckhead
- Site Admin
- Posts: 128
- Joined: Fri Feb 21, 2020 5:44 am
- Location: Sydney, Australia
- Contact:
Re: openAl sound
AL_INVALID_NAME
only occurs in alSource3f
when the source ALuint
that you're providing is not valid. Looking at your code, I believe you might want to be using an auto&
in your initialisation loop. Otherwise you're assigning values to a copy of a Component::Vehicle
, not the Component::Vehicle
in the container.Developer of The Last Boundary and webmaster of IndieGameDev.net
Re: openAl sound
It's not that It's somehow do not recognize it as source no matter what I do. My last attempt :
in initialization function
and in update we have something like:
in initialization function
Code: Select all
auto vehicles = getEngine()->getSubSystem<EngineStore>()->getRoot().getComponentsOfType<Component::Vehicle>();
for (auto& vehicle : vehicles)
{
if (vehicle->type == Component::Vehicle::Type::Player) { continue; }
vehicle->aiSource = generateSource();
}
Code: Select all
auto vehicles = getEngine()->getSubSystem<EngineStore>()->getRoot().getComponentsOfType<Component::Vehicle>();
glm::vec3 playerPosition;
for (auto vehicle : vehicles)
{
if (vehicle->type == Component::Vehicle::Type::Player)
{
playerPosition = vehicle->position;
}
}
for (auto& vehicle : vehicles)
{
if (!vehicle->pxVehicle)
continue;
if (vehicle->type == Component::Vehicle::Type::Player) { continue; }
bool currentAcceleration;
bool currentBreaking;
glm::vec3 relativePosition = vehicle->position - playerPosition;
auto velocity = vehicle->pxVehicle->getRigidDynamicActor()->getLinearVelocity();
alCall(alSource3f, vehicle->aiSource, AL_POSITION, relativePosition.x, relativePosition.y, relativePosition.z);
alCall(alSource3f, vehicle->aiSource, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
if (vehicle->pxVehicleInputData.getAnalogAccel() == 1)
{
currentAcceleration = true;
if (currentAcceleration != vehicle->initialAccelerate)
{
alCall(alSourcei, vehicle->aiSource, AL_LOOPING, AL_TRUE);
alCall(alSourcei, vehicle ->aiSource, AL_BUFFER, accelerationBuffer);
playSound(vehicle ->aiSource);
vehicle->initialAccelerate = true;
}
}
if (vehicle->pxVehicleInputData.getAnalogAccel() == 0)
{
currentAcceleration = false;
if (currentAcceleration != vehicle->initialAccelerate)
{
stopSound(vehicle->aiSource);
vehicle->initialAccelerate = false;
}
}
if (vehicle->pxVehicleInputData.getAnalogBrake() == 1)
{
currentBreaking = true;
if (currentBreaking != vehicle->initialBreak)
{
alCall(alSourcei, vehicle->aiSource, AL_LOOPING, AL_FALSE);
alCall(alSourcei, vehicle->aiSource, AL_BUFFER, breakingBuffer);
playSound(vehicle->aiSource);
vehicle->initialBreak = true;
}
}
if (vehicle->pxVehicleInputData.getAnalogBrake() == 0)
{
currentBreaking = false;
if (currentBreaking != vehicle->initialBreak)
{
stopSound(vehicle->aiSource);
vehicle->initialBreak = false;
}
}
}
}
- Deckhead
- Site Admin
- Posts: 128
- Joined: Fri Feb 21, 2020 5:44 am
- Location: Sydney, Australia
- Contact:
Re: openAl sound
Well, it's hard to say without seeing all of your code in it's entirety. I can see that you are dereferencing the vehicles so they're likely pointers to the actual vehicles, in which case your code looks like it should work.
If you're getting that
It may seem silly, but the idea is to be 100% certain that the initialisation that you think is occurring is definitely occurring. You should get a bunch of that message output in your console window and should see a bunch of sequentially numbered sources (usually you'll see from OpenALSoft that the first source is the value
If you're getting that
AL_INVALID_NAME
error on the alSource3f
calls, the only way that can happen is with an invalid source. So with that in mind, have you tried doing something as simple as this:Code: Select all
auto vehicles = getEngine()->getSubSystem<EngineStore>()->getRoot().getComponentsOfType<Component::Vehicle>();
for (auto& vehicle : vehicles)
{
if (vehicle->type == Component::Vehicle::Type::Player) { continue; }
vehicle->aiSource = generateSource();
std::cout << "vehicle al source created: " << vehicle->aiSource << std::endl;
}
1
and then the next created is 2
etc etc).Developer of The Last Boundary and webmaster of IndieGameDev.net