瀏覽代碼

fix:测试

liujunchi 3 年之前
父節點
當前提交
51ae3dc56a

+ 16 - 7
audio-analysis/src/main/java/com/yonge/Main.java

@@ -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);

+ 1 - 0
audio-analysis/src/main/java/com/yonge/netty/dto/UserChannelContext.java

@@ -329,6 +329,7 @@ public class UserChannelContext {
 		int playFrequency = -1;
 		if(!percussionList.contains(subjectId)){
 			playFrequency = (int)detector.getPitch(samples).getPitch();
+			LOGGER.info("频率 {}",playFrequency);
 		}
 		
 		int splDb = (int) Signals.soundPressureLevel(samples);

+ 1 - 1
audio-analysis/src/main/java/com/yonge/netty/server/service/AudioCompareHandler.java

@@ -84,7 +84,7 @@ public class AudioCompareHandler implements MessageHandler {
 	/**
 	 * @describe 采样大小
 	 */
-	private int bufferSize = 1024 * 2;
+	private int bufferSize = 1024 * 2 *2;
 
 	private boolean signed = true;
 

+ 4 - 2
audio-analysis/src/main/java/com/yonge/netty/server/service/PitchDetectionHandler.java

@@ -74,8 +74,10 @@ public class PitchDetectionHandler implements MessageHandler {
 		YINPitchDetector frequencyDetector = new YINPitchDetector(samples.length, audioFormat.getSampleRate());
 
 		int playFrequency = (int) frequencyDetector.getFrequency(samples);
-		
-		LOGGER.info("校音频率:{}", playFrequency);
+
+		if (playFrequency != 49) {
+			LOGGER.info("校音频率:{}", playFrequency);
+		}
 
 		Map<String, Object> params = new HashMap<String, Object>();
 		params.put("frequency", playFrequency);