0
0

Hey there. I am a noob at using fmodex and I’m having a certain issue.
I’m not sure if it’s my fault or if it’s something else, but when I create an stream and play it, the stream plays in all the channels I create when initializing fmod. I tagged this thread as windows, but I’m not sure if the problem has anything to do with it.
Here is my current code for the class I’m using:
[code:3bjjxdjc]Audio::Audio()
{
//Create system object//
m_Result = FMOD::System_Create(&m_pSystem);
if(m_Result != FMOD_OK)
MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD System Error", MB_OK);

//Check FMOD version//
m_Result = m_pSystem->getVersion(&m_FmodVersion);
if(m_FmodVersion < FMOD_VERSION)
    MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD Version Error", MB_OK);

//Check if hardware acceleration is disabled//
m_pSystem->getDriverCaps(0, &m_Caps, 0, &m_SpeakerMode);
if (m_Caps & FMOD_CAPS_HARDWARE_EMULATED)
    MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD Acceleration Error", MB_OK);

//Initialize system object//
m_Result = m_pSystem->init(128, FMOD_INIT_NORMAL, 0);
if(m_Result != FMOD_OK)
    MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD System Error", MB_OK);

m_IsLoaded = false;

}

void Audio::LoadMusic(char *filename)
{
m_Result = m_pSystem->createStream(filename, FMOD_DEFAULT, 0, &m_pSound);
if(m_Result != FMOD_OK)
MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD Loading Error", MB_OK);
}

void Audio::Play()
{
m_Result = m_pSystem->playSound(FMOD_CHANNEL_FREE, m_pSound, false, &m_pChannel);
if(m_Result != FMOD_OK)
MessageBox(NULL, FMOD_ErrorString(m_Result), "FMOD Playing Error", MB_OK);
}[/code:3bjjxdjc]

When I use this code it seems like the song is playing in all the 128 channels at once. If I reduce it to 2, the song plays but every 2-3 seconds another piece of the same song plays at the same time. (The song in the background plays properly though.)
I hope you guys can give me some advices or at least point me what I’m doing wrong.
Thanks in advance.

EDIT: I managed to fix the error when playing a stream by pausing it at the end of the play method and unpausing at the beginning. It seems that it was playing it more than once, that was why. I still don’t know why it plays in several channels at once though.
Also, when I use a stream, the memory usage of the program keeps increasing all the time. I’m guessing it’s because the internal buffer for the stream isn’t being freed. Is there a function to free it on each frame?

  • You must to post comments
0
0

it really sounds like you’re creating the sound and playing it every frame, are you absolutely sure you’re only creating and playing it once. stream’s dont allocate memory once theyre playing so they would not increase in memory usage.

  • You must to post comments
0
0

I know a sound only has to be created once, but doesn’t a stream have to be read piece by piece on each frame? If I only create a stream and use the play function, it only plays a small portion of the song (or not even play anything). I have to create the stream on every frame for it to play completely, otherwise the same piece plays over and over.
I show you an example here:

[code:1b3dr907]if(!m_IsLoaded)
{
m_Result = m_pSystem->createStream(filename, FMOD_CREATECOMPRESSEDSAMPLE, 0, &m_pSound);
ErrorCheck(m_Result);
m_IsLoaded = true;
}
m_Result = m_pSystem->playSound(FMOD_CHANNEL_FREE, m_pSound, false, &m_pChannel);
ErrorCheck(m_Result);
[/code:1b3dr907]
When I do this, this is what I hear: http://www.mediafire.com/?ake0j6bfzpe3qee

[code:1b3dr907]
m_Result = m_pSystem->createStream(filename, FMOD_CREATECOMPRESSEDSAMPLE, 0, &m_pSound);
ErrorCheck(m_Result);
SetPause(false);
m_Result = m_pSystem->playSound(FMOD_CHANNEL_FREE, m_pSound, false, &m_pChannel);
ErrorCheck(m_Result);
SetPause(true);[/code:1b3dr907]
And when I do this it plays just fine as you can hear here: http://www.mediafire.com/?bjnbx3sn7cfuud6
but memory usage goes up all the time. Probably because it’s creating a new "stream" everytime.
Can you tell what I’m doing wrong here?

EDIT: Nevermind, I don’t know how I was so stupid. You need to run the play function only once.
Ignore what I just posted. It works perfectly now.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.