0
0

Hi,

I just started using FMODex a couple of days ago, and have run into some trouble with voices getting freed up after use. I’m attaching an example program, based on a modification of examples/playsound.

If you compile and run this example, it will sit there at the prompt waiting. Hit enter on the keyboard, and four sounds will play at once. If you hit enter again, the same thing will happen, for up to eight times. After that, only a single sound will play. If I play two songs at once, it takes 16 iterations before the sound is down to a single voice. This tells me, I think, that there are 32 voices in all, and that they aren’t getting freed up when the sound stops playing.

I read in in [url:22w9o9u8]http://www.fmod.org/forum/viewtopic.php?t=13461[/url:22w9o9u8] that the sounds must either stop or you must call channel::stop on them to free them up. Well these sounds are all quite short, and stop just a few seconds after starting. So I don’t think I should need to call stop on the channel.

Is this a bug in FMODex or am I doing something wrong?

Note that this problem occurs on Window XP 32, and Linux x86_64, and I have also tried using the development version (4.33.06) of FMODex, but the results were the same.

Thanks,

  • Corey

[code:22w9o9u8]

include "../inc/fmod.h"

include "../inc/fmod_errors.h"

include <stdlib.h>

include <stdio.h>

include <string.h>

include <errno.h>

void ERRCHECK(FMOD_RESULT result) {
if (result != FMOD_OK) {
fprintf(stderr, "FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}

struct sound {
char *file;
};

struct sound sounds[] = {
{ .file = "../media/jaguar.wav" },
{ .file = "../media/swish.wav" },
{ .file = "../media/drumloop.wav" },
{ .file = "../media/c.ogg" }
};

static inline int get_num_sounds()
{
return (sizeof(sounds) / sizeof(struct sound));

}

int main(int argc, char *argv[]) {
FMOD_SYSTEM *system;
FMOD_SOUND **fmod_sounds;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
unsigned int version;
int i, ret;
char *buffer;
size_t buffer_size = 1024;

fmod_sounds = malloc(sizeof(FMOD_SOUND *) * get_num_sounds());
buffer = malloc(buffer_size);

/*
 Create a System object and initialize.
 */
result = FMOD_System_Create(&amp;system);
ERRCHECK(result);

result = FMOD_System_GetVersion(system, &amp;version);
ERRCHECK(result);

if (version &lt; FMOD_VERSION) {
    printf(&quot;Error!  You are using an old version of FMOD %08x.  This program requires %08x\n&quot;,
        version, FMOD_VERSION);
    return 0;
}

result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
ERRCHECK(result);

for (i = 0; i &lt; get_num_sounds(); i++) {
    result = FMOD_System_CreateSound(system, sounds[i].file,
            FMOD_SOFTWARE, 0, &amp;fmod_sounds[i]);
    ERRCHECK(result);
    result = FMOD_Sound_SetMode(fmod_sounds[i], FMOD_LOOP_OFF);
    ERRCHECK(result);
}
while (1) {
    printf(&quot;Hit Enter to play four sounds simultaneously:&quot;);
    ret = getline(&amp;buffer, &amp;buffer_size, stdin);
    if (ret &lt; 0)
        break;
    for (i = 0; i &lt; get_num_sounds(); i++) {
        result = FMOD_System_PlaySound(system,
                FMOD_CHANNEL_FREE, fmod_sounds[i], 0, &amp;channel);
        ERRCHECK(result);
    }
}

/*
 Shut down
 */
for (i = 0; i &lt; get_num_sounds(); i++) {
    result = FMOD_Sound_Release(fmod_sounds[i]);
    ERRCHECK(result);
}
result = FMOD_System_Close(system);
ERRCHECK(result);
result = FMOD_System_Release(system);
ERRCHECK(result);

return 0;

}
[/code:22w9o9u8]

  • You must to post comments
0
0

Ok, I want to post that I found the error in the test case I posted.

The problem is that it should be allocating a separate channel for every sound that is played simultaneously, not re-using/overwriting the FMOD_CHANNEL pointer on every call to FMOD_System_PlaySound().

I tried a modification of the test case where each of the four sounds is allocated a separate channel, and it seems to work flawlessly.

So, in other words, "my bad", and thanks for providing such a nice and easy to use library!

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.