0
0

I am trying to build a class which has all sounds in one object. I came across this website [url:2ca43xxe]http://hi.baidu.com/jingjiacheng/blog/item/0f477d3ca347bdfcb211c757.html[/url:2ca43xxe] which has done basically the same as I have.

I manage to load a sound into the SoundVector array, but I have trouble getting access to it when playing. Any clues?

ps: also tips on makeing a game engine( with sounds ), managing sounds etc is appreciated.

[code:2ca43xxe]
void SoundClass::load_sound(const char * name_or_data)
{
FMOD::Sound Sound;
FMOD::Channel *Channel;
SoundSystem->createSound(name_or_data, FMOD_3D, 0, &Sound);
Sound->set3DMinMaxDistance(0.5f * DISTANCEFACTOR, 5000.0f * DISTANCEFACTOR);
Sound->setMode(FMOD_LOOP_NORMAL);
SoundVector->push_back(
Sound);
ChannelVector->push_back(*Channel);
}

void SoundClass::PlaySound(int i)
{
FMOD::Channel *Channel;
SoundSystem->playSound(FMOD_CHANNEL_FREE, SoundVector[i], false, &Channel); //<- ERROR HERE
ChannelVector[i] = Channel;
}
[/code:2ca43xxe]
[code:2ca43xxe]
: error C2664: ‘FMOD::System::playSound’ : cannot convert parameter 2 from ‘std::vector<_Ty>’ to ‘FMOD::Sound *’
with
[
_Ty=FMOD::Sound
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
: error C2679: binary ‘=’ : no operator found which takes a right-hand operand of type ‘FMOD::Channel *’ (or there is no acceptable conversion)
: could be ‘std::vector<_Ty> &std::vector<_Ty>::operator =(const std::vector<_Ty> &)’
with
[
_Ty=FMOD::Channel
]
while trying to match the argument list ‘(std::vector<_Ty>, FMOD::Channel *)’
with
[
_Ty=FMOD::Channel
]
[/code:2ca43xxe]

  • You must to post comments
0
0

The "pointers" that FMOD provides to you are not actual pointers. That is, you can’t dereference them and expect to get anything meaningful.

You can think of it like the C file API:
[code:1alst3ep]FILE* pFile = fopen("blah.txt", "r");[/code:1alst3ep]
You shouldn’t actually dereference pFile. Instead, you use functions that take a FILE* like fread(), ftell(), and fseek().

Similarly, you shouldn’t actually be dereferencing FMOD’s classes. You should not be storing a vector<FMOD::Sound>, but rather a vector<FMOD::Sound>:
[code:1alst3ep]FMOD::Sound
pSound = pSystem->createSound(...);
vec.push_back(pSound);[/code:1alst3ep]
(Obviously you’ll have to change the declaration to match.)

It’s also worth noting that your SoundClass::load_sound() function puts an uninitialized channel into the vector, which can only be a bad thing. Similar to FMOD::Sound*, you should only be storing a vector of FMOD::Channel*. Then if you want a placeholder you can use NULL (or nullptr if you’re on a compiler that supports it).

Hope that helps.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.