mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
Handle corrupt sud files
Better handling of corrupt sud files which will not return a valid audioinputstream. These will be gracelessly skipped during analysis.
This commit is contained in:
parent
62148351c6
commit
d207325b2d
@ -104,9 +104,13 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings, D
|
||||
boolean ans = super.prepareInputFile();
|
||||
if (ans == false && ++currentFile < allFiles.size()) {
|
||||
System.out.println("Failed to open sound file. Try again with file " + allFiles.get(currentFile).getName());
|
||||
|
||||
/*
|
||||
* jumping striaght to the next file messes it up if it thinks the files
|
||||
* are continuous, so we HAVE to stop and restart.
|
||||
*/
|
||||
// return prepareInputFile();
|
||||
PamController.getInstance().pamStop();
|
||||
PamController.getInstance().startLater();
|
||||
PamController.getInstance().startLater(false);
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
@ -614,16 +618,16 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings, D
|
||||
long currFileEnd = 0;
|
||||
if (currentFile >= 0) {
|
||||
try {
|
||||
WavFileType currentWav = allFiles.get(currentFile);
|
||||
currFileStart = getFileStartTime(currentWav.getAbsoluteFile());
|
||||
if (audioStream != null) {
|
||||
fileSamples = audioStream.getFrameLength();
|
||||
currFileLength = (long) (fileSamples * 1000 / audioStream.getFormat().getFrameRate());
|
||||
currFileEnd = currFileStart + currFileLength;
|
||||
}
|
||||
WavFileType currentWav = allFiles.get(currentFile);
|
||||
currFileStart = getFileStartTime(currentWav.getAbsoluteFile());
|
||||
if (audioStream != null) {
|
||||
fileSamples = audioStream.getFrameLength();
|
||||
currFileLength = (long) (fileSamples * 1000 / audioStream.getFormat().getFrameRate());
|
||||
currFileEnd = currFileStart + currFileLength;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (currFileEnd == 0) {
|
||||
@ -648,7 +652,17 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings, D
|
||||
}
|
||||
setFolderProgress();
|
||||
// sayEta();
|
||||
ans = prepareInputFile();
|
||||
/*
|
||||
* I think that here, we just need a check of the file. the prepareInputFile in
|
||||
* this class will (on failure) move straight to the next file and also issue a
|
||||
* stop/start, which is not good if it's trying a continuous file, where this is
|
||||
* being called, if false is returned it should manage moving onto the next file by
|
||||
* itself if we use the super.prep ....
|
||||
*/
|
||||
ans = super.prepareInputFile();
|
||||
if (ans == false) {
|
||||
return false;
|
||||
}
|
||||
currentFileStart = System.currentTimeMillis();
|
||||
// if (ans && audioFormat.getSampleRate() != currentSampleRate && currentFile > 0) {
|
||||
// acquisitionControl.getDaqProcess().setSampleRate(currentSampleRate = audioFormat.getSampleRate(), true);
|
||||
|
@ -48,9 +48,9 @@ public class SudAudioFile extends WavAudioFile {
|
||||
}
|
||||
// don't do anything and it will try the built in Audiosystem
|
||||
catch (UnsupportedAudioFileException e) {
|
||||
System.err.println("Could not open sud file: not a supported file " + soundFile.getName());
|
||||
|
||||
e.printStackTrace();
|
||||
System.err.println("UnsupportedAudioFileException: Could not open sud file: not a supported file " + soundFile.getName());
|
||||
System.err.println(e.getMessage());
|
||||
// e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Could not open sud file: IO Exception: " + soundFile.getName());
|
||||
|
||||
|
@ -46,7 +46,8 @@ public class SudAudioFileReader {
|
||||
try {
|
||||
sudAudioInputStream = SudAudioInputStream.openInputStream(file, sudParams, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
String msg = String.format("Corrupt sud file %s: %s", file.getName(), e.getMessage());
|
||||
throw new UnsupportedAudioFileException(msg);
|
||||
}
|
||||
return sudAudioInputStream;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user