From 01c41a28966a714c6c0df7e6767df0e64c2cedf7 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Wed, 23 Feb 2022 09:54:34 +0000 Subject: [PATCH] Simple fix to amplitude calculations which were not thread safe. Not constants are stored per channel rather than a single constant, so will be fine. --- src/Acquisition/AcquisitionProcess.java | 35 +++++++++++++++++++------ src/fftManager/PamFFTProcess.java | 4 +-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/Acquisition/AcquisitionProcess.java b/src/Acquisition/AcquisitionProcess.java index c124032c..fe889516 100644 --- a/src/Acquisition/AcquisitionProcess.java +++ b/src/Acquisition/AcquisitionProcess.java @@ -920,9 +920,11 @@ public class AcquisitionProcess extends PamProcess { */ public double rawAmplitude2dB(double rawAmplitude, int channel, boolean fast){ + channel = checkSingleChannel(channel); + double constantTerm; - if (fast && fixedAmplitudeConstantTerm != 0) { - constantTerm = fixedAmplitudeConstantTerm; + if (fast && fixedAmplitudeConstantTerm[channel] != 0) { + constantTerm = fixedAmplitudeConstantTerm[channel]; } else { constantTerm = getAmplitudeConstantTerm(channel); @@ -944,6 +946,18 @@ public class AcquisitionProcess extends PamProcess { return dB; } + /** + * Check it's a single channel and not a channel map. + * @param channel + * @return single channel if it seemed to be a bitmap. + */ + private int checkSingleChannel(int channel) { + int bitCount = PamUtils.getNumChannels(channel); + if (bitCount > 1 || channel > 32) { + channel = PamUtils.getLowestChannel(channel); + } + return channel; + } /** * Some devices may be setting this per channel. @@ -969,17 +983,20 @@ public class AcquisitionProcess extends PamProcess { * like preamp gain will remain constant. Contains a constant * term in the SPL calculations bases on preamp gains and * hdrophone sensitivities. + * Changes to be channel specific since with multi threading it goes horribly + * wrong if different channels have different sensitivities. */ - double fixedAmplitudeConstantTerm; + private double[] fixedAmplitudeConstantTerm = new double[PamConstants.MAX_CHANNELS]; - DaqSystem ampSystem; + private DaqSystem ampSystem; /** - * Gets the fixedAmplitudeConstantTerm based on channel and hydrophone - * numbers. + * Gets the fixedAmplitudeConstantTerm based on channel and hydrophone This is + * the hydrophone sensitivity + all gains + ADC sensitivity in counts / volt. * @param channel = single software channel * @return constant term for amplitude calculations */ private double getAmplitudeConstantTerm(int channel) { + channel = checkSingleChannel(channel); // need to fish around a bit working out which hydrophone it is, etc. PamArray array = ArrayManager.getArrayManager().getCurrentArray(); int hydrophoneChannel = acquisitionControl.getChannelHydrophone(channel); @@ -1000,12 +1017,14 @@ public class AcquisitionProcess extends PamProcess { } return (hSens + preamp.getGain() + xtra); } + /** * Prepares for fast amplitude calculations * @param channel */ - public void prepareFastAmplitudeCalculation(int channel) { - fixedAmplitudeConstantTerm = getAmplitudeConstantTerm(channel); + public double prepareFastAmplitudeCalculation(int channel) { + channel = checkSingleChannel(channel); + return fixedAmplitudeConstantTerm[channel] = getAmplitudeConstantTerm(channel); } /** diff --git a/src/fftManager/PamFFTProcess.java b/src/fftManager/PamFFTProcess.java index 8df88bc6..b7dde70f 100644 --- a/src/fftManager/PamFFTProcess.java +++ b/src/fftManager/PamFFTProcess.java @@ -72,7 +72,7 @@ public class PamFFTProcess extends PamProcess { private double[] dataToFFT; - private ComplexArray fftData; +// private ComplexArray fftData; private double[] fftRealBlock; @@ -198,7 +198,7 @@ public class PamFFTProcess extends PamProcess { channelPointer[i] = 0; } } - fftData = new ComplexArray(fftParameters.fftLength); +// fftData = new ComplexArray(fftParameters.fftLength); /* * Tell the output data block - should then get passed on to Spectrogram * display which can come back and work it out for itself that life has