0
0

Hello all,

I have a question related to the pcmreadcallback function.
Suppose I do the following (example with non-relevant parts cut out):

[b:2i1qcmiq]In main fmod thread:[/b:2i1qcmiq]
[code:2i1qcmiq]
char *filename;

// Initialise and create the sound
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
.....
exinfo.pcmreadcallback   = pcmreadcallback;
exinfo.pcmsetposcallback = pcmsetposcallback;
mode = ...
result = fmodsystem->createSound(0, mode, &exinfo, &sound);

// Set the user data for the sound
sound->setUserData(&filename);   (1)

[/code:2i1qcmiq]

[b:2i1qcmiq]In pcmreadcallback function:[/b:2i1qcmiq]
[code:2i1qcmiq]
((FMOD::Sound *)sound)->getUserData(...) (2)
[/code:2i1qcmiq]

When I debug, it seems to me that the pcmreadcallback function is entered before the sound’s user data was set in the main fmod thread. Is there a guarantee that line (1) is executed before line (2), or is it just random chance? (Does pcmreadcallback run in its own thread?)

In case there’s no guarantee regarding the order of execution: is there any other way I can use fmod to pass the char *filename to the pcmreadcallback?
Thank you!
–Cristina.

PS. Just for my curiosity: how can I get the filename using getUserData(), anyway? The void** pointer parameter confuses my meek C++ mojo…

  • You must to post comments
0
0

[quote:vk5oglbe]PS. Just for my curiosity: how can I get the filename using getUserData(), anyway? The void** pointer parameter confuses my meek C++ mojo…[/quote:vk5oglbe]

I solved this part, but I’d be grateful for any comments on the main question in my post! :)

  • You must to post comments
0
0

You can set the user data at createSound time by using the userdata member of the FMOD_CREATESOUNDEXINFO structure.

  • You must to post comments
0
0

[quote:1zpr9ulx]When I debug, it seems to me that the pcmreadcallback function is entered before the sound’s user data was set in the main fmod thread. Is there a guarantee that line (1) is executed before line (2), or is it just random chance? (Does pcmreadcallback run in its own thread?) [/quote:1zpr9ulx]
The PCMSETPOSCALLBACK will be called once inside createSound, the PCMREADCALLBACK can be called mutliple times inside createSound. This is because FMOD needs to prepare the sound by loading some data. If you load your sound as FMOD_CREATESAMPLE, it will load the entire sound into memory inside createSound, if you load it as FMOD_CREATESTREAM then it will only load enough to fill the stream buffer. If you use FMOD_CREATESTREAM along with FMOD_OPENONLY you can avoid filling the stream buffer inside createSound, that means your PCMREADCALLBACK wont be fired off until the sound is actually playing. When a sound is playing as a stream and FMOD requires more data the PCMREADCALLBACK will be fired from FMOD’s stream thread.

  • You must to post comments
0
0

Thanks a lot Mathew & Peter, that’s exactly what I needed to know! :)

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.