Simply put, is there a way to determine whether a given AudioSound object is a 3D sound or a 2D sound? (As in the cases of a sound that was loaded via an Audio3DManager, as opposed to one simply loaded via “loader”.)
The Audio3DManager class instance holds a dictionary of object : sound-list items named
sound_dict. If your sound is attached to an object (and hence in the 3d space) it will be in the list for any of the objects in the dict. There is also a function to get the sounds attached to an object in the Audio3DManager
getSoundsOnObject(yourObject) if that’d be simpler for you.
If yoiu haven’t attached your sound to an object you may want to create a dedicated list to which you add your 3D sounds to since as far as I’ve seen, all lists in the audio sound classes that hold the loaded sounds are private and by that not even visible to the python side.
Other than that you may be able to check if the sound is mono or stereo since all 3D sounds have to be Mono, but the only way I have found so far is via the MovieAudioCursor class’
audioChannels function. Not sure if or how hard it would be to create a MovieAudioCursor for your loaded sounds.
Ah, hmm, thank you.
Unfortunately, the code in question is intended to run before attachment to any object (and indeed, is intended in part to determine whether to attempt to attach the sound to an object).
As to creating lists of 3D and 2D sounds, that somewhat runs into the same problem: I would want to know whether a sound was 3D or 2D in order to determine which list to add it to.
And, well, all of my sounds (thus far) are mono! ^^;
Hum. Okay, in that case I may end up going for a slightly heavier approach than I’d hoped for, one that allows me to specify at the “source” whether a sound is 2D or 3D…
Thank you for the input!
Well, you need to know if your audio will be used as 3D audio or not as you’ll load it either through the Audio3DManager or loader.load_sfx, don’t you? Using load sfx will pass positional=False by default but it seems even the positional variable in the AudioSound class is private. So, in one way or another, you need to know if the to be loaded audio file will be used for 2D or 3D as it seems there isn’t a way to change the sounds mode (2D vs 3D) after it has been loaded. At least I couldn’t find a way.
The thing is, as things currently stand, in at least some cases the audio will have been loaded before it reaches the code in question.
That said, I’m considering making changes that would allow me to specify to said code whether a sound is 2D or 3D. That would answer the question–and, if I so choose, would allow me to switch to loading the sound later in the process.
What does it mean for a sound to be 2D or 3D, to you?
In this case, “3D” means “works with the 3D positional system”, and “2D” means “doesn’t work with the 3D positional system”.
I found that, if I just let the code handle any sound as though it were “3D”, it seemed to result in unexpected positioning of 2D sounds–in particular, audio that was intended to be UI-related ended up being positioned, I think as though it was located at the world-origin. Thus I’ve been wanting to separate out those sounds that are “2D”, in order to bypass the 3D-related code in their cases.
From a loading perspective, “2D” sounds are loaded via “loader.loadSfx”, while “3D” sounds are loaded via an Audio3DManager.
There is a “positional” flag stored on the AudioSound object, but unfortunately, there is no getter to get access to it. Sounds like an easy thing to add to a next release of Panda though; if you file an issue then I won’t forget.
Hmm… Honestly, I think that it might be simpler for me to just rework things as mentioned above.
Still, such a thing may be useful to others, so I’ll file an issue suggesting a “getter” for that flag, I intend. Thank you!