Add audio::convert(sample)
This commit is contained in:
parent
3feb2776c1
commit
3e38bb2672
1 changed files with 9 additions and 0 deletions
|
|
@ -18,4 +18,13 @@ namespace psemek::audio
|
|||
return static_cast<sample>(std::min<int>(max, std::max<int>(min, std::round(v))));
|
||||
}
|
||||
|
||||
// maps [-1, 1] range to samples
|
||||
inline sample convert(float v)
|
||||
{
|
||||
static auto const min = static_cast<float>(std::numeric_limits<sample>::min());
|
||||
static auto const max = static_cast<float>(std::numeric_limits<sample>::max());
|
||||
|
||||
return clamp(min + (v * 0.5f + 0.5f) * (max - min));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue