Added race condition debugging and reduced recording buffer size for better responsiveness

This commit is contained in:
2019-08-11 12:51:10 +01:00
parent 54739b0a75
commit 04fea4acb2
2 changed files with 22 additions and 1 deletions
@@ -1365,6 +1365,7 @@ public class AudiobookRecorder extends JFrame {
if (s.startRecording()) { if (s.startRecording()) {
recording = (Sentence)selectedNode; recording = (Sentence)selectedNode;
System.err.println("Starting flash");
centralPanel.setFlash(true); centralPanel.setFlash(true);
} }
} }
@@ -1414,6 +1415,7 @@ public class AudiobookRecorder extends JFrame {
if (s.startRecording()) { if (s.startRecording()) {
recording = s; recording = s;
System.err.println("Starting flash");
centralPanel.setFlash(true); centralPanel.setFlash(true);
} }
} }
@@ -1464,6 +1466,7 @@ public class AudiobookRecorder extends JFrame {
if (s.startRecording()) { if (s.startRecording()) {
recording = s; recording = s;
System.err.println("Starting flash");
centralPanel.setFlash(true); centralPanel.setFlash(true);
} }
} }
@@ -1513,6 +1516,7 @@ public class AudiobookRecorder extends JFrame {
if (s.startRecording()) { if (s.startRecording()) {
recording = s; recording = s;
System.err.println("Starting flash");
centralPanel.setFlash(true); centralPanel.setFlash(true);
} }
} }
@@ -1562,23 +1566,29 @@ public class AudiobookRecorder extends JFrame {
if (s.startRecording()) { if (s.startRecording()) {
recording = s; recording = s;
System.err.println("Starting flash");
centralPanel.setFlash(true); centralPanel.setFlash(true);
} }
} }
public void stopRecording() { public void stopRecording() {
System.err.println("Record stop requested");
if (recording == null) return; if (recording == null) return;
recording.stopRecording(); recording.stopRecording();
System.err.println("Reloading model");
bookTreeModel.reload(book); bookTreeModel.reload(book);
bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath())); bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath()));
bookTree.setSelectionPath(new TreePath(recording.getPath())); bookTree.setSelectionPath(new TreePath(recording.getPath()));
bookTree.scrollPathToVisible(new TreePath(recording.getPath())); bookTree.scrollPathToVisible(new TreePath(recording.getPath()));
System.err.println("Stopping flash");
centralPanel.setFlash(false); centralPanel.setFlash(false);
recording = null; recording = null;
System.err.println("Saving book");
saveBookStructure(); saveBookStructure();
System.err.println("Stop request complete");
} }
public void deleteLastRecording() { public void deleteLastRecording() {
@@ -94,7 +94,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
try { try {
running = true; running = true;
recording = true; recording = true;
byte[] buf = new byte[AudiobookRecorder.window.microphone.getBufferSize()]; byte[] buf = new byte[1024]; //AudiobookRecorder.window.microphone.getBufferSize()];
FileOutputStream fos = new FileOutputStream(tempFile); FileOutputStream fos = new FileOutputStream(tempFile);
int len = 0; int len = 0;
AudiobookRecorder.window.microphone.flush(); AudiobookRecorder.window.microphone.flush();
@@ -155,24 +155,31 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
} }
public boolean startRecording() { public boolean startRecording() {
System.err.println("Starting record");
if (AudiobookRecorder.window.microphone == null) { if (AudiobookRecorder.window.microphone == null) {
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Microphone not started. Start the microphone first.", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(AudiobookRecorder.window, "Microphone not started. Start the microphone first.", "Error", JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
System.err.println("Removing object from cache");
CacheManager.removeFromCache(this); CacheManager.removeFromCache(this);
System.err.println("Creating record thread");
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat()); recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
System.err.println("Starting record thread");
Thread rc = new Thread(recordingThread); Thread rc = new Thread(recordingThread);
rc.setDaemon(true); rc.setDaemon(true);
rc.start(); rc.start();
System.err.println("Recording started");
return true; return true;
} }
public void stopRecording() { public void stopRecording() {
System.err.println("Stopping recording...");
recordingThread.stopRecording(); recordingThread.stopRecording();
System.err.println("Waiting for stop to complete...");
while (recordingThread.isRunning()) { while (recordingThread.isRunning()) {
try { try {
Thread.sleep(10); Thread.sleep(10);
@@ -181,11 +188,14 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
} }
} }
System.err.println("Removing object from cache...");
CacheManager.removeFromCache(this); CacheManager.removeFromCache(this);
audioData = null; audioData = null;
processedAudio = null; processedAudio = null;
System.err.println("Running trim and recognition...");
if (!id.equals("room-noise")) { if (!id.equals("room-noise")) {
String tm = Options.get("audio.recording.trim"); String tm = Options.get("audio.recording.trim");
if (tm.equals("peak")) { if (tm.equals("peak")) {
@@ -197,6 +207,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
recognise(); recognise();
} }
} }
System.err.println("Recording stop complete");
} }
public static final int FFTBuckets = 1024; public static final int FFTBuckets = 1024;