From 030ded78f3486c3da25e05572a91ab23434976cb Mon Sep 17 00:00:00 2001 From: Dmitriy Malych Date: Thu, 9 Feb 2017 20:56:20 +0300 Subject: [PATCH] =?UTF-8?q?TargetDataLine=20=D0=BE=D0=B1=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D1=83=D1=82=20=D0=B2=20AudioInputStream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tests/TestCommandCounterAndStatistic.java | 10 +++++----- .../company/RecordingThread/RecordingThread.java | 6 ------ .../company/microphone/MicrophoneAnalyzer.java | 15 +++++++++++---- .../company/testInterfaceCommandsListener.java | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Tests/TestCommandCounterAndStatistic.java b/src/Tests/TestCommandCounterAndStatistic.java index 2cb2c4d..9d1af0e 100644 --- a/src/Tests/TestCommandCounterAndStatistic.java +++ b/src/Tests/TestCommandCounterAndStatistic.java @@ -11,28 +11,28 @@ public class TestCommandCounterAndStatistic implements CommandsListener { private int correctCommandCounter = 0; private int commandCounter = 0; - @Override + public void onStartTraining() { correctCommandCounter += 1; commandCounter+=1; } - @Override + public void onPoseType(String name) { commandCounter+=1; } - @Override + public void onCapturePose() { commandCounter+=1; } - @Override + public void onCompleteTraining() { commandCounter+=1; } - @Override + public void noCommand() { commandCounter+=1; } diff --git a/src/com/company/RecordingThread/RecordingThread.java b/src/com/company/RecordingThread/RecordingThread.java index 08a4d98..3020e1e 100644 --- a/src/com/company/RecordingThread/RecordingThread.java +++ b/src/com/company/RecordingThread/RecordingThread.java @@ -103,12 +103,6 @@ public void run() { microphone.setAudioFile(tempAudioFile); microphone.captureAudioToFile(microphone.getAudioFile()); - /*double dTms = 32; - int bytes = microphone.getNumOfBytes(dTms/1000); - int freq = microphone.getFrequency(bytes); - int vol = microphone.getAudioVolume((int) dTms); - System.out.println(freq + " " + vol);*/ - Thread.sleep(checkVolumeSampleTime * 3); double magnitude = microphone.magnitude(120, 122); diff --git a/src/com/company/microphone/MicrophoneAnalyzer.java b/src/com/company/microphone/MicrophoneAnalyzer.java index 99e5b8e..b3ba8a3 100644 --- a/src/com/company/microphone/MicrophoneAnalyzer.java +++ b/src/com/company/microphone/MicrophoneAnalyzer.java @@ -3,7 +3,10 @@ import com.darkprograms.speech.util.Complex; import com.darkprograms.speech.util.FFT; +import java.io.IOException; + import javax.sound.sampled.AudioFileFormat; +import javax.sound.sampled.AudioInputStream; /******************************************************************************************** @@ -156,12 +159,16 @@ public int getFrequency(byte[] bytes){ public double magnitude (int minFreq, int maxFreq) { int numOfBytes = 2048; + + AudioInputStream stream = new AudioInputStream(getTargetDataLine()); - if(getTargetDataLine() == null){ - return -1; - } byte[] data = new byte[numOfBytes+1];//One byte is lost during conversion - this.getTargetDataLine().read(data, 0, numOfBytes); + try { + stream.read(data, 0, numOfBytes); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } double[] audioData = this.bytesToDoubleArray(data); diff --git a/src/com/company/testInterfaceCommandsListener.java b/src/com/company/testInterfaceCommandsListener.java index 6fa7440..e619741 100644 --- a/src/com/company/testInterfaceCommandsListener.java +++ b/src/com/company/testInterfaceCommandsListener.java @@ -30,7 +30,7 @@ public void onCompleteTraining() { System.out.println("**************"); } - @Override + public void noCommand() { System.out.println("**************"); System.out.println("No Command");