Skip to content

Commit

Permalink
Add linear interpolation to convex and concave transfer functions (#1156
Browse files Browse the repository at this point in the history
)

Co-authored-by: md1872b <72792887+md1872b@users.noreply.github.com>
  • Loading branch information
derselbst and md1872b authored Sep 20, 2022
1 parent 05c95c4 commit bfe3599
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/utils/fluid_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,17 @@ fluid_real_t fluid_balance(fluid_real_t balance, int left)
fluid_real_t
fluid_concave(fluid_real_t val)
{
int ival = (int)val;
if(val < 0.f)
{
return 0.f;
}
else if(val >= (fluid_real_t)FLUID_VEL_CB_SIZE)
else if (ival >= FLUID_VEL_CB_SIZE - 1)
{
return 1.f;
return fluid_concave_tab[FLUID_VEL_CB_SIZE - 1];
}

return fluid_concave_tab[(int) val];
return fluid_concave_tab[ival] + (fluid_concave_tab[ival + 1] - fluid_concave_tab[ival]) * (val - ival);
}

/*
Expand All @@ -316,15 +317,17 @@ fluid_concave(fluid_real_t val)
fluid_real_t
fluid_convex(fluid_real_t val)
{
int ival = (int)val;
if(val < 0.f)
{
return 0.f;
}
else if(val >= (fluid_real_t)FLUID_VEL_CB_SIZE)
else if (ival >= FLUID_VEL_CB_SIZE - 1)
{
return 1.f;
return fluid_convex_tab[FLUID_VEL_CB_SIZE - 1];
}

return fluid_convex_tab[(int) val];
// interpolation between convex steps: fixes bad sounds with modenv and filter cutoff
return fluid_convex_tab[ival] + (fluid_convex_tab[ival + 1] - fluid_convex_tab[ival]) * (val - ival);
}

0 comments on commit bfe3599

Please sign in to comment.