-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmathematics.h
executable file
·75 lines (59 loc) · 2.39 KB
/
mathematics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/***************************************************************************
* *
* This code is distribuited under LGPL v2.1 *
* *
* QAudioLib by Andrea993 *
* *
***************************************************************************/
#ifndef MATHEMATICS_H
#define MATHEMATICS_H
#include "buffers.h"
#include <qmath.h>
#include <limits>
#include <QObject>
class Mathematics
{
public:
explicit Mathematics(QObject *parent = 0);
/******SOUND GENERATION******/
//Generate some waves with freq f and duration sec
static QAudioLibBuffer sinwave(qreal f, qreal sec);
static QAudioLibBuffer squarewave(qreal f, qreal sec);
/******SOUND MANIPULATION******/
//Convolution of 2 signal
static QAudioLibBuffer conv(QAudioLibBuffer &u ,QAudioLibBuffer &v);
//Correlation of 2 signal
static QAudioLibBuffer corr(QAudioLibBuffer &u ,QAudioLibBuffer &v);
//FIR with hanning window (type can be 'l': lowpass, 'h' highpass, 'b' bandpass) set f1 only for bandpass filters
static QAudioLibBuffer filter(QAudioLibBuffer &x, int N, char type, int f0, int f1=0);
/******FREQUENCY DOMAIN******/
//dft of a power of 2 length signal
static QAudioLibFreqBuffer fft(const QAudioLibFreqBuffer & x);
//dft of a generic signal
static QAudioLibFreqBuffer dft(const QAudioLibFreqBuffer & x);
//dft or fft of a QAudioLibFreqBuffer signal
static QAudioLibFreqBuffer fft(const QAudioLibBuffer & x, bool zeropadding=true);
//inverse dft or fft of a signal
static QAudioLibBuffer ifft(const QAudioLibFreqBuffer & x);
private:
static QAudioLibBuffer bandpass(QAudioLibBuffer &x, int N, int f0, int f1);
static void bitreverse(QAudioLibFreqBuffer & x);
static int distanceFromPowerOf2(int n);
static inline void swap(qcomplex & a, qcomplex & b)
{
qcomplex tmp=a;
a=b;
b=tmp;
}
static inline double hanning(qreal t, int N)
{
return 0.5*(1+qCos(M_PI*t/(N-1.0)));
}
static inline double sinc(qreal t)
{
if(t==0)
return 1;
return qSin(M_PI*t)/M_PI/t;
}
};
#endif // MATHEMATICS_H