Use templates for common geometric constants (#7558)
* add templates for common geometric constants * oops missed one * LD_2PI -> LD_PI i re-added the wrong constant ffs * CamelCase names and also verify compilation without -DLMMS_MINIMAL * C++20 stuff Updated to account for `<numbers>` and C++20: - Marked all `lmms_constants.h` constants with an exact equivalent in `<numbers>` as deprecated - Removed all `lmms_constants.h` constants where no variant is currently in use - Using `inline constexpr` - Using `std::floating_point` concept instead of `typename` * add lmms::numbers namespace * Remove panning_constants.h Moves the four constants in panning_constants.h into panning.h, then removes panning.h. * Use std::exp(n) instead of powf(numbers::e, n) * Use C++ std math functions Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com> * Use overloaded std math functions An attempt to fix compiler warnings on some platforms * Remove uses of __USE_XOPEN And also update two functions I missed from the previous commit * Missed a few * Fix ANOTHER std math function use Of course there's another one --------- Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
@@ -103,8 +103,8 @@ void BandLimitedWave::generateWaves()
|
||||
{
|
||||
hlen = static_cast<double>( len ) / static_cast<double>( harm );
|
||||
const double amp = -1.0 / static_cast<double>( harm );
|
||||
//const double a2 = cos( om * harm * F_2PI );
|
||||
s += amp * /*a2 **/sin( static_cast<double>( ph * harm ) / static_cast<double>( len ) * F_2PI );
|
||||
//const double a2 = std::cos(om * harm * numbers::tau_v<float>);
|
||||
s += amp * /*a2 **/ std::sin(static_cast<double>(ph * harm) / static_cast<double>(len) * numbers::tau_v<float>);
|
||||
harm++;
|
||||
} while( hlen > 2.0 );
|
||||
s_waveforms[static_cast<std::size_t>(BandLimitedWave::Waveform::BLSaw)].setSampleAt( i, ph, s );
|
||||
@@ -145,8 +145,8 @@ void BandLimitedWave::generateWaves()
|
||||
{
|
||||
hlen = static_cast<double>( len ) / static_cast<double>( harm );
|
||||
const double amp = 1.0 / static_cast<double>( harm );
|
||||
//const double a2 = cos( om * harm * F_2PI );
|
||||
s += amp * /*a2 **/ sin( static_cast<double>( ph * harm ) / static_cast<double>( len ) * F_2PI );
|
||||
//const double a2 = std::cos(om * harm * numbers::tau_v<float>);
|
||||
s += amp * /*a2 **/ std::sin(static_cast<double>(ph * harm) / static_cast<double>(len) * numbers::tau_v<float>);
|
||||
harm += 2;
|
||||
} while( hlen > 2.0 );
|
||||
s_waveforms[static_cast<std::size_t>(BandLimitedWave::Waveform::BLSquare)].setSampleAt( i, ph, s );
|
||||
@@ -186,9 +186,9 @@ void BandLimitedWave::generateWaves()
|
||||
{
|
||||
hlen = static_cast<double>( len ) / static_cast<double>( harm );
|
||||
const double amp = 1.0 / static_cast<double>( harm * harm );
|
||||
//const double a2 = cos( om * harm * F_2PI );
|
||||
s += amp * /*a2 **/ sin( ( static_cast<double>( ph * harm ) / static_cast<double>( len ) +
|
||||
( ( harm + 1 ) % 4 == 0 ? 0.5 : 0.0 ) ) * F_2PI );
|
||||
//const double a2 = std::cos(om * harm * numbers::tau_v<float>);
|
||||
s += amp * /*a2 **/ std::sin((static_cast<double>(ph * harm) / static_cast<double>(len) +
|
||||
((harm + 1) % 4 == 0 ? 0.5 : 0.0)) * numbers::tau_v<float>);
|
||||
harm += 2;
|
||||
} while( hlen > 2.0 );
|
||||
s_waveforms[static_cast<std::size_t>(BandLimitedWave::Waveform::BLTriangle)].setSampleAt( i, ph, s );
|
||||
@@ -273,4 +273,4 @@ moogfile.close();
|
||||
|
||||
}
|
||||
|
||||
} // namespace lmms
|
||||
} // namespace lmms
|
||||
|
||||
@@ -152,7 +152,7 @@ void Instrument::applyFadeIn(SampleFrame* buf, NotePlayHandle * n)
|
||||
{
|
||||
for (ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch)
|
||||
{
|
||||
buf[offset + f][ch] *= 0.5 - 0.5 * cosf(F_PI * (float) f / (float) n->m_fadeInLength);
|
||||
buf[offset + f][ch] *= 0.5 - 0.5 * std::cos(numbers::pi_v<float> * (float) f / (float) n->m_fadeInLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ void Instrument::applyFadeIn(SampleFrame* buf, NotePlayHandle * n)
|
||||
for (ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch)
|
||||
{
|
||||
float currentLength = n->m_fadeInLength * (1.0f - (float) f / frames) + new_length * ((float) f / frames);
|
||||
buf[f][ch] *= 0.5 - 0.5 * cosf(F_PI * (float) (total + f) / currentLength);
|
||||
buf[f][ch] *= 0.5 - 0.5 * std::cos(numbers::pi_v<float> * (float) (total + f) / currentLength);
|
||||
if (total + f >= currentLength)
|
||||
{
|
||||
n->m_fadeInLength = currentLength;
|
||||
|
||||
@@ -127,7 +127,7 @@ void Oscillator::generateSawWaveTable(int bands, sample_t* table, int firstBand)
|
||||
const float imod = (i - OscillatorConstants::WAVETABLE_LENGTH / 2.f) / OscillatorConstants::WAVETABLE_LENGTH;
|
||||
for (int n = firstBand; n <= bands; n++)
|
||||
{
|
||||
table[i] += (n % 2 ? 1.0f : -1.0f) / n * sinf(F_2PI * n * imod) / F_PI_2;
|
||||
table[i] += (n % 2 ? 1.0f : -1.0f) / n * std::sin(numbers::tau_v<float> * n * imod) / numbers::pi_half_v<float>;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ void Oscillator::generateTriangleWaveTable(int bands, sample_t* table, int first
|
||||
for (int n = firstBand | 1; n <= bands; n += 2)
|
||||
{
|
||||
table[i] += (n & 2 ? -1.0f : 1.0f) / powf(n, 2.0f) *
|
||||
sinf(F_2PI * n * i / (float)OscillatorConstants::WAVETABLE_LENGTH) / (F_PI_SQR / 8);
|
||||
std::sin(numbers::tau_v<float> * n * i / (float)OscillatorConstants::WAVETABLE_LENGTH) / (numbers::pi_sqr_v<float> / 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,9 @@ void Oscillator::generateSquareWaveTable(int bands, sample_t* table, int firstBa
|
||||
{
|
||||
for (int n = firstBand | 1; n <= bands; n += 2)
|
||||
{
|
||||
table[i] += (1.0f / n) * sinf(F_2PI * i * n / OscillatorConstants::WAVETABLE_LENGTH) / (F_PI / 4);
|
||||
table[i] += (1.0f / n)
|
||||
* std::sin(numbers::tau_v<float> * i * n / OscillatorConstants::WAVETABLE_LENGTH)
|
||||
/ (numbers::pi_v<float> / 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,9 +144,9 @@ int precomputeWindow(float *window, unsigned int length, FFTWindow type, bool no
|
||||
// common computation for cosine-sum based windows
|
||||
for (unsigned int i = 0; i < length; i++)
|
||||
{
|
||||
window[i] = (a0 - a1 * cos(2 * F_PI * i / ((float)length - 1.0))
|
||||
+ a2 * cos(4 * F_PI * i / ((float)length - 1.0))
|
||||
- a3 * cos(6 * F_PI * i / ((float)length - 1.0)));
|
||||
window[i] = (a0 - a1 * std::cos(2 * numbers::pi_v<float> * i / ((float)length - 1.0))
|
||||
+ a2 * std::cos(4 * numbers::pi_v<float> * i / ((float)length - 1.0))
|
||||
- a3 * std::cos(6 * numbers::pi_v<float> * i / ((float)length - 1.0)));
|
||||
gain += window[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,6 @@
|
||||
#include "SampleClip.h"
|
||||
#include "SampleWaveform.h"
|
||||
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN
|
||||
#endif
|
||||
|
||||
#include "ActionGroup.h"
|
||||
#include "AutomationNode.h"
|
||||
#include "ComboBox.h"
|
||||
|
||||
@@ -41,10 +41,6 @@
|
||||
#include <QStyleOption>
|
||||
#include <QToolButton>
|
||||
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
|
||||
@@ -29,10 +29,6 @@
|
||||
#include <QInputDialog>
|
||||
#include <QPainter>
|
||||
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN
|
||||
#endif
|
||||
|
||||
#include "lmms_math.h"
|
||||
#include "CaptionMenu.h"
|
||||
#include "ControllerConnection.h"
|
||||
|
||||
@@ -25,15 +25,10 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN
|
||||
#endif
|
||||
|
||||
#include "GroupBox.h"
|
||||
#include "embed.h"
|
||||
#include "FontHelper.h"
|
||||
|
||||
|
||||
namespace lmms::gui
|
||||
{
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#ifndef __USE_XOPEN
|
||||
#define __USE_XOPEN
|
||||
#endif
|
||||
|
||||
#include "lmms_math.h"
|
||||
#include "DeprecationHelper.h"
|
||||
#include "embed.h"
|
||||
@@ -316,7 +312,7 @@ void Knob::setTextColor( const QColor & c )
|
||||
|
||||
QLineF Knob::calculateLine( const QPointF & _mid, float _radius, float _innerRadius ) const
|
||||
{
|
||||
const float rarc = m_angle * F_PI / 180.0;
|
||||
const float rarc = m_angle * numbers::pi_v<float> / 180.0;
|
||||
const float ca = cos( rarc );
|
||||
const float sa = -sin( rarc );
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "EffectChain.h"
|
||||
#include "Mixer.h"
|
||||
#include "panning_constants.h"
|
||||
#include "panning.h"
|
||||
#include "PatternStore.h"
|
||||
#include "PatternTrack.h"
|
||||
#include "SampleClip.h"
|
||||
|
||||
Reference in New Issue
Block a user