0
0

I’m writing a free game, trying to implemet some object oriented design, I’v chossen FMOD for the sound system, it is really using so little CPU power for playback, it is really uncomparable with other free engines, and it really works just fine for everithing except that I can’t set the volumes for channels…
I’m using FMOD on WinXP with VC++7.0…

Here is a snippet of my code, C++ implementation of a music stream…
Please have a llok, it’s really very simple…
[code:266c78vb]
//cMusic.h
class cMusic
{
public:
cMusic(char *fileName, int defaultVolume = MIX_MAX_VOLUME / 2);
~cMusic(void);
bool setVolume(int newVolume);
bool setMusicStopCallback(FSOUND_STREAMCALLBACK callback, int data);

inline FSOUND_STREAM *getMusic() {return music;};
inline int getVolume() {return volume;};
inline int getChannel() {return channel;};

private:
FSOUND_STREAM *music;
int volume;
int channel;
};

//cMusic.cpp

include "cMusic.h"

extern int _mix_num_of_channels;

cMusic::~cMusic(void)
{
if (music)
{
FSOUND_Stream_Close(music);
if (FSOUND_SetReserved(channel, false))
_mix_num_of_channels–;
}
}

cMusic::cMusic(char *fileName, int defaultVolume)
{
music = NULL;
music = FSOUND_Stream_OpenFile(fileName, FSOUND_NORMAL | FSOUND_MPEGACCURATE, 0);
channel = 0;

if (music && _mix_num_of_channels < MIX_MAX_CHANNELS)
{
    volume = defaultVolume;
    channel = FSOUND_Stream_PlayEx(FSOUND_FREE, music, NULL, TRUE);
    if (channel != -1)
    {
        if (FSOUND_SetReserved(channel, true) &&
            setVolume(volume) &&
            FSOUND_StopSound(channel))
        {
            _mix_num_of_channels++;
            return;
        }
    }
}

if (music)
    FSOUND_Stream_Close(music);
if (channel)
{
    if (FSOUND_GetReserved(channel))
        FSOUND_SetReserved(channel, false);
}

channel = 0;
music = NULL;
volume = 0;

}

bool cMusic::setVolume(int newVolume)
{
if (!music)
return false;

volume = newVolume;

if (newVolume < MIX_MIN_VOLUME)
    volume = MIX_MIN_VOLUME;
if (newVolume > MIX_MAX_VOLUME)
    volume = MIX_MAX_VOLUME;

if (!FSOUND_SetVolume(channel, volume))
{
    volume = 0;
    return false;
}
else
    return true;

}

bool cMusic::setMusicStopCallback(FSOUND_STREAMCALLBACK callback, int data)
{
if (music)
return FSOUND_Stream_SetEndCallback(music, callback, data) ? true : false;
else
return false;
}
[/code:266c78vb]
the problem is that all FSOUND calls return ok values, not indicating any error, event if I try to read the volume for a specified channel, it returns me the volume that I’v set, but I can’t hear the diference…
I play the stream like this…
[code:266c78vb]
bool cMixer::playMusic(cMusic *music)
{
if (bInit && music)
{
if (FSOUND_Stream_Play(music->getChannel(), music->getMusic()) == -1)
return false;
else
return true;
}
else
return false;
}
[/code:266c78vb]
and it plays, but the volume is always the same, no metter wich value I passed to cMusic::setVolume….
I think that the code is pretty straight, and really can’t figure out what is wrong??? I suppose that I have made some mistake somwhere but I can’t figure it out, I really don’t think that this can be a bug in FSOUND….

is the FSOUND_StreamPlayEx, getiing the channel handle, then FSOUND_StopSound on that channel, and then FSOUND_SetReserved combination OK or what is wrong???

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.