Fix synchronization problem in RawDataTransfroms

This commit is contained in:
Douglas Gillespie 2022-09-13 09:07:11 +01:00
parent 6b15b3d536
commit cd89c65d7c

View File

@ -188,7 +188,8 @@ public class RawDataTransforms {
* @param fftLength * @param fftLength
* @return Power spectrum * @return Power spectrum
*/ */
public synchronized double[] getPowerSpectrum(int channel, int fftLength) { public double[] getPowerSpectrum(int channel, int fftLength) {
synchronized (synchObject) {
if (powerSpectra == null) { if (powerSpectra == null) {
powerSpectra = new double[PamUtils.getNumChannels(dataUnit.getChannelBitmap())][]; powerSpectra = new double[PamUtils.getNumChannels(dataUnit.getChannelBitmap())][];
} }
@ -212,6 +213,7 @@ public class RawDataTransforms {
} }
return powerSpectra[channel]; return powerSpectra[channel];
} }
}
/** /**
@ -220,7 +222,8 @@ public class RawDataTransforms {
* @param fftLength * @param fftLength
* @return Sum of power spectra * @return Sum of power spectra
*/ */
public synchronized double[] getTotalPowerSpectrum(int fftLength) { public double[] getTotalPowerSpectrum(int fftLength) {
synchronized (synchObject) {
if (fftLength == 0) { if (fftLength == 0) {
fftLength = getCurrentSpectrumLength(); fftLength = getCurrentSpectrumLength();
} }
@ -240,6 +243,7 @@ public class RawDataTransforms {
} }
return totalPowerSpectrum; return totalPowerSpectrum;
} }
}
@ -253,7 +257,8 @@ public class RawDataTransforms {
* @param fftLength - the FFT length to use. * @param fftLength - the FFT length to use.
* @return the complex spectrum - the comnplex spectrum of the wave data from the specified channel. * @return the complex spectrum - the comnplex spectrum of the wave data from the specified channel.
*/ */
public synchronized ComplexArray getComplexSpectrumHann(int channel, int fftLength) { public ComplexArray getComplexSpectrumHann(int channel, int fftLength) {
synchronized (synchObject) {
complexSpectrum = new ComplexArray[PamUtils.getNumChannels(dataUnit.getChannelBitmap())]; complexSpectrum = new ComplexArray[PamUtils.getNumChannels(dataUnit.getChannelBitmap())];
if (complexSpectrum[channel] == null if (complexSpectrum[channel] == null
|| complexSpectrum.length != fftLength / 2) { || complexSpectrum.length != fftLength / 2) {
@ -263,6 +268,7 @@ public class RawDataTransforms {
} }
return complexSpectrum[channel]; return complexSpectrum[channel];
} }
}
@ -389,7 +395,8 @@ public class RawDataTransforms {
* @param fftLength * @param fftLength
* @return the complex spectrum * @return the complex spectrum
*/ */
public synchronized ComplexArray getComplexSpectrum(int channel, int fftLength) { public ComplexArray getComplexSpectrum(int channel, int fftLength) {
synchronized (synchObject) {
double[] paddedRawData; double[] paddedRawData;
double[] rawData; double[] rawData;
int i, mn; int i, mn;
@ -413,6 +420,7 @@ public class RawDataTransforms {
} }
return complexSpectrum[channel]; return complexSpectrum[channel];
} }
}
/** /**
@ -420,7 +428,8 @@ public class RawDataTransforms {
* @param iChan channel index * @param iChan channel index
* @return analytic waveform * @return analytic waveform
*/ */
public synchronized double[] getAnalyticWaveform(int iChan) { public double[] getAnalyticWaveform(int iChan) {
synchronized (synchObject) {
if (analyticWaveform == null) { if (analyticWaveform == null) {
analyticWaveform = new double[getNChan()][]; analyticWaveform = new double[getNChan()][];
} }
@ -429,6 +438,7 @@ public class RawDataTransforms {
// } // }
return analyticWaveform[iChan]; return analyticWaveform[iChan];
} }
}
/** /**
* Get filtered or unfiltered analytic waveform. Easy access method for click * Get filtered or unfiltered analytic waveform. Easy access method for click
@ -439,7 +449,8 @@ public class RawDataTransforms {
* @param fftFilterParams fft filter parameters. * @param fftFilterParams fft filter parameters.
* @return analystic waveform. * @return analystic waveform.
*/ */
public synchronized double[] getAnalyticWaveform(int iChan, boolean filtered, FFTFilterParams fftFilterParams) { public double[] getAnalyticWaveform(int iChan, boolean filtered, FFTFilterParams fftFilterParams) {
synchronized (synchObject) {
if (filtered == false || fftFilterParams == null) { if (filtered == false || fftFilterParams == null) {
return getAnalyticWaveform(iChan); return getAnalyticWaveform(iChan);
} }
@ -447,6 +458,7 @@ public class RawDataTransforms {
return getFilteredAnalyticWaveform(fftFilterParams, iChan); return getFilteredAnalyticWaveform(fftFilterParams, iChan);
} }
} }
}
/** /**
* Get a filtered version of the analytic waveform. In principle, this could be made more efficient * Get a filtered version of the analytic waveform. In principle, this could be made more efficient