player: add some comments
The code is horribly undocumented as is. Try to improve this by adding some comments in the most important parts.
This commit is contained in:
parent
bc5fcca75f
commit
55f2508283
13
sync/track.c
13
sync/track.c
@ -36,16 +36,21 @@ static float key_ramp(const struct track_key k[2], double row)
|
|||||||
float sync_get_val(const struct sync_track *t, double row)
|
float sync_get_val(const struct sync_track *t, double row)
|
||||||
{
|
{
|
||||||
int idx, irow;
|
int idx, irow;
|
||||||
|
|
||||||
|
/* If we have no keys at all, return a constant 0 */
|
||||||
if (!t->num_keys)
|
if (!t->num_keys)
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
||||||
irow = (int)floor(row);
|
irow = (int)floor(row);
|
||||||
idx = key_idx_floor(t, irow);
|
idx = key_idx_floor(t, irow);
|
||||||
|
|
||||||
|
/* at the edges, return the first/last value */
|
||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return t->keys[0].value;
|
return t->keys[0].value;
|
||||||
if (idx > (int)t->num_keys - 2)
|
if (idx > (int)t->num_keys - 2)
|
||||||
return t->keys[t->num_keys - 1].value;
|
return t->keys[t->num_keys - 1].value;
|
||||||
|
|
||||||
|
/* interpolate according to key-type */
|
||||||
switch (t->keys[idx].type) {
|
switch (t->keys[idx].type) {
|
||||||
case KEY_STEP:
|
case KEY_STEP:
|
||||||
return t->keys[idx].value;
|
return t->keys[idx].value;
|
||||||
@ -64,6 +69,8 @@ float sync_get_val(const struct sync_track *t, double row)
|
|||||||
int sync_find_key(const struct sync_track *t, int row)
|
int sync_find_key(const struct sync_track *t, int row)
|
||||||
{
|
{
|
||||||
int lo = 0, hi = t->num_keys;
|
int lo = 0, hi = t->num_keys;
|
||||||
|
|
||||||
|
/* binary search, t->keys is sorted by row */
|
||||||
while (lo < hi) {
|
while (lo < hi) {
|
||||||
int mi = (lo + hi) / 2;
|
int mi = (lo + hi) / 2;
|
||||||
assert(mi != hi);
|
assert(mi != hi);
|
||||||
@ -73,8 +80,11 @@ int sync_find_key(const struct sync_track *t, int row)
|
|||||||
else if (t->keys[mi].row > row)
|
else if (t->keys[mi].row > row)
|
||||||
hi = mi;
|
hi = mi;
|
||||||
else
|
else
|
||||||
return mi;
|
return mi; /* exact hit */
|
||||||
}
|
}
|
||||||
|
assert(lo == hi);
|
||||||
|
|
||||||
|
/* return first key after row, negated and biased (to allow -0) */
|
||||||
return -lo - 1;
|
return -lo - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +93,7 @@ int sync_set_key(struct sync_track *t, const struct track_key *k)
|
|||||||
{
|
{
|
||||||
int idx = sync_find_key(t, k->row);
|
int idx = sync_find_key(t, k->row);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
|
/* no exact hit, we need to allocate a new key */
|
||||||
void *tmp;
|
void *tmp;
|
||||||
idx = -idx - 1;
|
idx = -idx - 1;
|
||||||
tmp = realloc(t->keys, sizeof(struct track_key) *
|
tmp = realloc(t->keys, sizeof(struct track_key) *
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user