1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2019 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #ifndef SAMPLEUTILS_H
26 #define SAMPLEUTILS_H
27 
28 #include "basetypes.h"
29 
30 class SampleUtils
31 {
32 public:
33     SampleUtils();
34 
35     static QByteArray resampleMono(QByteArray data, double echInit, quint32 echFinal, quint16 wBps);
36     static QByteArray bandFilter(QByteArray baData, quint16 wBps, double dwSmplRate, double fBas, double fHaut, int ordre);
37     static QByteArray cutFilter(QByteArray baData, quint32 dwSmplRate, QVector<double> dValues, quint16 wBps, int maxFreq);
38     static QByteArray EQ(QByteArray baData, quint32 dwSmplRate, quint16 wBps, int i1, int i2, int i3, int i4, int i5,
39                          int i6, int i7, int i8, int i9, int i10);
40     static QByteArray bpsConversion(QByteArray baData, quint16 wBpsInit, quint16 wBpsFinal, bool bigEndian = false);
41     static void bpsConversion(char *cDest, const char *cFrom, qint32 size, quint16 wBpsInit, quint16 wBpsFinal, bool bigEndian = false);
42     static QByteArray from2MonoTo1Stereo(QByteArray baData1, QByteArray baData2, quint16 wBps, bool bigEndian = false);
43     static Complex * fromBaToComplex(QByteArray baData, quint16 wBps, quint32 &size);
44     static Complex * fromBaToComplex(QVector<float> fData, quint32 &size);
45     static QByteArray fromComplexToBa(Complex * cpxData, int size, quint16 wBps);
46     static QVector<float> getFourierTransform(QVector<float> input);
47     static QByteArray normaliser(QByteArray baData, double dVal, quint16 wBps, double &db);
48     static QByteArray multiplier(QByteArray baData, double dMult, quint16 wBps, double &db);
49     static QByteArray enleveBlanc(QByteArray baData, float seuil, quint16 wBps, quint32 &pos);
50     static void regimePermanent(QByteArray baData, quint32 dwSmplRate, quint16 wBps, quint32 &posStart, quint32 &posEnd);
51     static void regimePermanent(QVector<float> fData, quint32 dwSmplRate, quint32 &posStart, quint32 &posEnd);
52     static QVector<float> correlation(const float *fData, quint32 size, quint32 dwSmplRate, quint32 fMin, quint32 fMax, quint32 &dMin);
53     static float correlation(const float *fData1, const float *fData2, quint32 length, float *bestValue);
54     static QByteArray loop(QByteArray baData, quint32 dwSmplRate, quint32 &loopStart, quint32 &loopEnd, quint16 wBps);
55     static QList<quint32> findMins(QVector<float> vectData, int maxNb, float minFrac = 0);
56     static QList<quint32> findMax(QVector<float> vectData, int maxNb, float minFrac = 0);
57     static qint32 max(QByteArray baData, quint16 wBps);
58     static double moyenneCarre(QByteArray baData, quint16 wBps);
59     static int lastLettersToRemove(QString str1, QString str2);
60 
61 private:
62     static void FFT_calculate(Complex * x, quint32 N /* must be a power of 2 */,
63                               Complex * X, Complex * scratch, Complex * twiddles);
64     static double moyenne(QByteArray baData, quint16 wBps);
65     static double gainEQ(double freq, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10);
66     static float mediane(QVector<float> data);
67     static qint64 somme(QByteArray baData, quint16 wBps);
68     static qint64 sommeCarre(QByteArray baData, quint16 wBps);
69     static void regimePermanent(QVector<float> data, quint32 dwSmplRate, quint32 &posStart, quint32 &posEnd, quint32 nbOK, float coef);
70     static double sinc(double x);
71     static void KBDWindow(double* window, int size, double alpha);
72     static double BesselI0(double x);
73     static Complex * FFT(Complex * x, quint32 N); // N must be a power of 2
74     static Complex * IFFT(Complex * x, quint32 N); // N must be a power of 2
75 };
76 
77 #endif // SAMPLEUTILS_H
78