Skip to content

Conversation

@rh101
Copy link
Contributor

@rh101 rh101 commented Sep 12, 2025

Describe your changes

Add support for audio panning relative to the listener, from left to right, -60° to +60°.

Issue ticket number and link

Checklist before requesting a review

For each PR

  • Add Copyright if it missed:
    - "Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md)."

  • I have performed a self-review of my code.

    Optional:

    • I have checked readme and add important infos to this PR.
    • I have added/adapted some tests too.

For core/new feature PR

  • I have checked readme and add important infos to this PR.
  • I have added thorough tests.

Axmol 3.x ------------------------------------------------------------

For each 3.x PR

  • Check the '#include "axmol.h"' and replace it with the needed headers.

@halx99
Copy link
Collaborator

halx99 commented Sep 12, 2025

will your also add 3d API: int AudioEngine::play3d(const std::string& filePath, const Vec3& position, bool loop = false, float volume = 1.0f, const AudioProfile* profile = nullptr); ?

@halx99
Copy link
Collaborator

halx99 commented Sep 12, 2025

will your also add 3d API: int AudioEngine::play3d(const std::string& filePath, const Vec3& position, bool loop = false, float volume = 1.0f, const AudioProfile* profile = nullptr); ?

never mind, the audio panning still for 2d, right?

@rh101
Copy link
Contributor Author

rh101 commented Sep 12, 2025

will your also add 3d API: int AudioEngine::play3d(const std::string& filePath, const Vec3& position, bool loop = false, float volume = 1.0f, const AudioProfile* profile = nullptr); ?

never mind, the audio panning still for 2d, right?

This implementation is only for 2D. Do you want me to try and add 3D panning to this PR?

@halx99
Copy link
Collaborator

halx99 commented Sep 12, 2025

will your also add 3d API: int AudioEngine::play3d(const std::string& filePath, const Vec3& position, bool loop = false, float volume = 1.0f, const AudioProfile* profile = nullptr); ?

will your also add 3d API: int AudioEngine::play3d(const std::string& filePath, const Vec3& position, bool loop = false, float volume = 1.0f, const AudioProfile* profile = nullptr); ?

never mind, the audio panning still for 2d, right?

This implementation is only for 2D. Do you want me to try and add 3D panning to this PR?

Maybe a separated PR is better due to current only have play2d API

@halx99 halx99 added this to the 2.8.2 milestone Sep 12, 2025
@rh101
Copy link
Contributor Author

rh101 commented Sep 12, 2025

Maybe a separated PR is better due to current only have play2d API

I can take a look at adding play3d sometime next week.

Improve isExtensionPresent()
@rh101
Copy link
Contributor Author

rh101 commented Sep 12, 2025

Using a value of -0.5 for the Z position, instead of -1.f, seems to give a better result for 2D audio panning, where it seems to completely silence the opposite side.

So this:
alSource3f(player->_alSource, AL_POSITION, player->_pan, 0.0f, -1.0f);
changes to:
alSource3f(player->_alSource, AL_POSITION, player->_pan, 0.0f, -0.5f);

Instead of hard-coding it, how about we introduce a new parameter to the setPan method, "distance", which is actually the Z value:
void AudioEngineImpl::setPan(AUDIO_ID audioId, float value, float distance = -0.5f)

so it would end up as;
alSource3f(player->_alSource, AL_POSITION, player->_pan, 0.0f, distance);

This way the developer can set it for the specific panning effect they want if the default is not suitable.

Also, we should add a method to get the current audio source position, such as:

ax::Vec3 AudioEngineImpl::getSourcePosition(int audioId)

This would cover both 2D and 3D audio.

@halx99 What is your opinion of this?

@rh101 rh101 marked this pull request as draft September 12, 2025 15:43
@halx99
Copy link
Collaborator

halx99 commented Sep 12, 2025

If ax::Vec3 AudioEngineImpl::getSourcePosition(int audioId) added, shoud we also add setSourcePosition ?

@rh101
Copy link
Contributor Author

rh101 commented Sep 13, 2025

If ax::Vec3 AudioEngineImpl::getSourcePosition(int audioId) added, shoud we also add setSourcePosition ?

Yes, I'll add that too.

Allow adjustment to 2d audio panning distance from source
@rh101 rh101 marked this pull request as ready for review September 13, 2025 00:16
@rh101
Copy link
Contributor Author

rh101 commented Sep 13, 2025

@halx99 I'm not quite sure why the iOS and OSX tests are failing, unless it's something I'm not seeing in the logs.

@halx99
Copy link
Collaborator

halx99 commented Sep 13, 2025

@halx99 I'm not quite sure why the iOS and OSX tests are failing, unless it's something I'm not seeing in the logs.

here: /Users/runner/work/axmol/axmol/core/audio/AudioPlayer.h:78:5: error: unknown type name 'Vec3'
78 | Vec3 _sourcePosition;

seems you miss include "math/Vec3.h" in AudioPlayer.h

@rh101
Copy link
Contributor Author

rh101 commented Sep 13, 2025

here: /Users/runner/work/axmol/axmol/core/audio/AudioPlayer.h:78:5: error: unknown type name 'Vec3' 78 | Vec3 _sourcePosition;

seems you miss include "math/Vec3.h" in AudioPlayer.h

Thank you. I totally missed that in the logs.

@halx99 halx99 merged commit 3afa35b into axmolengine:release/2.x Sep 13, 2025
15 checks passed
@rh101 rh101 deleted the audio-enhancements branch September 13, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants