0
0

In the description of sound::lock it says that two parts/pieces of data are used and two pointers apper as arguments to the function.

[code:3u1pbja6]
Sound::lock
Returns a pointer to the beginning of the sample data for a sound.

Syntax

FMOD_RESULT Sound::lock(
unsigned int offset,
unsigned int length,
void ** ptr1,
void ** ptr2,
unsigned int * len1,
unsigned int * len2
);
[/code:3u1pbja6]

with following explenation

[code:3u1pbja6]
ptr1
Address of a pointer that will point to the first part of the locked data.

ptr2
Address of a pointer that will point to the second part of the locked data. This will be null if the data locked hasn’t wrapped at the end of the buffer.
[/code:3u1pbja6]

I have following questions:

(1) Why one needs two parts/pieces of locked data (two pointers)? For example, why not having just one chunk?

(2) What is meant precisely with the statement above "the data locked hasn’t wrapped at the end of the buffer"?

(3) What is meant by "to wrap at the end of the buffer"?

I can not visualise what is going on… :( In a way I understand that locking the buffer is fundamental if one wants get access to data (for whatever reason, analysis, etc). I would really like to understand the description of sound::lock in detail and accosicate information of how buffer is actually filled.

All the help appreciated.
ZoranK

  • You must to post comments
0
0

I’ve not looked into an example, but my first guess would be that ptr2/len2 will be a continuation of the data from ptr1/len1, something like this to rebuild the buffer for your understanding.

void *ptr;
int len;

if (ptr2)
len = len1 + len2;
else
len = len1;

ptr = malloc(len);

memcpy(ptr, ptr1, len1);

if (ptr2)
{
memcpy(ptr + len1, ptr2, len2);
}

  • You must to post comments
0
0

Many thanks for trying to help me out a1psx. I think I know now. Anyone interested in the answer please stay tuned…

I have added write statements to check how recordtodisk example behaves.

Conclusion is that FMOD uses circural buffer.

Two scenarios are possible. First one looks like this

0—-ptr1——————ptr1+len1————————-end

and data from ptr1 to ptr1+len1 will be locked. In such a case ptr2 is null, len2=0.

Second scenario is

0=ptr2—–len2——————–ptr1————–end

which corresponds to the situation where buffer is wrapped, and locked region starts from ptr1 to end, wraping back to ptr2 untill len2 is reached. In such a case len1=end-ptr1, ptr2=0 (denotes first address of the buffer).

Cheers
ZoranK

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.