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.
Returns a pointer to the beginning of the sample data for a sound.
unsigned int offset,
unsigned int length,
void ** ptr1,
void ** ptr2,
unsigned int * len1,
unsigned int * len2
with following explenation
Address of a pointer that will point to the first part of the locked data.
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.
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 asked 8 years ago
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.
len = len1 + len2;
len = len1;
ptr = malloc(len);
memcpy(ptr, ptr1, len1);
memcpy(ptr + len1, ptr2, len2);
- a1psx answered 8 years ago
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
and data from ptr1 to ptr1+len1 will be locked. In such a case ptr2 is null, len2=0.
Second scenario is
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).
- zorank answered 8 years ago
Please login first to submit.