فهرست منبع

feat:小节评分涉及参数提取

Joburgess 4 سال پیش
والد
کامیت
11d60c8f40

+ 39 - 17
mec-biz/src/main/java/com/ym/mec/biz/dal/config/SoundCompareConfig.java

@@ -11,29 +11,51 @@ import javax.sound.sampled.AudioFormat;
  */
 public class SoundCompareConfig {
 
-    //采样率
+    /**
+     * @describe 采样率
+     */
     public float simpleRate = 44100;
-    //采样大小
+    /**
+     * @describe 采样大小
+     */
     public int simpleSize = 1024;
-    //帧覆盖大小
+    /**
+     * @describe 帧覆盖大小
+     */
     public int overlap = 256;
 
-    //音频解析格式
+    /**
+     * @describe 音频解析格式
+     */
     public AudioFormat audioFormat = new AudioFormat(simpleRate, 16, 1, true, false);
-    //音频解析算法
+    /**
+     * @describe 音频解析算法
+     */
     public PitchProcessor.PitchEstimationAlgorithm algo = PitchProcessor.PitchEstimationAlgorithm.FFT_YIN;
-    //分贝检测器
-    public SilenceDetector silenceDetecor = new SilenceDetector();
-
-    //有效分贝大小
+    /**
+     * @describe 分贝检测器
+     */
+    public SilenceDetector silenceDetector = new SilenceDetector();
+
+    /**
+     * @describe 有效分贝大小
+     */
     public int validDb = -70;
-    //有效频率
+    /**
+     * @describe 有效频率
+     */
     public int validFrequency = 20;
-    //音准前后音分误差范围
+    /**
+     * @describe 音准前后音分误差范围
+     */
     public int intonationCentsRange = 3;
-    //节奏有效阈值
+    /**
+     * @describe 节奏有效阈值
+     */
     public float cadenceValidDuty = 0.09f;
-    //完整性有效频率误差范围
+    /**
+     * @describe 完整性有效频率误差范围
+     */
     public int integrityFrequencyRange = 30;
 
     public float getSimpleRate() {
@@ -76,12 +98,12 @@ public class SoundCompareConfig {
         this.algo = algo;
     }
 
-    public SilenceDetector getSilenceDetecor() {
-        return silenceDetecor;
+    public SilenceDetector getSilenceDetector() {
+        return silenceDetector;
     }
 
-    public void setSilenceDetecor(SilenceDetector silenceDetecor) {
-        this.silenceDetecor = silenceDetecor;
+    public void setSilenceDetector(SilenceDetector silenceDetector) {
+        this.silenceDetector = silenceDetector;
     }
 
     public int getValidDb() {

+ 12 - 7
mec-biz/src/main/java/com/ym/mec/biz/handler/WebSocketHandler.java

@@ -39,17 +39,22 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketHandler.class);
 
-    //存储客户端链接
+    /**
+     * @describe 存储客户端链接
+     */
     public static final Map<String, WebSocketClientDetail> WS_CLIENTS = new ConcurrentHashMap<>();
 
     private BigDecimal oneHundred = new BigDecimal(100);
 
     private final String tmpDir = FileUtils.getTempDirectoryPath() + "/soundCompare/";
 
-    //用户对应评分信息
+    /**
+     * @describe 用户对应评分信息
+     */
     private Map<String, SoundCompareHelper> userSoundInfoMap = new ConcurrentHashMap<>();
-
-    //音频处理参数
+    /**
+     * @describe 音频处理参数
+     */
     private SoundCompareConfig soundCompareConfig = new SoundCompareConfig();
 
     @Autowired
@@ -155,7 +160,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
         }
 
         AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), soundCompareConfig.audioFormat, soundCompareConfig.simpleSize, soundCompareConfig.overlap);
-        dispatcher.addAudioProcessor(soundCompareConfig.silenceDetecor);
+        dispatcher.addAudioProcessor(soundCompareConfig.silenceDetector);
         dispatcher.addAudioProcessor(new PitchProcessor(soundCompareConfig.algo, soundCompareConfig.simpleRate, soundCompareConfig.simpleSize, (pitchDetectionResult, audioEvent) -> {
             int timeStamp = (int) (userSoundInfoMap.get(phone).getMeasureStartTime() + audioEvent.getTimeStamp()*1000);
             float pitch = pitchDetectionResult.getPitch();
@@ -163,11 +168,11 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
                 int preTimeStamp = CollectionUtils.isEmpty(userSoundInfoMap.get(phone).getRecordMeasurePithInfo())?0:userSoundInfoMap.get(phone).getRecordMeasurePithInfo().get(userSoundInfoMap.get(phone).getRecordMeasurePithInfo().size()-1).getTimeStamp();
                 calOffsetTime(phone, timeStamp - (timeStamp - preTimeStamp)/2);
             }
-            if(soundCompareConfig.silenceDetecor.currentSPL()<soundCompareConfig.validDb){
+            if(soundCompareConfig.silenceDetector.currentSPL()<soundCompareConfig.validDb){
                 pitch = -1;
             }
 //            LOGGER.info("时间:{}, 频率:{}, 分贝:{}", timeStamp, pitch, silenceDetecor.currentSPL());
-            userSoundInfoMap.get(phone).getRecordMeasurePithInfo().add(new MusicPitchDetailDto(timeStamp, pitch, soundCompareConfig.silenceDetecor.currentSPL()));
+            userSoundInfoMap.get(phone).getRecordMeasurePithInfo().add(new MusicPitchDetailDto(timeStamp, pitch, soundCompareConfig.silenceDetector.currentSPL()));
         }));
         dispatcher.run();
         if(Objects.isNull(userSoundInfoMap.get(phone).getAccessFile())){