0
0

Hi,

I’m trying to extract the raw pcm data from FMOD (to inject into an audio recognision lib).
As I want the entire sound file at once, I use Lock/Unlock on the sound object :
[code:37nq0kfu]int channels, bits;
float rate;
void *ptr1, *ptr2;
unsigned int lenbytes, len1, len2;
SamplePtr ret(new Sample()); //ref counting pointer

mSound->getFormat (0, 0, &channels, &bits);
mSound->getDefaults(&rate, 0, 0, 0);
mSound->getLength (&lenbytes, FMOD_TIMEUNIT_PCMBYTES);

mSound->lock(0, lenbytes, &ptr1, &ptr2, &len1, &len2);

ret->data = (short*)ptr1;
ret->size = len1 / (bits>>3);
ret->bitpersample = bits;
ret->channel = channels;
ret->frequency = rate;

mSound->unlock(ptr1, ptr2, len1, len2);
return ret;[/code:37nq0kfu]

it works fine untill I’m done with it and all the ref counting pointers get out of scope…
I do a free() on the data but, just as delete and _aligned_free, it crashes.

Am I not supposed to delete this memory and will FMOD do it for me?
or should I take a copy of the data instead of just storing the pointer ?

  • You must to post comments
0
0

Hi mindbreaker,

That data is internal to FMOD, do not attempt to free it. Our API works by keeping things parallel, if you called ‘create’ to make the object, then you need to call ‘release’ to clean it up. If you used malloc to create a buffer to pass to FMOD, then you have to use free to clean it up later. Depending on what platform you’re on, this can be a necessity. For example on Windows if you try to free memory that was allocated inside a DLL with a different CRT version that can cause problems.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.