|
@@ -282,14 +282,14 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
//音准匹配误差范围
|
|
|
float intonationErrRange = 15;
|
|
|
//音准有效阈值
|
|
|
- float intonationValidDuty = 0.2f;
|
|
|
+ float intonationValidDuty = 0.01f;
|
|
|
|
|
|
//节奏匹配数量
|
|
|
float cadenceNum = 0;
|
|
|
//节奏匹配误差范围
|
|
|
float cadenceErrRange = 30;
|
|
|
//节奏有效阈值
|
|
|
- float cadenceValidDuty = 0.2f;
|
|
|
+ float cadenceValidDuty = 0.01f;
|
|
|
|
|
|
//完整性数量
|
|
|
float integrityNum = 0;
|
|
@@ -298,11 +298,13 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
//完整性有效阈值
|
|
|
float integrityValidDuty = 0.5f;
|
|
|
|
|
|
+ float td = 0;
|
|
|
+
|
|
|
int totalCompareNum = userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex).size();
|
|
|
|
|
|
for (int i = 0; i < userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex).size(); i++) {
|
|
|
MusicPitchDetailDto musicXmlInfo = userSoundInfoMap.get(phone).getMeasureXmlInfoMap().get(measureIndex).get(i);
|
|
|
- int ot5 = (int) (musicXmlInfo.getDuration()*0.1);
|
|
|
+ int ot5 = (int) (musicXmlInfo.getDuration()*0.001);
|
|
|
int halfOt = (int) (musicXmlInfo.getDuration()*0.35);
|
|
|
int startTimeStamp = musicXmlInfo.getTimeStamp() + userSoundInfoMap.get(phone).getOffsetTime() - ot5;
|
|
|
int endTimeStamp = musicXmlInfo.getTimeStamp() + userSoundInfoMap.get(phone).getOffsetTime() + musicXmlInfo.getDuration() + ot5;
|
|
@@ -316,7 +318,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
//时间范围内匹配次数
|
|
|
float compareNum = 0;
|
|
|
|
|
|
- boolean newMeasure = false;
|
|
|
+ boolean newMeasure = true;
|
|
|
float preMusicalNotesPitch = 0;
|
|
|
if(userSoundInfoMap.get(phone).getMusicalNotePitchMap().containsKey(musicXmlInfo.getMusicalNotesIndex()-1)){
|
|
|
preMusicalNotesPitch = userSoundInfoMap.get(phone).getMusicalNotePitchMap().get(musicXmlInfo.getMusicalNotesIndex()-1);
|
|
@@ -384,20 +386,21 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(CollectionUtils.isEmpty(musicalNotesPitchs)){
|
|
|
userSoundInfoMap.get(phone).getMusicalNotePitchMap().put(musicXmlInfo.getMusicalNotesIndex(), (float) 0);
|
|
|
}else{
|
|
|
- Map<Integer, Long> collect = musicalNotesPitchs.stream().collect(Collectors.groupingBy(Integer::intValue, Collectors.counting()));
|
|
|
+ Map<Integer, Long> collect = musicalNotesPitchs.stream().filter(pitch->pitch>0).collect(Collectors.groupingBy(Integer::intValue, Collectors.counting()));
|
|
|
//出现次数最多的频率
|
|
|
Integer pitch = collect.entrySet().stream().max(Comparator.comparing(e -> e.getValue())).get().getKey();
|
|
|
boolean ing = false;
|
|
|
int dnum = 0;
|
|
|
for (Integer musicalNotesPitch : musicalNotesPitchs) {
|
|
|
- if (!ing && Math.abs(musicalNotesPitch - pitch) <= 20){
|
|
|
+ if (Math.abs(musicalNotesPitch - pitch) <= 10){
|
|
|
+ dnum = 0;
|
|
|
ing = true;
|
|
|
continue;
|
|
|
}
|
|
|
- if (ing && Math.abs(musicalNotesPitch - pitch) > 20){
|
|
|
+ if (ing && Math.abs(musicalNotesPitch - pitch) > 10){
|
|
|
dnum++;
|
|
|
}
|
|
|
- if (dnum>=2){
|
|
|
+ if (dnum>1){
|
|
|
dnum = 0;
|
|
|
errPitchNum++;
|
|
|
ing = false;
|
|
@@ -407,15 +410,20 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
}
|
|
|
|
|
|
//有效音频占比
|
|
|
+ integrityValidNum = integrityValidNum + (float) (compareNum * 0.05);
|
|
|
+ if(integrityValidNum > compareNum){
|
|
|
+ integrityValidNum = compareNum;
|
|
|
+ }
|
|
|
float integrityDuty = integrityValidNum/compareNum;
|
|
|
+ td += integrityDuty;
|
|
|
//有效音高占比
|
|
|
float intonationDuty = recordValidIntonationNum/compareNum;
|
|
|
//有效节奏占比
|
|
|
float cadenceDuty = cadenceValidNum/compareNum;
|
|
|
//如果错误频率达到一定数值,则当前小节无效
|
|
|
- if(errPitchNum>=3){
|
|
|
- cadenceDuty = 0;
|
|
|
- }
|
|
|
+// if(errPitchNum>=3){
|
|
|
+// cadenceDuty = 0;
|
|
|
+// }
|
|
|
//节奏
|
|
|
if(cadenceDuty>=cadenceValidDuty){
|
|
|
cadenceNum++;
|
|
@@ -431,6 +439,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
intonation = new BigDecimal(intonationNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
cadence = new BigDecimal(cadenceNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
integrity = new BigDecimal(integrityNum).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ integrity = new BigDecimal(td).divide(new BigDecimal(totalCompareNum), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).multiply(oneHundred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
} catch (ArithmeticException e){
|
|
|
LOGGER.info("无musicXml信息");
|
|
|
}
|
|
@@ -671,8 +682,8 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
webSocketInfo.setHeader(header);
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
// BigDecimal score = intonation.multiply(new BigDecimal(0.5)).add(cadence.multiply(new BigDecimal(0.5))).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
- BigDecimal score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
-// BigDecimal score = intonation.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+// BigDecimal score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal score = integrity.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
result.put("score", score);
|
|
|
result.put("intonation", intonation);
|
|
|
result.put("cadence", cadence);
|