Browse Source

feat:智能陪练一期

Joburgess 3 years ago
parent
commit
c1ccb829a2

+ 7 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SoundCheckHandler.java

@@ -36,10 +36,8 @@ import java.util.concurrent.ConcurrentHashMap;
 @Service
 public class SoundCheckHandler implements WebSocketEventHandler {
 
-    private static final double COMPARE_FREQUENCY = 442;
-
     /** 校音数据 */
-    private Map<String, Integer> userSoundCheckInfo = new ConcurrentHashMap<>();
+    private Map<String, Double> userSoundCheckInfo = new ConcurrentHashMap<>();
 
     public SoundCheckHandler() {
         WebSocketHandler.regist(WebsocketTypeEnum.SOUND_CHECK, this);
@@ -57,7 +55,11 @@ public class SoundCheckHandler implements WebSocketEventHandler {
                 userSoundCheckInfo.remove(phone);
                 break;
             default:
-                userSoundCheckInfo.put(phone, 0);
+                userSoundCheckInfo.put(phone, (double) 442);
+                JSONObject body = (JSONObject) message.getBody();
+                if(body.containsKey("frequency")){
+                    userSoundCheckInfo.put(phone, body.getDoubleValue("frequency"));
+                }
                 break;
         }
     }
@@ -73,7 +75,7 @@ public class SoundCheckHandler implements WebSocketEventHandler {
                 if(pitchDetectionResult.getPitch()<=0){
                     return;
                 }
-                double normalCents = PitchConverter.hertzToAbsoluteCent(COMPARE_FREQUENCY);
+                double normalCents = PitchConverter.hertzToAbsoluteCent(userSoundCheckInfo.get(phone));
                 double recordCents = PitchConverter.hertzToAbsoluteCent(pitchDetectionResult.getPitch());
                 if(Math.abs(normalCents - recordCents)<3){
                     WebSocketHandler.sendTextMessage(phone, WebSocketInfo.success("checkDone"));