diff options
author | Ferran Pujol Camins <ferranpujolcamins@gmail.com> | 2019-06-21 19:53:26 +0200 |
---|---|---|
committer | Ferran Pujol Camins <ferranpujolcamins@gmail.com> | 2019-06-21 19:53:26 +0200 |
commit | db6aadc1370950bf2d2f93b7068a044a4c6aef5a (patch) | |
tree | 54f9bb8a559feb63fd76e70796a260b5ff573cff /lib | |
parent | ab78036ad5364eb746f9a16eada978f4f40aa43a (diff) | |
parent | a2d9300539a57d1f6c9679a2617aa9354fbf2c72 (diff) |
Merge branch 'master' into migrate-to-QJSEngine
Diffstat (limited to 'lib')
85 files changed, 3976 insertions, 54639 deletions
diff --git a/lib/qm-dsp/CONTRIBUTING.md b/lib/qm-dsp/CONTRIBUTING.md index 6f6229e610..00b09d8148 100644 --- a/lib/qm-dsp/CONTRIBUTING.md +++ b/lib/qm-dsp/CONTRIBUTING.md @@ -71,9 +71,11 @@ Code style at the start of a function or class definition where it gets a line of its own - * Please use braces around any conditional or loop block that - occupies its own line + * Please use braces around any conditional or loop block that is not + on the same line as the test -Some of the older code in this library does not follow these -guidelines - usually this means the code needs to be updated. + * Please keep lines to no more than 80 characters in length + + * Avoid using unsigned int types, unless doing bit manipulation (see + http://soundsoftware.ac.uk/c-pitfall-unsigned.html for rationale) diff --git a/lib/qm-dsp/base/KaiserWindow.cpp b/lib/qm-dsp/base/KaiserWindow.cpp index 4fe838e090..306b6aaacd 100644 --- a/lib/qm-dsp/base/KaiserWindow.cpp +++ b/lib/qm-dsp/base/KaiserWindow.cpp @@ -17,27 +17,27 @@ KaiserWindow::Parameters KaiserWindow::parametersForTransitionWidth(double attenuation, - double transition) + double transition) { Parameters p; p.length = 1 + (attenuation > 21.0 ? - ceil((attenuation - 7.95) / (2.285 * transition)) : - ceil(5.79 / transition)); + ceil((attenuation - 7.95) / (2.285 * transition)) : + ceil(5.79 / transition)); p.beta = (attenuation > 50.0 ? - 0.1102 * (attenuation - 8.7) : - attenuation > 21.0 ? - 0.5842 * pow(attenuation - 21.0, 0.4) + 0.07886 * (attenuation - 21.0) : - 0); + 0.1102 * (attenuation - 8.7) : + attenuation > 21.0 ? + 0.5842 * pow(attenuation - 21.0, 0.4) + 0.07886 * (attenuation - 21.0) : + 0); return p; } static double besselTerm(double x, int i) { if (i == 0) { - return 1; + return 1; } else { - double f = MathUtilities::factorial(i); - return pow(x/2, i*2) / (f*f); + double f = MathUtilities::factorial(i); + return pow(x/2, i*2) / (f*f); } } @@ -45,7 +45,7 @@ static double bessel0(double x) { double b = 0.0; for (int i = 0; i < 20; ++i) { - b += besselTerm(x, i); + b += besselTerm(x, i); } return b; } @@ -56,8 +56,8 @@ KaiserWindow::init() double denominator = bessel0(m_beta); bool even = (m_length % 2 == 0); for (int i = 0; i < (even ? m_length/2 : (m_length+1)/2); ++i) { - double k = double(2*i) / double(m_length-1) - 1.0; - m_window.push_back(bessel0(m_beta * sqrt(1.0 - k*k)) / denominator); + double k = double(2*i) / double(m_length-1) - 1.0; + m_window.push_back(bessel0(m_beta * sqrt(1.0 - k*k)) / denominator); } for (int i = 0; i < (even ? m_length/2 : (m_length-1)/2); ++i) { m_window.push_back(m_window[int(m_length/2) - i - 1]); diff --git a/lib/qm-dsp/base/KaiserWindow.h b/lib/qm-dsp/base/KaiserWindow.h index f16a4b6c16..23afe8c687 100644 --- a/lib/qm-dsp/base/KaiserWindow.h +++ b/lib/qm-dsp/base/KaiserWindow.h @@ -11,8 +11,8 @@ COPYING included with this distribution for more information. */ -#ifndef KAISER_WINDOW_H -#define KAISER_WINDOW_H +#ifndef QM_DSP_KAISER_WINDOW_H +#define QM_DSP_KAISER_WINDOW_H #include <vector> #include <cmath> @@ -26,8 +26,8 @@ class KaiserWindow { public: struct Parameters { - int length; - double beta; + int length; + double beta; }; /** @@ -41,9 +41,9 @@ public: * and transition width in samples. */ static KaiserWindow byTransitionWidth(double attenuation, - double transition) { - return KaiserWindow - (parametersForTransitionWidth(attenuation, transition)); + double transition) { + return KaiserWindow + (parametersForTransitionWidth(attenuation, transition)); } /** @@ -51,10 +51,10 @@ public: * and transition bandwidth in Hz for the given samplerate. */ static KaiserWindow byBandwidth(double attenuation, - double bandwidth, - double samplerate) { - return KaiserWindow - (parametersForBandwidth(attenuation, bandwidth, samplerate)); + double bandwidth, + double samplerate) { + return KaiserWindow + (parametersForBandwidth(attenuation, bandwidth, samplerate)); } /** @@ -62,7 +62,7 @@ public: * given attenuation in dB and transition width in samples. */ static Parameters parametersForTransitionWidth(double attenuation, - double transition); + double transition); /** * Obtain the parameters necessary for a Kaiser window of the @@ -70,28 +70,28 @@ public: * given samplerate. */ static Parameters parametersForBandwidth(double attenuation, - double bandwidth, - double samplerate) { - return parametersForTransitionWidth - (attenuation, (bandwidth * 2 * M_PI) / samplerate); + double bandwidth, + double samplerate) { + return parametersForTransitionWidth + (attenuation, (bandwidth * 2 * M_PI) / samplerate); } int getLength() const { - return m_length; + return m_length; } const double *getWindow() const { - return m_window.data(); + return m_window.data(); } void cut(double *src) const { - cut(src, src); + cut(src, src); } void cut(const double *src, double *dst) const { - for (int i = 0; i < m_length; ++i) { - dst[i] = src[i] * m_window[i]; - } + for (int i = 0; i < m_length; ++i) { + dst[i] = src[i] * m_window[i]; + } } private: diff --git a/lib/qm-dsp/base/Pitch.cpp b/lib/qm-dsp/base/Pitch.cpp index 9ba8b4b3f7..2b8fd8b9bd 100644 --- a/lib/qm-dsp/base/Pitch.cpp +++ b/lib/qm-dsp/base/Pitch.cpp @@ -18,8 +18,8 @@ float Pitch::getFrequencyForPitch(int midiPitch, - float centsOffset, - float concertA) + float centsOffset, + float concertA) { float p = float(midiPitch) + (centsOffset / 100); return concertA * powf(2.0, (p - 69.0) / 12.0); @@ -27,8 +27,8 @@ Pitch::getFrequencyForPitch(int midiPitch, int Pitch::getPitchForFrequency(float frequency, - float *centsOffsetReturn, - float concertA) + float *centsOffsetReturn, + float concertA) { float p = 12.0 * (log(frequency / (concertA / 2.0)) / log(2.0)) + 57.0; @@ -36,8 +36,8 @@ Pitch::getPitchForFrequency(float frequency, float centsOffset = (p - midiPitch) * 100.0; if (centsOffset >= 50.0) { - midiPitch = midiPitch + 1; - centsOffset = -(100.0 - centsOffset); + midiPitch = midiPitch + 1; + centsOffset = -(100.0 - centsOffset); } if (centsOffsetReturn) *centsOffsetReturn = centsOffset; diff --git a/lib/qm-dsp/base/Pitch.h b/lib/qm-dsp/base/Pitch.h index 5b55ecc4a3..3a564c30c6 100644 --- a/lib/qm-dsp/base/Pitch.h +++ b/lib/qm-dsp/base/Pitch.h @@ -12,8 +12,8 @@ COPYING included with this distribution for more information. */ -#ifndef _PITCH_H_ -#define _PITCH_H_ +#ifndef QM_DSP_PITCH_H +#define QM_DSP_PITCH_H /** * Convert between musical pitch (i.e. MIDI pitch number) and @@ -23,12 +23,12 @@ class Pitch { public: static float getFrequencyForPitch(int midiPitch, - float centsOffset = 0, - float concertA = 440.0); + float centsOffset = 0, + float concertA = 440.0); static int getPitchForFrequency(float frequency, - float *centsOffsetReturn = 0, - float concertA = 440.0); + float *centsOffsetReturn = 0, + float concertA = 440.0); }; diff --git a/lib/qm-dsp/base/Restrict.h b/lib/qm-dsp/base/Restrict.h index 723a8b3b67..47e1636721 100644 --- a/lib/qm-dsp/base/Restrict.h +++ b/lib/qm-dsp/base/Restrict.h @@ -1,17 +1,18 @@ -
-#ifndef QM_DSP_RESTRICT_H
-#define QM_DSP_RESTRICT_H
-
-#ifdef _MSC_VER
-#define QM_R__ __restrict
-#endif
-
-#ifdef __GNUC__
-#define QM_R__ __restrict__
-#endif
-
-#ifndef QM_R__
-#define QM_R__
-#endif
-
-#endif
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +#ifndef QM_DSP_RESTRICT_H +#define QM_DSP_RESTRICT_H + +#ifdef _MSC_VER +#define QM_R__ __restrict +#endif + +#ifdef __GNUC__ +#define QM_R__ __restrict__ +#endif + +#ifndef QM_R__ +#define QM_R__ +#endif + +#endif diff --git a/lib/qm-dsp/base/SincWindow.cpp b/lib/qm-dsp/base/SincWindow.cpp index 5d31a631e3..0a795e535f 100644 --- a/lib/qm-dsp/base/SincWindow.cpp +++ b/lib/qm-dsp/base/SincWindow.cpp @@ -19,27 +19,27 @@ void SincWindow::init() { if (m_length < 1) { - return; + return; } else if (m_length < 2) { - m_window.push_back(1); - return; + m_window.push_back(1); + return; } else { - int n0 = (m_length % 2 == 0 ? m_length/2 : (m_length - 1)/2); - int n1 = (m_length % 2 == 0 ? m_length/2 : (m_length + 1)/2); - double m = 2 * M_PI / m_p; + int n0 = (m_length % 2 == 0 ? m_length/2 : (m_length - 1)/2); + int n1 = (m_length % 2 == 0 ? m_length/2 : (m_length + 1)/2); + double m = 2 * M_PI / m_p; - for (int i = 0; i < n0; ++i) { - double x = ((m_length / 2) - i) * m; - m_window.push_back(sin(x) / x); - } + for (int i = 0; i < n0; ++i) { + double x = ((m_length / 2) - i) * m; + m_window.push_back(sin(x) / x); + } - m_window.push_back(1.0); + m_window.push_back(1.0); - for (int i = 1; i < n1; ++i) { - double x = i * m; - m_window.push_back(sin(x) / x); - } + for (int i = 1; i < n1; ++i) { + double x = i * m; + m_window.push_back(sin(x) / x); + } } } diff --git a/lib/qm-dsp/base/SincWindow.h b/lib/qm-dsp/base/SincWindow.h index bb35d90c20..324639a598 100644 --- a/lib/qm-dsp/base/SincWindow.h +++ b/lib/qm-dsp/base/SincWindow.h @@ -11,8 +11,8 @@ COPYING included with this distribution for more information. */ -#ifndef SINC_WINDOW_H -#define SINC_WINDOW_H +#ifndef QM_DSP_SINC_WINDOW_H +#define QM_DSP_SINC_WINDOW_H #include <vector> @@ -33,21 +33,21 @@ public: SincWindow(int length, double p) : m_length(length), m_p(p) { init(); } int getLength() const { - return m_length; + return m_length; } const double *getWindow() const { - return m_window.data(); + return m_window.data(); } void cut(double *src) const { - cut(src, src); + cut(src, src); } void cut(const double *src, double *dst) const { - for (int i = 0; i < m_length; ++i) { - dst[i] = src[i] * m_window[i]; - } + for (int i = 0; i < m_length; ++i) { + dst[i] = src[i] * m_window[i]; + } } |