/[qspeakers]/branches/qtcharts/system.cpp
ViewVC logotype

Contents of /branches/qtcharts/system.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (show annotations)
Thu Apr 5 00:21:47 2018 UTC (3 years, 2 months ago) by ben
File size: 3365 byte(s)
simplify printing method
1 #include <QDebug>
2
3 #include <math.h>
4
5 #include "system.h"
6
7 #define Q 7 /* common ported box resonance quality loss */
8 #define QL 10000 /* common box losses */
9
10 System::System(const Speaker& s, const SealedBox *b, unsigned int number) :
11 speaker(s),
12 box(b),
13 type(BOX_SEALED),
14 sibling(number)
15 {
16 }
17
18 System::System(const Speaker& s, const PortedBox *b, unsigned int number) :
19 speaker(s),
20 box(b),
21 type(BOX_PORTED),
22 sibling(number)
23 {
24 }
25
26 System::System(const Speaker& s, const BandPassBox *b, unsigned int number) :
27 speaker(s),
28 box(b),
29 type(BOX_BANDPASS),
30 sibling(number)
31 {
32 }
33
34 double System::response(double f)
35 {
36 if (type == BOX_SEALED) {
37 SealedBox *b = (SealedBox *)box;
38 double vr = speaker.getVas() * sibling / b->getVolume();
39 double qr = sqrt(vr + 1.0);
40 double qtc = qr * speaker.getQts();
41 double fb = qr * speaker.getFs();
42 double fr = pow(f / fb, 2.0);
43 double db = 10 * log10(pow(fr, 2.0) / (pow(fr - 1, 2.0) + fr/pow(qtc, 2.0)));
44 return db;
45 } else if (type == BOX_PORTED) {
46 PortedBox *b = (PortedBox *)box;
47 double A = pow(b->getResFreq() / speaker.getFs(), 2.0);
48 double B = A / speaker.getQts() + b->getResFreq() / (Q * speaker.getFs() * speaker.getQts());
49 double C = 1.0 + A + (speaker.getVas() * sibling / b->getBoxVolume()) + b->getResFreq() /
50 (Q * speaker.getFs() * speaker.getQts());
51 double D = 1.0 / speaker.getQts() + b->getResFreq() / (Q * speaker.getFs());
52 double fn2 = pow(f / speaker.getFs(), 2.0);
53 double fn4 = pow(fn2, 2.0);
54 double db = 10 * log10(pow(fn4, 2.0) / (pow(fn4 - C * fn2 + A, 2.0) + fn2 * pow(D * fn2 - B, 2.0)));
55 return db;
56 } else {
57 BandPassBox *b = (BandPassBox *)box;
58 double A = pow(1.0 / (b->getPortedBoxResFreq()), 2.0) * pow(f, 4.0);
59 double B = ((1 / QL + (speaker.getFs() / b->getPortedBoxResFreq()) / speaker.getQts()) / b->getPortedBoxResFreq()) * pow(f, 3.0);
60 double C = (((1 + speaker.getVas() * sibling / b->getSealedBoxVolume() + speaker.getVas() * sibling / b->getPortedBoxVolume()) *
61 speaker.getFs() / b->getPortedBoxResFreq() + (1 / speaker.getQts()) / QL) * speaker.getFs() / b->getPortedBoxResFreq() + 1) * pow(f, 2.0);
62 double D = ((1 / speaker.getQts() + (speaker.getFs() / b->getPortedBoxResFreq()) / QL * (speaker.getVas() * sibling / b->getSealedBoxVolume() + 1)) *
63 speaker.getFs()) * f;
64 double E = (speaker.getVas() * sibling / b->getSealedBoxVolume() + 1) * pow(speaker.getFs(), 2);
65 double G = A - C + E;
66 double H = -B + D;
67 double db = 20 * log10(pow(f, 2.0) / sqrt(pow(G, 2.0) + pow(H, 2.0)));
68 return db;
69 }
70 }
71
72 void System::render(QPainter *painter, const QRectF& area)
73 {
74 qreal x1, y1, x2, y2;
75 qreal w, h;
76 area.getCoords(&x1, &y1, &x2, &y2);
77 w = x2 - x1;
78 h = y2 - y1;
79 qreal ytab = h / 3.0;
80
81 QRectF a(x1, y1, w, ytab);
82
83 QString text = QObject::tr("Driver(s) number: ") + QString::number(sibling);
84 QTextOption option(Qt::AlignLeft);
85 painter->drawText(a, text, option);
86
87 y1 += ytab;
88 a.setY(y1);
89 a.setHeight(ytab);
90 speaker.render(painter, a);
91
92 y1 += ytab;
93 a.setY(y1);
94 a.setHeight(ytab);
95 box->render(painter, a);
96 }

  ViewVC Help
Powered by ViewVC 1.1.26