From 068a8b1a273e014fce12ecb66579ee4a20927ba8 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Fri, 11 Nov 2022 08:56:03 +0000 Subject: [PATCH] Better SUD timing Using latest microsecond time extraction from SUD unpack --- src/Acquisition/sud/SUDFileTime.java | 2 +- src/clickDetector/ClickDetector.java | 2 +- src/soundtrap/STClickControl.java | 18 ++++++++++++++++++ src/soundtrap/sud/SudFileDWVHandler.java | 20 +++++++++++++++----- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Acquisition/sud/SUDFileTime.java b/src/Acquisition/sud/SUDFileTime.java index 9d4e0853..1cc3ef52 100644 --- a/src/Acquisition/sud/SUDFileTime.java +++ b/src/Acquisition/sud/SUDFileTime.java @@ -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; } diff --git a/src/clickDetector/ClickDetector.java b/src/clickDetector/ClickDetector.java index 074138d7..db602360 100644 --- a/src/clickDetector/ClickDetector.java +++ b/src/clickDetector/ClickDetector.java @@ -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()); diff --git a/src/soundtrap/STClickControl.java b/src/soundtrap/STClickControl.java index 2fbdde7d..0ef6a8d2 100644 --- a/src/soundtrap/STClickControl.java +++ b/src/soundtrap/STClickControl.java @@ -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 dispList = dispManager.getWindowList(); + for (ClickDisplay display : dispList) { + if (display instanceof ClickBTDisplay) { + ((ClickBTDisplay) display).newScrollTimingData(timeMillis); + } + } + } + } diff --git a/src/soundtrap/sud/SudFileDWVHandler.java b/src/soundtrap/sud/SudFileDWVHandler.java index 57d61e82..6129c381 100644 --- a/src/soundtrap/sud/SudFileDWVHandler.java +++ b/src/soundtrap/sud/SudFileDWVHandler.java @@ -46,7 +46,7 @@ public class SudFileDWVHandler implements SUDNotificationHandler { private List 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,7 +218,12 @@ public class SudFileDWVHandler implements SUDNotificationHandler { ClickDetection click = new ClickDetection(1, elapsedSamples, nSamples, clickDetector, channelGroupDetector, 1); click.setWaveData(wavData); - clickDetector.getClickDataBlock().addPamData(click); +// if (groupDetector != null) { +// groupDetector. +// } + if (clickDetector.completeClick(click)) { + clickDetector.getClickDataBlock().addPamData(click); + } } private void dwvEffort(long javaMillis, boolean isStart) {