Skip to content

Commit

Permalink
Use sqrt() in pan law
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Nov 28, 2017
1 parent b890a76 commit 89233e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/amuse/Voice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class Voice : public Entity
float m_curAuxBVol = 0.f; /**< Current AuxB volume of voice */
float m_userPan = 0.f; /**< User pan of voice */
float m_curPan = 0.f; /**< Current pan of voice */
float m_userSpan = 0.f; /**< User span of voice */
float m_curSpan = 0.f; /**< Current surround pan of voice */
float m_userSpan = -1.f; /**< User span of voice */
float m_curSpan = -1.f; /**< Current surround pan of voice */
float m_curPitchWheel = 0.f; /**< Current normalized wheel value for control */
int32_t m_pitchWheelUp = 600; /**< Up range for pitchwheel control in cents */
int32_t m_pitchWheelDown = 600; /**< Down range for pitchwheel control in cents */
Expand Down
20 changes: 18 additions & 2 deletions lib/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,52 +979,61 @@ void Voice::_panLaw(float coefs[8], float frontPan, float backPan, float totalSp
case AudioChannelSet::Stereo:
default:
/* Left */
coefs[0] = -frontPan * 0.5f + 0.5f;
coefs[0] = std::sqrt(-frontPan * 0.5f + 0.5f);

/* Right */
coefs[1] = frontPan * 0.5f + 0.5f;
coefs[1] = std::sqrt(frontPan * 0.5f + 0.5f);

break;

case AudioChannelSet::Quad:
/* Left */
coefs[0] = -frontPan * 0.5f + 0.5f;
coefs[0] *= -totalSpan * 0.5f + 0.5f;
coefs[0] = std::sqrt(coefs[0]);

/* Right */
coefs[1] = frontPan * 0.5f + 0.5f;
coefs[1] *= -totalSpan * 0.5f + 0.5f;
coefs[1] = std::sqrt(coefs[1]);

/* Back Left */
coefs[2] = -backPan * 0.5f + 0.5f;
coefs[2] *= totalSpan * 0.5f + 0.5f;
coefs[2] = std::sqrt(coefs[2]);

/* Back Right */
coefs[3] = backPan * 0.5f + 0.5f;
coefs[3] *= totalSpan * 0.5f + 0.5f;
coefs[3] = std::sqrt(coefs[3]);

break;

case AudioChannelSet::Surround51:
/* Left */
coefs[0] = (frontPan <= 0.f) ? -frontPan : 0.f;
coefs[0] *= -totalSpan * 0.5f + 0.5f;
coefs[0] = std::sqrt(coefs[0]);

/* Right */
coefs[1] = (frontPan >= 0.f) ? frontPan : 0.f;
coefs[1] *= -totalSpan * 0.5f + 0.5f;
coefs[1] = std::sqrt(coefs[1]);

/* Back Left */
coefs[2] = -backPan * 0.5f + 0.5f;
coefs[2] *= totalSpan * 0.5f + 0.5f;
coefs[2] = std::sqrt(coefs[2]);

/* Back Right */
coefs[3] = backPan * 0.5f + 0.5f;
coefs[3] *= totalSpan * 0.5f + 0.5f;
coefs[3] = std::sqrt(coefs[3]);

/* Center */
coefs[4] = 1.f - std::fabs(frontPan);
coefs[4] *= -totalSpan * 0.5f + 0.5f;
coefs[4] = std::sqrt(coefs[4]);

/* LFE */
coefs[5] = 0.25f;
Expand All @@ -1035,33 +1044,40 @@ void Voice::_panLaw(float coefs[8], float frontPan, float backPan, float totalSp
/* Left */
coefs[0] = (frontPan <= 0.f) ? -frontPan : 0.f;
coefs[0] *= (totalSpan <= 0.f) ? -totalSpan : 0.f;
coefs[0] = std::sqrt(coefs[0]);

/* Right */
coefs[1] = (frontPan >= 0.f) ? frontPan : 0.f;
coefs[1] *= (totalSpan <= 0.f) ? -totalSpan : 0.f;
coefs[1] = std::sqrt(coefs[1]);

/* Back Left */
coefs[2] = -backPan * 0.5f + 0.5f;
coefs[2] *= (totalSpan >= 0.f) ? totalSpan : 0.f;
coefs[2] = std::sqrt(coefs[2]);

/* Back Right */
coefs[3] = backPan * 0.5f + 0.5f;
coefs[3] *= (totalSpan >= 0.f) ? totalSpan : 0.f;
coefs[3] = std::sqrt(coefs[3]);

/* Center */
coefs[4] = 1.f - std::fabs(frontPan);
coefs[4] *= (totalSpan <= 0.f) ? -totalSpan : 0.f;
coefs[4] = std::sqrt(coefs[4]);

/* LFE */
coefs[5] = 0.25f;

/* Side Left */
coefs[6] = -backPan * 0.5f + 0.5f;
coefs[6] *= 1.f - std::fabs(totalSpan);
coefs[6] = std::sqrt(coefs[6]);

/* Side Right */
coefs[7] = backPan * 0.5f + 0.5f;
coefs[7] *= 1.f - std::fabs(totalSpan);
coefs[7] = std::sqrt(coefs[7]);

break;
}
Expand Down

0 comments on commit 89233e9

Please sign in to comment.