|
@@ -44,11 +44,11 @@ public class Main {
|
|
|
public static void main(String[] args){
|
|
|
try{
|
|
|
float sampleRate = 44100;
|
|
|
- int audioBufferSize = 2048;
|
|
|
+ int audioBufferSize = 2048 * 2;
|
|
|
int bufferOverlap = 0;
|
|
|
AudioFloatConverter converter = AudioFloatConverter.getConverter(audioFormat);
|
|
|
//Create an AudioInputStream from my .wav file
|
|
|
- URL soundURL = Main.class.getResource("/300.wav");
|
|
|
+ URL soundURL = Main.class.getResource("/WAV.wav");
|
|
|
AudioInputStream stream = AudioSystem.getAudioInputStream(soundURL);
|
|
|
final MFCC mfccProcessor = new MFCC(audioBufferSize, stream.getFormat().getSampleRate(),
|
|
|
amountOfCepstrumCoef, amountOfMelFilters, lowerFilterFreq, upperFilterFreq);
|
|
@@ -59,17 +59,26 @@ public class Main {
|
|
|
|
|
|
int b = 0;
|
|
|
int frequency = 0;
|
|
|
- while (bytes.length > 2048 *2) {
|
|
|
+ while (bytes.length > 2048 *4) {
|
|
|
|
|
|
- byte[] bufferData = ArrayUtil.extractByte(bytes, 0, 2048*2 - 1);
|
|
|
+ byte[] bufferData = ArrayUtil.extractByte(bytes, 0, 2048*4 - 1);
|
|
|
|
|
|
- float[] sampleFloats = new float[1024*2];
|
|
|
+ float[] sampleFloats = new float[1024*4];
|
|
|
|
|
|
converter.toFloatArray(bufferData, sampleFloats);
|
|
|
int playFrequency = (int)detector.getPitch(sampleFloats).getPitch();
|
|
|
- System.out.println("play frequency is " +playFrequency);
|
|
|
+ if (playFrequency != -1) {
|
|
|
+ System.out.println("play frequency is " + playFrequency);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ YINPitchDetector frequencyDetector = new YINPitchDetector(sampleFloats.length, audioFormat.getSampleRate());
|
|
|
+
|
|
|
+ playFrequency = (int) frequencyDetector.getFrequency(sampleFloats);
|
|
|
+
|
|
|
+ System.out.println("frequencyDetector play frequency is " + playFrequency);
|
|
|
// ArrayUtil.extractByte(channelContext.getChannelBufferBytes(), bufferSize, totalLength - 1)
|
|
|
- bytes = ArrayUtil.extractByte(bytes, 2048*2, bytes.length - 1);
|
|
|
+ bytes = ArrayUtil.extractByte(bytes, 2048*4, bytes.length - 1);
|
|
|
// if (b == 1) {
|
|
|
// frequency += playFrequency;
|
|
|
// System.out.println("play frequency is " +frequency/2);
|