-
Notifications
You must be signed in to change notification settings - Fork 7
/
buffers.cpp
executable file
·175 lines (137 loc) · 5.22 KB
/
buffers.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "buffers.h"
/***************************************************************************
* *
* This code is distribuited under LGPL v2.1 *
* *
* QAudioLib by Andrea993 *
* *
***************************************************************************/
/*
******QAudioLibBuffer******
*/
const QAudioLibBuffer::DefaultAudioFormat QAudioLibBuffer::DEFAULT_FORMAT;
QAudioLibBuffer QAudioLibBuffer::operator<<(const QAudioLibBuffer &x) const
{
QAudioLibBuffer y(this->frameCount()+x.frameCount());
memcpy(y.data(),this->constData(),this->byteCount());
memcpy(y.data()+this->frameCount(),x.constData(),x.byteCount());
return y;
}
QAudioLibBuffer QAudioLibBuffer::operator+(const QAudioLibBuffer &x) const
{
const QAudioLibBuffer* shortb=(this->frameCount()<=x.frameCount()) ? this : &x;
const QAudioLibBuffer* longb=(this->frameCount()>=x.frameCount()) ? &x : this;
QAudioLibBuffer y(longb->frameCount());
for(int i=0;i<shortb->frameCount();i++)
{
y.data()[i].left=shortb->constData()[i].left+longb->constData()[i].left;
y.data()[i].right=shortb->constData()[i].right+longb->constData()[i].right;
}
memcpy(y.data()+shortb->byteCount(),longb->constData(),longb->byteCount()-shortb->byteCount());
return y;
}
QAudioLibBuffer QAudioLibBuffer::operator*(qreal x) const
{
QAudioLibBuffer y(this->frameCount());
for (int i=0;i<y.frameCount();i++)
{
y.data()[i].left=this->constData()[i].left*x;
y.data()[i].right=this->constData()[i].right*x;
}
return y;
}
QAudioLibBuffer QAudioLibBuffer::operator*(const QAudioLibBuffer &x) const
{
const QAudioLibBuffer* shortb=(this->frameCount()<=x.frameCount()) ? this : &x;
const QAudioLibBuffer* longb=(this->frameCount()>=x.frameCount()) ? &x : this;
QAudioLibBuffer y(longb->frameCount());
for(int i=0;i<shortb->frameCount();i++)
{
y.data()[i].left=shortb->constData()[i].left*longb->constData()[i].left;
y.data()[i].right=shortb->constData()[i].right*longb->constData()[i].right;
}
memcpy(y.data()+shortb->byteCount(),longb->constData(),longb->byteCount()-shortb->byteCount());
return y;
}
QAudioLibBuffer QAudioLibBuffer::subBuffer(int k0, int k1) const
{
QAudioLibBuffer y(qAbs(k0-k1)+1);
int k=qMin(k0,k1);
for (int i=0;i<y.frameCount();i++)
{
y.data()[i].left=this->constData()[i+k].left;
y.data()[i].right=this->constData()[i+k].right;
}
return y;
}
/*
******QAudioLibFreqBuffer******
*/
QAudioLibFreqBuffer QAudioLibFreqBuffer::newByRealBuffer(const QAudioLibBuffer & x)
{
QAudioLibFreqBuffer y(x.frameCount());
for(int i=0;i<x.frameCount();i++)
{
y.data()[i].left=qcomplex(x.constData()[i].left);
y.data()[i].right=qcomplex(x.constData()[i].right);
}
return y;
}
QAudioLibFreqBuffer QAudioLibFreqBuffer::operator*(const QAudioLibFreqBuffer &x)
{
const QAudioLibFreqBuffer* shortb=(this->frameCount()<=x.frameCount()) ? this : &x;
const QAudioLibFreqBuffer* longb=(this->frameCount()>=x.frameCount()) ? &x : this;
QAudioLibFreqBuffer y(longb->frameCount());
for(int i=0;i<shortb->frameCount();i++)
{
y.data()[i].left=shortb->constData()[i].left*longb->constData()[i].left;
y.data()[i].right=shortb->constData()[i].right*longb->constData()[i].right;
}
memcpy(y.data()+shortb->byteCount(),longb->constData(),longb->byteCount()-shortb->byteCount());
return y;
}
void QAudioLibFreqBuffer::operator=(const QAudioLibFreqBuffer &x)
{
_zdata.resize(x.frameCount());
memcpy(this->data(),x.constData(),x.byteCount());
}
QAudioLibFreqBuffer QAudioLibFreqBuffer::operator*(const qreal x)
{
QAudioLibFreqBuffer y(this->frameCount());
for (int i=0;i<y.frameCount();i++)
{
y.data()[i].left=this->constData()[i].left*x;
y.data()[i].right=this->constData()[i].right*x;
}
return y;
}
QAudioLibFreqBuffer QAudioLibFreqBuffer::mod() const
{
QAudioLibFreqBuffer y(this->frameCount());
for(int i=0;i<y.frameCount();i++)
{
y.data()[i].left=abs(this->constData()[i].left);
y.data()[i].right=abs(this->constData()[i].right);
}
return y;
}
QAudioLibFreqBuffer QAudioLibFreqBuffer::phase() const
{
QAudioLibFreqBuffer y(this->frameCount());
for(int i=0;i<y.frameCount();i++)
{
y.data()[i].left=atan2(this->constData()[i].left.imag(),this->constData()[i].left.real());
y.data()[i].right=atan2(this->constData()[i].right.imag(),this->constData()[i].right.real());
}
return y;
}
QAudioLibFreqBuffer QAudioLibFreqBuffer::conj() const
{
QAudioLibFreqBuffer y(this->frameCount());
for(int i=0;i<y.frameCount();i++)
{
y.data()[i].left=std::conj(this->constData()[i].left);
y.data()[i].right=std::conj(this->constData()[i].right);
}
return y;
}