Better SUD timing

Using latest microsecond time extraction from SUD unpack
This commit is contained in:
Douglas Gillespie 2022-11-11 08:56:03 +00:00
parent ee24c0ab6b
commit 068a8b1a27
4 changed files with 35 additions and 7 deletions

View File

@ -48,7 +48,7 @@ public class SUDFileTime {
if (sudMap == null) {
return Long.MIN_VALUE;
}
long t = sudMap.getFirstChunkTime();
long t = sudMap.getFirstChunkTimeMillis();
if (t != 0) {
sudTime = t;
}

View File

@ -1096,7 +1096,7 @@ public class ClickDetector extends PamProcess {
* @return true if the tasks complete successfully and the click is to be kept.
* false otherwise.
*/
private boolean completeClick(ClickDetection newClick) {
public boolean completeClick(ClickDetection newClick) {
if (newClick.dataType == ClickDetection.CLICK_CLICK) {
int nChannels = PamUtils.getNumChannels(newClick.getChannelBitmap());

View File

@ -25,6 +25,7 @@
package soundtrap;
import java.awt.Frame;
import java.util.ArrayList;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
@ -33,7 +34,10 @@ import Acquisition.AcquisitionControl;
import Acquisition.sud.SUDNotificationManager;
import PamController.PamController;
import PamguardMVC.PamRawDataBlock;
import clickDetector.ClickBTDisplay;
import clickDetector.ClickControl;
import clickDetector.ClickDisplay;
import clickDetector.ClickDisplayManager;
import soundtrap.sud.SudFileDWVHandler;
/**
@ -136,5 +140,19 @@ public class STClickControl extends ClickControl {
}
}
/**
* Called when running SUD file data to find and scroll the BT Display's
* @param timeMillis
*/
public void updateDisplayScrollers(long timeMillis) {
ClickDisplayManager dispManager = getDisplayManager();
ArrayList<ClickDisplay> dispList = dispManager.getWindowList();
for (ClickDisplay display : dispList) {
if (display instanceof ClickBTDisplay) {
((ClickBTDisplay) display).newScrollTimingData(timeMillis);
}
}
}
}

View File

@ -46,7 +46,7 @@ public class SudFileDWVHandler implements SUDNotificationHandler {
private List<BCLDetectionChunk> bclChunks = new LinkedList();
int bclDetCount, bclNoiseCount, dwvCount, processedChunks;
private long effortStart;
private long effortStart, fileStartMicros;
private double sampleRate;
private ByteConverter byteConverter;
private ClickDetector clickDetector;
@ -73,6 +73,7 @@ public class SudFileDWVHandler implements SUDNotificationHandler {
// sampleRate = sudAudioInputStream.getFormat().getFrameRate();
// this is the right one
sampleRate = sudAudioInputStream.getSudMap().clickDetSampleRate;
fileStartMicros = sudAudioInputStream.getSudMap().getFirstChunkTimeMicros();
stClickControl.findRawDataBlock().setChannelMap(1);
stClickControl.findRawDataBlock().setSampleRate((float) sampleRate, true);
stClickControl.getSTAcquisition().acquisitionParameters.sampleRate = (float) sampleRate;
@ -100,8 +101,12 @@ public class SudFileDWVHandler implements SUDNotificationHandler {
String chunkName = "Unknown";
int chunkSize = sudChunk.buffer.length;
if (sudAudioInputStream.getChunkIDString(chunkID).equals("wav")) {
long millis = sudChunk.getChunkHeader().getMillisTime();
stClickControl.updateDisplayScrollers(millis);
if (sudAudioInputStream.isChunkIDWav(chunkID)) {
chunkName = "RECORDINGS";
// chunkName = "RECORDINGS";
// System.out.printf("Chunk ID %d, size %d, type %s\n", chunkID, chunkSize,
// chunkName);
// System.out.println("ID: " + chunkID + " This is raw data from detected
@ -201,8 +206,8 @@ public class SudFileDWVHandler implements SUDNotificationHandler {
}
private void makeClick(BCLDetectionChunk bclChunk, Chunk dwvChunk) {
long elapsedSamples = (long) ((bclChunk.getJavaMicros() - effortStart) * (sampleRate / 1e6));
long elapsedSamples = (long) ((bclChunk.getJavaMicros() - fileStartMicros) * (sampleRate / 1e6));
long millis = bclChunk.getJavaMillis();
byte[] rawData = dwvChunk.getBuffer();
int nBytes = rawData.length;
int nSamples = nBytes / Short.BYTES;
@ -213,8 +218,13 @@ public class SudFileDWVHandler implements SUDNotificationHandler {
ClickDetection click = new ClickDetection(1, elapsedSamples, nSamples, clickDetector, channelGroupDetector, 1);
click.setWaveData(wavData);
// if (groupDetector != null) {
// groupDetector.
// }
if (clickDetector.completeClick(click)) {
clickDetector.getClickDataBlock().addPamData(click);
}
}
private void dwvEffort(long javaMillis, boolean isStart) {
System.out.printf("DWV Effort %s at %s\n", isStart ? "Start" : "End", PamCalendar.formatDBDateTime(javaMillis));