mirror of
https://github.com/LMMS/lmms.git
synced 2025-12-25 15:48:40 -05:00
* use c++ std::* math functions This updates usages of sin, cos, tan, pow, exp, log, log10, sqrt, fmod, fabs, and fabsf, excluding any usages that look like they might be part of a submodule or 3rd-party code. There's probably some std math functions not listed here that haven't been updated yet. * fix std::sqrt typo lmao one always sneaks by * Apply code review suggestions - std::pow(2, x) -> std::exp2(x) - std::pow(10, x) -> lmms::fastPow10f(x) - std::pow(x, 2) -> x * x, std::pow(x, 3) -> x * x * x, etc. - Resolve TODOs, fix typos, and so forth Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * Fix double -> float truncation, DrumSynth fix I mistakenly introduced a bug in my recent PR regarding template constants, in which a -1 that was supposed to appear outside of an abs() instead was moved inside it, screwing up the generated waveform. I fixed that and also simplified the function by factoring out the phase domain wrapping using the new `ediv()` function from this PR. It should behave how it's supposed to now... assuming all my parentheses are in the right place lol * Annotate magic numbers with TODOs for C++20 * On second thought, why wait? What else is lmms::numbers for? * begone inline Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * begone other inline Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> * Re-inline function in lmms_math.h For functions, constexpr implies inline so this just re-adds inline to the one that isn't constexpr yet * Formatting fixes, readability improvements Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Fix previously missed pow() calls, cleanup Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Just delete ediv() entirely lmao No ediv(), no std::fmod(), no std::remainder(), just std::floor(). It should all work for negative phase inputs as well. If I end up needing ediv() in the future, I can add it then. * Simplify DrumSynth triangle waveform This reuses more work and is also a lot more easy to visualize. It's probably a meaningless micro-optimization, but it might be worth changing it back to a switch-case and just calculating ph_tau and saw01 at the beginning of the function in all code paths, even if it goes unused for the first two cases. Guess I'll see if anybody has strong opinions about it. * Move multiplication inside abs() * Clean up a few more pow(x, 2) -> x * x * Remove numbers::inv_pi, numbers::inv_tau * delete spooky leading 0 Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> --------- Co-authored-by: Rossmaxx <74815851+Rossmaxx@users.noreply.github.com> Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
153 lines
3.2 KiB
C++
Executable File
153 lines
3.2 KiB
C++
Executable File
/*
|
|
* Compressor.h
|
|
*
|
|
* Copyright (c) 2020 Lost Robot <r94231@gmail.com>
|
|
*
|
|
* This file is part of LMMS - https://lmms.io
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program (see COPYING); if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
* Boston, MA 02110-1301 USA.
|
|
*
|
|
*/
|
|
|
|
|
|
#ifndef COMPRESSOR_H
|
|
#define COMPRESSOR_H
|
|
|
|
#include "CompressorControls.h"
|
|
|
|
#include "Effect.h"
|
|
|
|
|
|
namespace lmms
|
|
{
|
|
|
|
|
|
constexpr float COMP_LOG = -2.2f;
|
|
|
|
class CompressorEffect : public Effect
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
CompressorEffect(Model* parent, const Descriptor::SubPluginFeatures::Key* key);
|
|
~CompressorEffect() override = default;
|
|
|
|
ProcessStatus processImpl(SampleFrame* buf, const fpp_t frames) override;
|
|
void processBypassedImpl() override;
|
|
|
|
EffectControls* controls() override
|
|
{
|
|
return &m_compressorControls;
|
|
}
|
|
|
|
private slots:
|
|
void calcAutoMakeup();
|
|
void calcAttack();
|
|
void calcRelease();
|
|
void calcAutoAttack();
|
|
void calcAutoRelease();
|
|
void calcHold();
|
|
void calcOutGain();
|
|
void calcRatio();
|
|
void calcRange();
|
|
void resizeRMS();
|
|
void calcLookaheadLength();
|
|
void calcThreshold();
|
|
void calcKnee();
|
|
void calcInGain();
|
|
void calcTiltCoeffs();
|
|
void calcMix();
|
|
void changeSampleRate();
|
|
void redrawKnee();
|
|
|
|
private:
|
|
CompressorControls m_compressorControls;
|
|
|
|
float msToCoeff(float ms);
|
|
|
|
inline void calcTiltFilter(sample_t inputSample, sample_t &outputSample, int filtNum);
|
|
|
|
enum class StereoLinkMode { Unlinked, Maximum, Average, Minimum, Blend };
|
|
|
|
std::array<std::vector<float>, 2> m_inLookBuf;
|
|
std::array<std::vector<float>, 2> m_scLookBuf;
|
|
int m_lookWrite;
|
|
int m_lookBufLength;
|
|
|
|
float m_attCoeff;
|
|
float m_relCoeff;
|
|
float m_autoAttVal;
|
|
float m_autoRelVal;
|
|
|
|
int m_holdLength = 0;
|
|
int m_holdTimer[2] = {0, 0};
|
|
|
|
int m_lookaheadLength;
|
|
float m_thresholdAmpVal;
|
|
float m_autoMakeupVal;
|
|
float m_outGainVal;
|
|
float m_inGainVal;
|
|
float m_rangeVal;
|
|
float m_tiltVal;
|
|
float m_mixVal;
|
|
|
|
float m_coeffPrecalc;
|
|
|
|
SampleFrame m_maxLookaheadVal;
|
|
|
|
int m_maxLookaheadTimer[2] = {1, 1};
|
|
|
|
float m_rmsTimeConst;
|
|
float m_rmsVal[2] = {0, 0};
|
|
|
|
float m_crestPeakVal[2] = {0, 0};
|
|
float m_crestRmsVal[2] = {0, 0};
|
|
float m_crestFactorVal[2] = {0, 0};
|
|
float m_crestTimeConst;
|
|
|
|
float m_tiltOut[2] = {0};
|
|
|
|
bool m_cleanedBuffers = false;
|
|
|
|
float m_sampleRate;
|
|
|
|
float m_lgain;
|
|
float m_hgain;
|
|
float m_a0;
|
|
float m_b1;
|
|
|
|
float m_prevOut[2] = {0};
|
|
|
|
float m_yL[2];
|
|
float m_gainResult[2];
|
|
float m_displayPeak[2];
|
|
float m_displayGain[2];
|
|
|
|
float m_kneeVal;
|
|
float m_thresholdVal;
|
|
float m_ratioVal;
|
|
|
|
bool m_redrawKnee = true;
|
|
bool m_redrawThreshold = true;
|
|
|
|
friend class CompressorControls;
|
|
friend class gui::CompressorControlDialog;
|
|
} ;
|
|
|
|
|
|
} // namespace lmms
|
|
|
|
#endif
|