Skip to content

Commit

Permalink
TargetDataLine обернут в AudioInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
3XclusiVe committed Feb 9, 2017
1 parent 3b24ec7 commit 030ded7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/Tests/TestCommandCounterAndStatistic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 0 additions & 6 deletions src/com/company/RecordingThread/RecordingThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions src/com/company/microphone/MicrophoneAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/********************************************************************************************
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/com/company/testInterfaceCommandsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onCompleteTraining() {
System.out.println("**************");
}

@Override

public void noCommand() {
System.out.println("**************");
System.out.println("No Command");
Expand Down

0 comments on commit 030ded7

Please sign in to comment.