Explorar o código

feat:云教练音准与节奏计算逻辑调整

Joburgess %!s(int64=3) %!d(string=hai) anos
pai
achega
47ca54b24d

+ 7 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/SoundCompareHelper.java

@@ -323,12 +323,18 @@ public class SoundCompareHelper implements PitchDetectionHandler {
         float pitch = pitchDetectionResult.getPitch();
         int decibel = (int) (100 - Math.abs(silenceDetector.currentSPL()));
 
+        int byteIndex = (int) (audioEvent.getTimeStamp()*(SoundCompareHandler.soundCompareConfig.audioFormat.getFrameSize()*SoundCompareHandler.soundCompareConfig.audioFormat.getFrameRate()));
+        byte byteOne = audioEvent.getByteBuffer()[byteIndex];
+        byte byteTwo = audioEvent.getByteBuffer()[byteIndex + 1];
+
+        double amplitude = ((byteOne&0x000000FF)|(byteTwo<<8));
+
         if(decibel <= SoundCompareHandler.soundCompareConfig.validDb){
             pitch = -1;
             decibel = 0;
         }
 
-        SoundCompareHandler.LOGGER.info("时间:{}, 频率:{}, 分贝:{}", timeStamp, pitch, decibel);
+        SoundCompareHandler.LOGGER.info("时间:{}, 振幅:{}, 频率:{}, 分贝:{}", timeStamp, amplitude, pitch, decibel);
 
         if(currPitchInfos.size()>0&&(Math.abs(currPitchInfos.get(currPitchInfos.size()-1).getFrequency()-pitch)>10||Math.abs(currPitchInfos.get(currPitchInfos.size()-1).getDecibel()-decibel)>10)){
             Double avgPitch = currPitchInfos.stream().skip(1).collect(Collectors.averagingDouble(MusicPitchDetailDto::getFrequency));