I have created a channel and applied it to a sound that gets played on a loop basis.
However, if I change the 3D coordinates for the channel, nothing happens.
I believe that this is due to the fact that there is no channel “creation”.
Every documentation I have found for Fmod simply just uses a channel, they never set it to anything, initializes it to anything. It’s just null.
I can’t find a constructor, I can’t find anything.
However, during my play of the sound, it should retrieve a channel from the audio function, but it doesn’t change the value.
There is no creation function for FMOD::Channel, internally FMOD has a pool of them, it will return you a handle to one of these objects via System::playSound.
If you change your SoundManager::PlaySound function to take a FMOD::Channel** you can return the pointer System::playSound returns.
After that you can call any Channel APIs you need.
Make sure you regularly call System::update, this should be performed once per game frame.
Also, please check the error codes returned from all FMOD functions.
Calling Channel::setPaused on a nullptr channel will fail.
e.g.
FMOD::Channel *channel = nullptr;
SoundManager::PlaySound(…, &channel, …);
SoundManager::SetChannelAttributes(channel, …);
Thanks a lot! I’ve changed my structure now but it still does not work. However, it does not return any errors (it says OK).
I’ve tried panning, and directly changing the 3D attributes, but always I hear the same audio at the same place. Do I have to create a listener?
It’s only for a 2D game so if SetPan could work that would be great.
void SoundManager::SetChannelAttributes(FMOD::Channel **aChannel, int aX, int aY, int aZ)
{
FMOD_VECTOR positionVector;
FMOD_VECTOR velocityVector; // default 0
FMOD_VECTOR alt_pan_posVector;
positionVector.x = aX;
positionVector.y = aY;
positionVector.z = aZ;
FMOD_RESULT result = (*aChannel)->set3DAttributes(&positionVector, 0, nullptr);
std::cout << result << std::endl;
You should leave SetChannelAttributes as FMOD::Channel*, only change PlaySound to FMOD::Channel**. Also I noticed you are passing in SoundClass to System::playSound, you should be passing in an FMOD::Sound*. I highly recommend you take a look at our examples and start with those, copying and modifying as necessary.
I send in a SoundClass which is typedef for FMOD::Sound* and then retrieve a channel and return it to the user of the function. I then alter that channel with error code “OK”. Still ordinary 1D sound though.
It works now! It was actually just missing a function call to system->update… My bad! However, what settings for the listener is correct if i want to center the listener at the middle of the screen? (in my engine 0.5f, 0.5f)
That was about to be my next suggestion, glad you got it working. As for Channel and Listener positions, they can be set with any units or positions you like, everything is relative.