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.
This commit is contained in:
Douglas Gillespie 2022-02-23 09:54:34 +00:00
parent 027a854084
commit 01c41a2896
2 changed files with 29 additions and 10 deletions

View File

@ -920,9 +920,11 @@ public class AcquisitionProcess extends PamProcess {
*/ */
public double rawAmplitude2dB(double rawAmplitude, int channel, boolean fast){ public double rawAmplitude2dB(double rawAmplitude, int channel, boolean fast){
channel = checkSingleChannel(channel);
double constantTerm; double constantTerm;
if (fast && fixedAmplitudeConstantTerm != 0) { if (fast && fixedAmplitudeConstantTerm[channel] != 0) {
constantTerm = fixedAmplitudeConstantTerm; constantTerm = fixedAmplitudeConstantTerm[channel];
} }
else { else {
constantTerm = getAmplitudeConstantTerm(channel); constantTerm = getAmplitudeConstantTerm(channel);
@ -944,6 +946,18 @@ public class AcquisitionProcess extends PamProcess {
return dB; 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. * 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 * like preamp gain will remain constant. Contains a constant
* term in the SPL calculations bases on preamp gains and * term in the SPL calculations bases on preamp gains and
* hdrophone sensitivities. * 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 * Gets the fixedAmplitudeConstantTerm based on channel and hydrophone This is
* numbers. * the hydrophone sensitivity + all gains + ADC sensitivity in counts / volt.
* @param channel = single software channel * @param channel = single software channel
* @return constant term for amplitude calculations * @return constant term for amplitude calculations
*/ */
private double getAmplitudeConstantTerm(int channel) { private double getAmplitudeConstantTerm(int channel) {
channel = checkSingleChannel(channel);
// need to fish around a bit working out which hydrophone it is, etc. // need to fish around a bit working out which hydrophone it is, etc.
PamArray array = ArrayManager.getArrayManager().getCurrentArray(); PamArray array = ArrayManager.getArrayManager().getCurrentArray();
int hydrophoneChannel = acquisitionControl.getChannelHydrophone(channel); int hydrophoneChannel = acquisitionControl.getChannelHydrophone(channel);
@ -1000,12 +1017,14 @@ public class AcquisitionProcess extends PamProcess {
} }
return (hSens + preamp.getGain() + xtra); return (hSens + preamp.getGain() + xtra);
} }
/** /**
* Prepares for fast amplitude calculations * Prepares for fast amplitude calculations
* @param channel * @param channel
*/ */
public void prepareFastAmplitudeCalculation(int channel) { public double prepareFastAmplitudeCalculation(int channel) {
fixedAmplitudeConstantTerm = getAmplitudeConstantTerm(channel); channel = checkSingleChannel(channel);
return fixedAmplitudeConstantTerm[channel] = getAmplitudeConstantTerm(channel);
} }
/** /**

View File

@ -72,7 +72,7 @@ public class PamFFTProcess extends PamProcess {
private double[] dataToFFT; private double[] dataToFFT;
private ComplexArray fftData; // private ComplexArray fftData;
private double[] fftRealBlock; private double[] fftRealBlock;
@ -198,7 +198,7 @@ public class PamFFTProcess extends PamProcess {
channelPointer[i] = 0; 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 * 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 * display which can come back and work it out for itself that life has