Commit 6aa247d5 authored by Gregor Pintar's avatar Gregor Pintar

Option to disable baffle simulation per speaker, Room simulation disabled by...

Option to disable baffle simulation per speaker, Room simulation disabled by default, off-axis response improvments
parent 9819d02c
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>SpeakerSim</groupId>
<artifactId>SpeakerSim</artifactId>
<version>2019-04-04</version>
<version>2019-04-07</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
......
......@@ -22,6 +22,7 @@ import com.eclipsesource.json.JsonValue;
public class Baffle implements JSONable
{
public boolean Enabled;
public double Width;
public double Height;
public double X;
......@@ -30,6 +31,7 @@ public class Baffle implements JSONable
public Baffle()
{
Enabled = true;
Width = 0.3;
Height = 0.7;
X = 0.15;
......@@ -38,6 +40,7 @@ public class Baffle implements JSONable
public Baffle(double width, double height, double x, double y, double edgeRadius)
{
Enabled = true;
Width = width;
Height = height;
X = x;
......@@ -49,6 +52,7 @@ public class Baffle implements JSONable
{
JsonObject jsonObj = json.asObject();
Enabled = JSON.getBoolean(jsonObj, "Enabled", true);
Width = JSON.getDouble(jsonObj, "Width");
Height = JSON.getDouble(jsonObj, "Height");
X = JSON.getDouble(jsonObj, "X");
......@@ -61,6 +65,7 @@ public class Baffle implements JSONable
{
JsonObject json = Json.object();
json.add("Enabled", Enabled);
json.add("Width", Width);
json.add("Height", Height);
json.add("X", X);
......
......@@ -21,6 +21,7 @@ public class BaffleSimulation
private final double horizontalAngle;
private final double verticalAngle;
private final double angle;
private final boolean enabled;
private final double[] mean;
private final double[] length;
private final double averageWavelength;
......@@ -50,17 +51,20 @@ public class BaffleSimulation
this.dipole = dipole;
angle = Math.max(Math.abs(horizontalAngle), Math.abs(verticalAngle));
if (baffle == null)
if (baffle == null || !baffle.Enabled)
{
mean = null;
length = null;
averageWavelength = 0;
edge = 0;
enabled = baffle == null;
return;
}
double[] edges = new double[36];
enabled = true;
double[] edges = new double[36];
edges[0] = edgeDistance(90, baffle.X, baffle.Y); // 0
edges[1] = edgeDistance(80, baffle.X, baffle.Y); // 10
edges[2] = edgeDistance(70, baffle.X, baffle.Y); // 20
......@@ -169,7 +173,7 @@ public class BaffleSimulation
public Complex response(double f)
{
Complex x = Fnc.toComplex(0.5 * offAxis(f, horizontalAngle, verticalAngle) * diffraction(f), 0);
Complex x = Fnc.toComplex((enabled ? 0.5 : 1) * offAxis(f, horizontalAngle, verticalAngle) * diffraction(f), 0);
// invert phase, if behind dipole
if (dipole && (angle < 270 && angle > 90))
......
......@@ -314,56 +314,87 @@ public class Driver implements JSONable
private double horizontalAxis(double f, double horizontalAngle)
{
double SPLdiff = SPL_2_83V - SPL_1W;
// no lower value
if (hFRD[0].horizontalAngle > horizontalAngle)
{
return hFRD[0].response(f, SPLdiff).abs();
}
for (int i = 1; i < hFRD.length; i++)
// no lower value
if (hFRD[0].horizontalAngle > horizontalAngle)
{
return -hFRD[0].response(f, SPLdiff).abs();
}
for (int i = 1; i < hFRD.length; i++)
{
if (hFRD[i].horizontalAngle >= horizontalAngle)
{
if (hFRD[i].horizontalAngle >= horizontalAngle)
{
return Fnc.interpolate(hFRD[i - 1].horizontalAngle, hFRD[i - 1].response(f, SPLdiff).abs(), hFRD[i].horizontalAngle, hFRD[i].response(f, SPLdiff).abs(), horizontalAngle);
}
return Fnc.interpolate
(
hFRD[i - 1].horizontalAngle,
hFRD[i - 1].response(f, SPLdiff).abs(),
hFRD[i].horizontalAngle,
hFRD[i].response(f, SPLdiff).abs(),
horizontalAngle
);
}
}
// no higher value
return hFRD[0].response(f, SPLdiff).abs();
// no higher value
return -hFRD[vFRD.length - 1].response(f, SPLdiff).abs();
}
private double verticalAxis(double f, double verticalAngle)
{
double SPLdiff = SPL_2_83V - SPL_1W;
// no lower value
if (vFRD[0].verticalAngle > verticalAngle)
{
return vFRD[0].response(f, SPLdiff).abs();
}
for (int i = 1; i < vFRD.length; i++)
// no lower value
if (vFRD[0].verticalAngle > verticalAngle)
{
return -vFRD[0].response(f, SPLdiff).abs();
}
for (int i = 1; i < vFRD.length; i++)
{
if (vFRD[i].verticalAngle >= verticalAngle)
{
if (vFRD[i].verticalAngle >= verticalAngle)
{
return Fnc.interpolate(vFRD[i - 1].verticalAngle, vFRD[i - 1].response(f, SPLdiff).abs(), vFRD[i].verticalAngle, vFRD[i].response(f, SPLdiff).abs(), verticalAngle);
}
return Fnc.interpolate
(
vFRD[i - 1].verticalAngle,
vFRD[i - 1].response(f, SPLdiff).abs(),
vFRD[i].verticalAngle,
vFRD[i].response(f, SPLdiff).abs(),
verticalAngle
);
}
}
// no higher value
return vFRD[0].response(f, SPLdiff).abs();
// no higher value
return -vFRD[vFRD.length - 1].response(f, SPLdiff).abs();
}
public double relativeOffAxis(double f, double horizontalAngle, double verticalAngle, boolean dipole)
{
if (hasFRD() && (hFRD != null || vFRD != null))
{
double SPLdiff = SPL_2_83V - SPL_1W;
// TODO: dipole and sign tricks
horizontalAngle = Math.abs(horizontalAngle);
verticalAngle = Math.abs(verticalAngle);
return Math.min(horizontalAxis(f, horizontalAngle), verticalAxis(f, verticalAngle)) / FRD.response(f, SPLdiff).abs();
double axial = FRD.response(f, SPL_2_83V - SPL_1W).abs();
double horizontal = horizontalAxis(f, horizontalAngle);
double vertical = verticalAxis(f, verticalAngle);
if (horizontal < 0 && vertical < 0)
{
return Math.min(relativeOffAxisSim(f, horizontalAngle, verticalAngle, dipole), Math.min(-horizontal, -vertical) / axial);
}
else if (horizontal < 0)
{
horizontal = Math.min(relativeOffAxisSim(f, horizontalAngle, 0, dipole) * axial, -horizontal);
}
else if (vertical < 0)
{
vertical = Math.min(relativeOffAxisSim(f, 0, verticalAngle, dipole) * axial, -vertical);
}
return Math.min(horizontal, vertical) / axial;
}
return relativeOffAxisSim(f, horizontalAngle, verticalAngle, dipole);
......
This diff is collapsed.
......@@ -17,6 +17,8 @@
package SpeakerSim.GUI;
import SpeakerSim.Baffle;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
......@@ -31,6 +33,25 @@ public class BafflePanel extends javax.swing.JPanel
initComponents();
enabledCheckBox.addItemListener(new ItemListener()
{
@Override
public void itemStateChanged(ItemEvent e)
{
if (listen)
{
baffle.Enabled = enabledCheckBox.isSelected();
main.refresh();
}
/*widthField.setEnabled(baffle.Enabled);
heightField.setEnabled(baffle.Enabled);
leftField.setEnabled(baffle.Enabled);
bottomField.setEnabled(baffle.Enabled);
edgeField.setEnabled(baffle.Enabled);*/
}
});
widthField.addPropertyChangeListener("value", new PropertyChangeListener()
{
@Override
......@@ -105,6 +126,7 @@ public class BafflePanel extends javax.swing.JPanel
this.baffle = baffle;
enabledCheckBox.setSelected(baffle.Enabled);
widthField.setValue(baffle.Width * 100);
heightField.setValue(baffle.Height * 100);
leftField.setValue(baffle.X * 100);
......@@ -130,18 +152,19 @@ public class BafflePanel extends javax.swing.JPanel
bottomField = new javax.swing.JFormattedTextField();
jLabel3 = new javax.swing.JLabel();
edgeField = new javax.swing.JFormattedTextField();
enabledCheckBox = new javax.swing.JCheckBox();
setBorder(javax.swing.BorderFactory.createTitledBorder("Baffle"));
java.awt.GridBagLayout layout = new java.awt.GridBagLayout();
layout.columnWidths = new int[] {0, 5, 0};
layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0};
layout.rowHeights = new int[] {0, 5, 0, 5, 0, 5, 0, 5, 0, 5, 0};
setLayout(layout);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel1.setText("Baffle width (cm):");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(jLabel1, gridBagConstraints);
......@@ -150,14 +173,14 @@ public class BafflePanel extends javax.swing.JPanel
widthField.setPreferredSize(new java.awt.Dimension(80, 19));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridy = 2;
add(widthField, gridBagConstraints);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel2.setText("Baffle height (cm):");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(jLabel2, gridBagConstraints);
......@@ -166,14 +189,14 @@ public class BafflePanel extends javax.swing.JPanel
heightField.setPreferredSize(new java.awt.Dimension(80, 19));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridy = 4;
add(heightField, gridBagConstraints);
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel5.setText("Driver position from left (cm):");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridy = 6;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(jLabel5, gridBagConstraints);
......@@ -182,14 +205,14 @@ public class BafflePanel extends javax.swing.JPanel
leftField.setPreferredSize(new java.awt.Dimension(80, 19));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridy = 6;
add(leftField, gridBagConstraints);
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel6.setText("Driver position from bottom (cm):");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridy = 8;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(jLabel6, gridBagConstraints);
......@@ -198,14 +221,14 @@ public class BafflePanel extends javax.swing.JPanel
bottomField.setPreferredSize(new java.awt.Dimension(80, 19));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridy = 8;
add(bottomField, gridBagConstraints);
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel3.setText("Edge radius (mm):");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 8;
gridBagConstraints.gridy = 10;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(jLabel3, gridBagConstraints);
......@@ -214,14 +237,23 @@ public class BafflePanel extends javax.swing.JPanel
edgeField.setPreferredSize(new java.awt.Dimension(80, 19));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 8;
gridBagConstraints.gridy = 10;
add(edgeField, gridBagConstraints);
enabledCheckBox.setText("Enable baffle simulation");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
add(enabledCheckBox, gridBagConstraints);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JFormattedTextField bottomField;
private javax.swing.JFormattedTextField edgeField;
private javax.swing.JCheckBox enabledCheckBox;
private javax.swing.JFormattedTextField heightField;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
......
......@@ -92,6 +92,7 @@ public class ResponsesWindow extends JDialog
if (frd != null)
{
model.removeElement(frd);
list.clearSelection();
refresh();
}
}
......@@ -122,6 +123,8 @@ public class ResponsesWindow extends JDialog
List<ResponseData> hfrd = new ArrayList<ResponseData>();
List<ResponseData> vfrd = new ArrayList<ResponseData>();
Iterator iter = model.iterator();
drv.FRD = null;
while (iter.hasNext())
{
......@@ -140,25 +143,15 @@ public class ResponsesWindow extends JDialog
{
vfrd.add(rd);
}
else
{
//TODO: throw exception
}
}
if (hfrd.size() > 0)
{
Collections.sort(hfrd);
drv.hFRD = new ResponseData[hfrd.size()];
drv.hFRD = hfrd.toArray(drv.hFRD);
}
Collections.sort(hfrd);
drv.hFRD = new ResponseData[hfrd.size()];
drv.hFRD = hfrd.toArray(drv.hFRD);
if (vfrd.size() > 0)
{
Collections.sort(vfrd);
drv.vFRD = new ResponseData[vfrd.size()];
drv.vFRD = vfrd.toArray(drv.vFRD);
}
Collections.sort(vfrd);
drv.vFRD = new ResponseData[vfrd.size()];
drv.vFRD = vfrd.toArray(drv.vFRD);
}
});
......@@ -181,6 +174,7 @@ public class ResponsesWindow extends JDialog
{
model.removeElement(e);
}
list.clearSelection();
refresh();
}
});
......
......@@ -52,7 +52,7 @@ public class Settings implements JSONable
dBRange = 30;
MaxImpedance = 80;
MaxPower = 1000;
RoomSimulation = true;
RoomSimulation = false;
BaffleSimulation = true;
PowerFilter = new PowerFilter();
}
......@@ -68,7 +68,7 @@ public class Settings implements JSONable
dBRange = JSON.getInt(jsonObj, "dBRange", 30);
MaxImpedance = JSON.getInt(jsonObj, "MaxImpedance", 80);
MaxPower = JSON.getInt(jsonObj, "MaxPower", 1000);
RoomSimulation = JSON.getBoolean(jsonObj, "RoomSimulationEnabled", true);
RoomSimulation = JSON.getBoolean(jsonObj, "RoomSimulationEnabled", false);
BaffleSimulation = JSON.getBoolean(jsonObj, "BaffleSimulationEnabled", true);
PowerFilter = new PowerFilter(jsonObj.get("PowerFilter"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment