Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AudioStreamPlayer3D volume calculation for multiple viewports #94613

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kus04e4ek
Copy link
Contributor

@kus04e4ek kus04e4ek commented Jul 22, 2024

Went with a different solution from #76713, cause the position of the listener is important to compute the volume, so just adding MAX wouldn't work.

Not quite sure if the solution I came up with is correct: always pick the listener with the biggest db_att and if there are multiple ones with the biggest db_att choose the one with the biggest multiplier among them. The biggest db_att is preferred to account for the emission angle, if the emission angle doesn't affect anything (listeners that are being compared are both out of the emission angle, they are both in the emission angle or there's no emission angle) or it affects only a little bit it basically chooses the closest listener. When comparing multiplier it just chooses the closest listener. There might be some edge cases when this doen't work (I think db_att might have less effect than multiplier depending on the sound being played, so multiplier should be preffered over db_att, I'm unsure how to fix something like this and if it's even possible to know for sure that this particular sound will cause issues).

Fixes the comment style in AudioStreamPlayer3D::_update_panning (as this PR only changes AudioStreamPlayer3D::_update_panning)

@kus04e4ek kus04e4ek requested a review from a team as a code owner July 22, 2024 09:10
@kus04e4ek kus04e4ek changed the title Fix AudioStreamPlayer3D calculation for multiple viewports Fix AudioStreamPlayer3D volume calculation for multiple viewports Jul 22, 2024
@AThousandShips AThousandShips added bug topic:audio topic:3d cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Jul 22, 2024
@AThousandShips AThousandShips added this to the 4.4 milestone Jul 22, 2024
@@ -359,6 +359,13 @@ Vector<AudioFrame> AudioStreamPlayer3D::_update_panning() {
cameras.insert(get_viewport()->get_camera_3d());

PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world_3d->get_space());
Area3D *area = _get_overriding_area();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved here to avoid calling _get_overriding_area every loop iteration as it stays the same

@olsongleb
Copy link

@kus04e4ek I also want to ask about Audio Stream Player 3D. Sorry if this is off topic, but I asked in thematic communities and didn’t find an answer.
Is it possible in the future updates to provide the ability to output audio to other playback devices for different subviewports? so that the sound setting for the main window/viewport would be done via AudioServer.set_output_device(), but the sound for the subviewport with the audio_listener_enable_3d option so that it can be assigned to the same device as the main one, or to another one. Initially I was looking for an answer to this exact question, then I noticed that the sound was not playing, and wrote about it here. and thanks for this correction.

If this possibility already exists, please let me know.
Why this is needed: It would be possible to provide the ability to output audio to different output devices for different players in split-screen mode depending on the position of their cameras.

@kus04e4ek
Copy link
Contributor Author

I asked in thematic communities and didn’t find an answer.

You can also ask in the contributors chat, it's not really a place to ask general questions, but if no one gives you an an answer on the forum, you can ask there.

Is it possible in the future updates to provide the ability to output audio to other playback devices for different subviewports?

It should be possible on most platforms, currently Android, iOS and Web have no way to set the different device though.

If this possibility already exists, please let me know.

Currently Godot doesn't provide functionality to use multiple audio devices at the same time.

As it's currently not supported you should open a proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release topic:audio topic:3d
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audio only plays on one viewport (3D)
3 participants