mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
LibAudio: Replace log_pan with a constant power panning algoritm
This little functional change uses the most common algorithm for panning audio, known as constant power panning. It makes it so that the total output power (not directly the sample value, i.e. the peak) stays the same no matter how the audio is panned.
This commit is contained in:
parent
8945cc8358
commit
61d9082da6
1 changed files with 11 additions and 7 deletions
|
@ -90,18 +90,22 @@ struct Sample {
|
||||||
return new_frame;
|
return new_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE Sample& log_pan(double const pan)
|
// Constant power panning
|
||||||
|
ALWAYS_INLINE Sample& pan(double const position)
|
||||||
{
|
{
|
||||||
left *= linear_to_log(min(pan * -1 + 1.0, 1.0));
|
double const pi_over_2 = AK::Pi<double> * 0.5;
|
||||||
right *= linear_to_log(min(pan + 1.0, 1.0));
|
double const root_over_2 = AK::sqrt(2.0) * 0.5;
|
||||||
|
double const angle = position * pi_over_2 * 0.5;
|
||||||
|
left *= root_over_2 * (AK::cos(angle) - AK::sin(angle));
|
||||||
|
right *= root_over_2 * (AK::cos(angle) + AK::sin(angle));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE Sample log_pan(double const pan) const
|
ALWAYS_INLINE Sample panned(double const position) const
|
||||||
{
|
{
|
||||||
Sample new_frame { left, right };
|
Sample new_sample { left, right };
|
||||||
new_frame.log_pan(pan);
|
new_sample.pan(position);
|
||||||
return new_frame;
|
return new_sample;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Sample& operator*=(double const mult)
|
constexpr Sample& operator*=(double const mult)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue