I don’t seem to be getting any distance attenuation on my 3D sounds. I am getting 3D positioning so the sounds are correctly coming from the left or right, so I’m assuming I’m setting up the Listener correctly.
I’m using FSBs for everything so I use LoadSongEx to load the bank and I pass in FSOUND_HW3D to use 3D sounds.
I’m not using velocity, but I’ve made sure the listener position is in the correct coordinate system and that my forward and up vectors are unit vectors.
After I call PlaySoundEx to get the channel, I call FSOUND_3D_SetMinMaxDistance() on the channel once. My default values are 2 and 2000. All of our units are in meters so I haven’t changed any factors within fmod.
Perhaps I’m supposed to set the MinMaxDistance every frame?
Once a frame before I call FSOUND_Update() I call FSOUND_3D_SetAttributes() on every 3D sound with it’s updated position.
That should be all I have to do, right? Does anyone have any ideas why I might not be getting any distance attenuation at all?
Red Storm Entertainment
- garner42 asked 13 years ago
Well, I tried it 2 ways and I’m getting the same result. Here’s my code snippet.
RSVector3 position = GetPosition();
fmodPos.x = -position.y;
fmodPos.y = position.z;
fmodPos.z = position.x;
FSOUND_3D_SetAttributes( channel, &fmodPos.x, NULL );
I also tried this:
pos2 = fmodPos.x;
pos2 = fmodPos.y;
pos2 = fmodPos.z;
FSOUND_3D_SetAttribues( channel, pos2, NULL );
Same result. RSVector3 is a class, but the only member variables are float x, y, z and they’re in that order and I’m 99% sure passing the pointer to x will work.
Now, the funky part. Distance attenuation is now working on the PS2 version of the game. It wasn’t working before, but since I’ve fixed my coordinate system conversion, now it is. And it’s running through the same exact code as the PC. Very frustrating. I’m sure I’m still doing something wrong.
Keep those suggestions coming…you are all being very helpful!
I am looking into my 3D sounds now and have noticed the same problem. I’m actually doing a test that seems to indicate a problem with FMod or in my init code.
I set the listener position at (0,0,0).
I set the listener orientation to be front(0,0,1) up(0,1,0).
I’m setting all sounds to be at position (1000000, 1000000, 1000000). I’m setting all sounds to have min distance = 10 and max distance = 1000000000.
Doing this I still hear the sounds playing at the same volume as if it were at position(0,0,0).
Now if I set all of my sounds to play at (0,0,0), and move my listener around… I get some attenuation, but it’s weird. If I set the listener to be (100, 0, 0), I’ll hear a few sounds at max volume, but most of them will play quieter. The sounds that are quieter are being played out of my right speakers, which is odd because since I moved my listener to the right of the origin I would expect my sounds to be heard out of the left speakers.
My tests have shown me the following:
Moving sounds doesn’t seem to attenuate them.
Moving the listener has odd behavior…
-> Hear some sounds at normal volume
-> Hear most sounds at quieter volume but out of wrong speakers.
- and 2. seem to be correct, but you hit upon #3. FSOUND_3D_SetAttributes is returning FALSE. I called GetError after that and it says I’m passing an invalid parameter.
So either I’m passing a bad channel or a bad pointer to the vector for position (I’m not using velocity). For the channel I’m using whatever value PlaySound returns (I save it).
For the position, we have our own vector class, but the only member variables are float x, y, z, so I’m passing a pointer to the x value. Like this:
FSOUND_3D_SetAttributes( channel, &pos.x );
I’m going to verify that the channel is correct and I’m going to try and create an array of 3 floats and set the values that way for the position just to be sure I’m doing it right.
You’re passing your vector data in the function wrong. You have to pass an array of size 3 as that parameter like this…
vPos = pos.x;
vPos = pos.y;
vPos = pos.z;
Then pass vPos in the parameter instead of &pos.x.
Hope that helps.
Well, I’m an idiot. I’m actually not getting FALSE for SetAttributes and it turns out I converted our coordinate system wrong. Sigh. Just for my own sanity and in case someone else needs the help, here is what I did:
X is forward
Z is up
Y is left
So I did the conversion as:
fmod.x = -pos.y
fmod.y = pos.z
fmod.z = pos.x
HOWEVER…I’m still not getting any distance attenuation.
For the channel on the PC, should I be getting values in the 10s of thousands? I verified that the channel I get from PlaySoundEx is the same value I pass in for SetAttributes and for SetMinMaxDistance.
Any more ideas would be greatly appreciated.
Please login first to submit.