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

Contents of /branches/qtcharts/optimizer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (show annotations)
Sun Mar 18 21:16:30 2018 UTC (3 years, 6 months ago) by ben
File size: 3573 byte(s)
added bandpass aligment chooser dialog
1 #include <math.h>
2
3 #include "optimizer.h"
4
5 Optimizer::Optimizer(const Speaker& speaker, SealedBox *box, int sibling) :
6 speaker(speaker),
7 box(box),
8 type(BOX_SEALED),
9 sibling(sibling)
10 {
11 }
12
13 Optimizer::Optimizer(const Speaker &speaker, PortedBox *box, int sibling) :
14 speaker(speaker),
15 box(box),
16 type(BOX_PORTED),
17 sibling(sibling)
18 {
19 }
20
21 Optimizer::Optimizer(const Speaker &speaker, BandPassBox *box, int sibling) :
22 speaker(speaker),
23 box(box),
24 type(BOX_BANDPASS),
25 sibling(sibling)
26 {
27 }
28
29 void Optimizer::genericOptimizeBox()
30 {
31 if (type == BOX_SEALED) {
32 SealedBox *b = (SealedBox *)box;
33 double qr = 0.707 / speaker.getQts();
34 double vr = pow(qr, 2.0) - 1;
35 b->setVolume(speaker.getVas() * sibling / vr);
36 } else if (type == BOX_PORTED) {
37 PortedBox *b = (PortedBox *)box;
38 /* approx. "natural max flat", a good starting point */
39 b->setBoxVolume(20 * speaker.getVas() * sibling * pow(speaker.getQts(), 3.3));
40 b->setResFreq(speaker.getFs() * pow(speaker.getVas() * sibling / b->getBoxVolume(), 0.31));
41 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
42 } else {
43 /* default optimization for 0dB ripple (s) and 0dB gain (pa)*/
44 double s = 0.7;
45 double pa = 0.0;
46 bandpassAlignS_Pa(s, pa);
47 }
48 }
49
50 void Optimizer::portedAlignBessel()
51 {
52 PortedBox *b = (PortedBox *)box;
53 b->setBoxVolume(8.0707 * pow(speaker.getQts(), 2.5848) * speaker.getVas() * sibling);
54 b->setResFreq(0.3552 * pow(speaker.getQts(), -0.9649) * speaker.getFs());
55 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
56 }
57
58 void Optimizer::portedAlignBullock()
59 {
60 PortedBox *b = (PortedBox *)box;
61 double qts = speaker.getQts();
62 b->setBoxVolume(qts * speaker.getVas() * sibling * (4.96 * qts - 0.136));
63 b->setResFreq(speaker.getFs());
64 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
65 }
66
67 void Optimizer::portedAlignKeele_Hoge()
68 {
69 PortedBox *b = (PortedBox *)box;
70 b->setBoxVolume(speaker.getVas() * sibling * 5.2358 * pow(speaker.getQts(), 2.1687));
71 b->setResFreq(speaker.getFs());
72 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
73 }
74
75 void Optimizer::portedAlignLegendre()
76 {
77 PortedBox *b = (PortedBox *)box;
78 b->setBoxVolume(10.728 * pow(speaker.getQts(), 2.4186) * speaker.getVas() * sibling);
79 b->setResFreq(0.3802 * pow(speaker.getQts(), -1.0657) * speaker.getFs());
80 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
81 }
82
83 void Optimizer::portedAlignModerate_Inf()
84 {
85 PortedBox *b = (PortedBox *)box;
86 /* use M4 Moderate alignment (see http://www.mzbinden.ch/ventedalignments/index.html) */
87 b->setBoxVolume((2.52 * speaker.getQts() - 0.35) * speaker.getVas() * sibling);
88 b->setResFreq(0.32 * sqrt((1.0/pow(speaker.getQts(), 2.0)) + 3.38) * speaker.getFs());
89 b->updatePorts(speaker.getSd() * sibling, speaker.getXmax());
90 }
91
92 void Optimizer::bandpassAlignS_Pa(double s, double pa)
93 {
94 BandPassBox *b = (BandPassBox *)box;
95 /* see http://www.diysubwoofers.org/bnd/4thord1.htm */
96 double qbp = pow((pow(10.0,(-pa/40.0)) * 2 * s ), -1);
97 double fb = qbp * speaker.getFs() / speaker.getQts();
98 double vf = pow(2 * s * speaker.getQts(), 2) * speaker.getVas() * sibling;
99 double vr = speaker.getVas() * sibling / (pow(qbp / speaker.getQts(), 2) - 1);
100 b->setSealedBoxVolume(vr);
101 b->setPortedBoxVolume(vf);
102 b->setPortedBoxResFreq(fb);
103 b->updatePortedBoxPorts(speaker.getSd() * sibling, speaker.getXmax());
104 }

  ViewVC Help
Powered by ViewVC 1.1.26