/[qspeakers]/system.cpp
ViewVC logotype

Contents of /system.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 118 - (show annotations)
Tue Jun 21 21:18:21 2016 UTC (12 months, 1 week ago) by (unknown author)
File size: 3077 byte(s)
fix sealed box and bandpass box calculation, using log10
1 #include <QDebug>
2
3 #include <math.h>
4
5 #include "system.h"
6 #include "sealedbox.h"
7 #include "portedbox.h"
8 #include "bandpassbox.h"
9
10 #define Q 7 /* common ported box resonance quality loss */
11 #define QL 10000 /* common box losses */
12
13 System::System(const Speaker& s, const SealedBox *b, unsigned int number) :
14 speaker(s),
15 box(b),
16 type(SEALED),
17 sibling(number)
18 {
19 }
20
21 System::System(const Speaker& s, const PortedBox *b, unsigned int number) :
22 speaker(s),
23 box(b),
24 type(PORTED),
25 sibling(number)
26 {
27 }
28
29 System::System(const Speaker& s, const BandPassBox *b, unsigned int number) :
30 speaker(s),
31 box(b),
32 type(BANDPASS),
33 sibling(number)
34 {
35 }
36
37 double System::response(double f)
38 {
39 if (type == SEALED) {
40 SealedBox *b = (SealedBox *)box;
41 double vr = speaker.getVas() * sibling / b->getVolume();
42 double qr = sqrt(vr + 1.0);
43 double qtc = qr * speaker.getQts();
44 double fb = qr * speaker.getFs();
45 double fr = pow(f / fb, 2.0);
46 double db = 10 * log10(pow(fr, 2.0) / (pow(fr - 1, 2.0) + fr/pow(qtc, 2.0)));
47 return db;
48 } else if (type == PORTED) {
49 PortedBox *b = (PortedBox *)box;
50 double A = pow(b->getResFreq() / speaker.getFs(), 2.0);
51 double B = A / speaker.getQts() + b->getResFreq() / (Q * speaker.getFs() * speaker.getQts());
52 double C = 1.0 + A + (speaker.getVas() * sibling / b->getBoxVolume()) + b->getResFreq() /
53 (Q * speaker.getFs() * speaker.getQts());
54 double D = 1.0 / speaker.getQts() + b->getResFreq() / (Q * speaker.getFs());
55 double fn2 = pow(f / speaker.getFs(), 2.0);
56 double fn4 = pow(fn2, 2.0);
57 double db = 10 * log10(pow(fn4, 2.0) / (pow(fn4 - C * fn2 + A, 2.0) + fn2 * pow(D * fn2 - B, 2.0)));
58 return db;
59 } else {
60 BandPassBox *b = (BandPassBox *)box;
61 double A = pow(1.0 / (b->getPortedBoxResFreq()), 2.0) * pow(f, 4.0);
62 double B = ((1 / QL + (speaker.getFs() / b->getPortedBoxResFreq()) / speaker.getQts()) / b->getPortedBoxResFreq()) * pow(f, 3.0);
63 double C = (((1 + speaker.getVas() * sibling / b->getSealedBoxVolume() + speaker.getVas() * sibling / b->getPortedBoxVolume()) *
64 speaker.getFs() / b->getPortedBoxResFreq() + (1 / speaker.getQts()) / QL) * speaker.getFs() / b->getPortedBoxResFreq() + 1) * pow(f, 2.0);
65 double D = ((1 / speaker.getQts() + (speaker.getFs() / b->getPortedBoxResFreq()) / QL * (speaker.getVas() * sibling / b->getSealedBoxVolume() + 1)) *
66 speaker.getFs()) * f;
67 double E = (speaker.getVas() * sibling / b->getSealedBoxVolume() + 1) * pow(speaker.getFs(), 2);
68 double G = A - C + E;
69 double H = -B + D;
70 double db = 20 * log10(pow(f, 2.0) / sqrt(pow(G, 2.0) + pow(H, 2.0)));
71 return db;
72 }
73 }
74
75 void System::render(QPainter *painter, const QRectF& area)
76 {
77
78 QString text = QObject::tr("number of driver(s) is ") + QString::number(sibling);
79 QTextOption option(Qt::AlignLeft);
80 painter->drawText(area, text, option);
81 }

  ViewVC Help
Powered by ViewVC 1.1.26