0
0

Hello all,

This is related to my previous post: [url:3s6g5xyr]http://www.fmod.org/forum/viewtopic.php?t=13389[/url:3s6g5xyr]

I have made some more accurate debugging and it seems to me that, in an FMOD thread, there is only one FMOD_CREATESOUNDEXINFO instance created, no matter how many FMOD::Sound objects are set up. Of course, this leads to problems: when I change the userdata stored for one sound, the userdata for other sounds is corrupted (I basically get a bad pointer).

A concrete example:
– I have an FMOD thread in which commands to start/stop recording from various sources are received
– whenever a start command is received, I do the following:
[code:3s6g5xyr]FMOD_CREATESOUNDEXINFO exinfo;
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
....
exinfo.pcmreadcallback = pcmreadcallback;
exinfo.userdata = (void *)&filename;

fmodsystem->createSound(0, FMOD_2D | FMOD_OPENUSER | FMOD_LOOP_NORMAL | FMOD_SOFTWARE | FMOD_CREATESTREAM, &exinfo, &sound);
[/code:3s6g5xyr]

  • in my [b:3s6g5xyr]pcmreadcallback[/b:3s6g5xyr] function, I get the userdata as follows:
    [code:3s6g5xyr]char **filename = NULL;
    ((FMOD::Sound *)sound)->getUserData((void **)&filename);
    [/code:3s6g5xyr]

  • when a stop command is received, I do (among other things)
    [code:3s6g5xyr]sound->setUserData((void *)NULL);
    [/code:3s6g5xyr]

  • in my test I created two sounds, sound1 and sound2. The address for the sound variables was different, but the address of the exinfo structure is always the same

  • when I stop sound1, I get a NULL value for userdata in [b:3s6g5xyr]pcmreadcallback[/b:3s6g5xyr]. But when the [b:3s6g5xyr]pcmreadcallback[/b:3s6g5xyr] is invoked for sound2, I get a bad pointer for its userdata, even though I only wanted to modify sound1’s userdata.

Should I have one pcmreadcallback for each defined sound? I have tried something like this but it didn’t work…after all, the exinfo was the same again.

Thanks in advance for any suggestion!
–Cristina.

  • You must to post comments
0
0

Hi Christina,

I think that what you need is to create the userdata dynamically. You would then have to take care that it gets deleted properly as well. You do not really care about the FMOD_CREATESOUNDEXINFO, because it is useful only for sound creation and it contains a pointer to a userdata object, which is the same object all the sounds are pointing to in your scenario. So you need to create one userdata object for each sound and then pass it to the FMOD_CREATESOUNDEXINFO.

[code:2g3z9ca1]
FMOD_CREATESOUNDEXINFO exinfo;
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
Sound_user_data* user_data = new Sound_user_data();
exinfo.userdata = user_data;
system->createSound(waveform_filename.c_str(),
FMOD_NONBLOCKING, &exinfo, &sound)
[/code:2g3z9ca1]
… then later in the code after you want to release the sound
[code:2g3z9ca1]
sound->getUserData((void**)&user_data);
delete user_data;
sound->release();
[/code:2g3z9ca1]
You could possibly use scoped_ptr to have that sorted out by itself.

  • You must to post comments
0
0

call

setUserData after you create the sound. that should fix it. And getUserData to get you extra info

  • You must to post comments
0
0

Thanks a lot both for the advice!

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.