0
0

Hi.
I have a problem with playing a .mod and a .wav at the same time.
I made a search on the forum, but I couldn’t find anything to help me.

I’ll just give you the code, it will be easier to understand :)
This is my sound class. Worth to mention is that I’ve tried to put two tutorials together from gametutorials.

[code:1amsw60b]Sound::Sound(void)
{
// Clear the file name
memset(m_strName, 0, sizeof(char));
memset(s_strName, 0, sizeof(char));

// Set the current song module to NULL
m_pSound = NULL;
m_pModule = NULL;

}

Sound::~Sound(void)
{
// Free the sound pointer that loaded our song if it’s valid
FSOUND_StopSound(m_soundChannel);
FMUSIC_FreeSong(m_pModule);

// Now free the whole sound system
FSOUND_Close();

}

bool Sound::InitEffect(char *strName)
{
// Make sure we are using the correct DLL version
if (FSOUND_GetVersion() < FMOD_VERSION)
return false;

// Initialize our FMod Sound System with good quality sound and a global focus
if (!FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS))
    return false;

// Return the result from when we attempt to load the song
return LoadEffect(strName);

}

bool Sound::InitSong(char *strName)
{

if (FSOUND_GetVersion() &lt; FMOD_VERSION)
    return false;

if (!FSOUND_Init(44100, 32, FSOUND_INIT_GLOBALFOCUS))
    return false;

return LoadSong(strName);

}

bool Sound::LoadEffect(char *strName)
{
// If strName is invalid, can’t load song
if(!strName)
return false;

// Load the desired song and store the pointer to the sound.
m_pSound = FSOUND_Sample_Load(FSOUND_FREE, strName, 0, 0);

// Make sure we got a valid sound pointer
if (!m_pSound )
    return false;

// Set the file name to the name passed in
strcpy(m_strName, strName);

// Return a success!
return true;

}

bool Sound::LoadSong(char *strName)
{
m_pModule = FMUSIC_LoadSong(strName);

if (!m_pModule )
    return false;

strcpy(s_strName, strName);

return true;

}

// This will play the current song stored in the m_pSound (Must be loaded first)
void Sound::PlayEffect()
{

// Play our song that we loaded, then get the sound channel it chose to assign it too.
m_soundChannel = FSOUND_PlaySound(FSOUND_FREE, m_pSound);

}

void Sound::PlaySong()
{
FMUSIC_PlaySong(m_pModule);
}[/code:1amsw60b]

I’ve read somewhere here in the forums that you shouldn’t have two init’s.. But i couldn’t come up with a better solution, because I have two different pointers.

And here is how I “use” my class.
[code:1amsw60b]if(!sound->InitSong("toilet.xm"))
exit(1);

sound->PlaySong();

if(!sound->InitEffect("Blip.wav"))
exit(1);[/code:1amsw60b]

I play the EffectSound when I push a button.
[code:1amsw60b]sound->PlayEffect();[/code:1amsw60b]

But as you can see. When I start my program, there will be no music, just the effect.
And if I comment the InitEffect, I only get music.

Do you have any suggestions what I should do?
There should be plenty, because I don’t think this is “the right way” to use FMOD 😆

  • You must to post comments
0
0

make a method which initialises fmod (it only needs to be done once per program) and then make seperate methods for loading songs and effects. or as you always call initsong first just remove the fsound_init from the initeffect method

  • You must to post comments
0
0

I changed so I only init fmod once, and loaded the song/effect with loadsong/loadeffect..

Now it works fine.
Thanks for you help.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.