|
@@ -171,10 +171,10 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
cents = PitchConverter.hertzToAbsoluteCent(pitch);
|
|
|
}
|
|
|
// LOGGER.info("时间:{}, 频率:{}, 分贝:{}, 音分:{}", timeStamp, pitch, silenceDetecor.currentSPL(), cents);
|
|
|
-// if (silenceDetecor.currentSPL() <= -60){
|
|
|
+// if (silenceDetecor.currentSPL() < -66){
|
|
|
// pitch = -1;
|
|
|
// }
|
|
|
- recordInfo.add(new MusicPitchDetailDto(timeStamp, pitch));
|
|
|
+ recordInfo.add(new MusicPitchDetailDto(timeStamp, pitch, silenceDetecor.currentSPL()));
|
|
|
}));
|
|
|
dispatcher.run();
|
|
|
if(Objects.isNull(userSoundInfoMap.get(phone).getAccessFile())){
|
|
@@ -309,13 +309,12 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
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.05);
|
|
|
- int halfOt = (int) (musicXmlInfo.getDuration()*0.35);
|
|
|
+ int ot5 = (int) (musicXmlInfo.getDuration()*0.1);
|
|
|
int startTimeStamp = musicXmlInfo.getTimeStamp() + userSoundInfoMap.get(phone).getOffsetTime() + ot5;
|
|
|
int endTimeStamp = musicXmlInfo.getTimeStamp() + userSoundInfoMap.get(phone).getOffsetTime() + musicXmlInfo.getDuration() - ot5;
|
|
|
|
|
|
int preMeasureEndTimeStamp = startTimeStamp;
|
|
|
- List<MusicPitchDetailDto> ms = userSoundInfoMap.get(phone).getMusicXmlInfos().stream().filter(m -> m.getMeasureIndex() == musicXmlInfo.getMeasureIndex() - 1).collect(Collectors.toList());
|
|
|
+ List<MusicPitchDetailDto> ms = userSoundInfoMap.get(phone).getMusicXmlInfos().stream().filter(m -> m.getMusicalNotesIndex() == musicXmlInfo.getMusicalNotesIndex() - 1).collect(Collectors.toList());
|
|
|
if(!CollectionUtils.isEmpty(ms)){
|
|
|
preMeasureEndTimeStamp = ms.get(0).getEndTimeStamp() + userSoundInfoMap.get(phone).getOffsetTime();
|
|
|
}
|
|
@@ -357,7 +356,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<Float> musicalNotesPitchs = new ArrayList<>();
|
|
|
+// List<Float> musicalNotesPitchs = new ArrayList<>();
|
|
|
+// List<Float> decibels = new ArrayList<>();
|
|
|
+ List<MusicPitchDetailDto> measureSoundPitchInfos = new ArrayList<>();
|
|
|
|
|
|
for (int j = 0; j < userSoundInfoMap.get(phone).getRecordMeasurePithInfo().size(); j++) {
|
|
|
MusicPitchDetailDto recordInfo = userSoundInfoMap.get(phone).getRecordMeasurePithInfo().get(j);
|
|
@@ -365,7 +366,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>endTimeStamp){
|
|
|
continue;
|
|
|
}
|
|
|
- musicalNotesPitchs.add(recordInfo.getFrequency());
|
|
|
+// musicalNotesPitchs.add(recordInfo.getFrequency());
|
|
|
+// decibels.add(recordInfo.getDecibel());
|
|
|
+ measureSoundPitchInfos.add(recordInfo);
|
|
|
compareNum++;
|
|
|
if(!newMeasure){
|
|
|
continue;
|
|
@@ -387,28 +390,47 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
|
|
|
//非正常频率次数
|
|
|
int errPitchNum = 0;
|
|
|
+ //分贝变化次数
|
|
|
+ int decibelChangeNum = 0;
|
|
|
|
|
|
- if(CollectionUtils.isEmpty(musicalNotesPitchs)){
|
|
|
+ if(CollectionUtils.isEmpty(measureSoundPitchInfos)){
|
|
|
userSoundInfoMap.get(phone).getMusicalNotePitchMap().put(musicXmlInfo.getMusicalNotesIndex(), (float) 0);
|
|
|
}else{
|
|
|
- Map<Integer, Long> collect = musicalNotesPitchs.stream().map(pitch -> pitch.intValue()).collect(Collectors.groupingBy(Integer::intValue, Collectors.counting()));
|
|
|
+ Map<Integer, Long> collect = measureSoundPitchInfos.stream().map(pitch -> (int)pitch.getFrequency()).collect(Collectors.groupingBy(Integer::intValue, Collectors.counting()));
|
|
|
//出现次数最多的频率
|
|
|
Integer pitch = collect.entrySet().stream().max(Comparator.comparing(e -> e.getValue())).get().getKey();
|
|
|
+ //当前频率
|
|
|
+ double cf = -1;
|
|
|
+ //频率持续数量
|
|
|
+ int fnum = 0;
|
|
|
+ //是否演奏中
|
|
|
boolean ing = false;
|
|
|
+ //当前分贝
|
|
|
+ double cd = 0;
|
|
|
+ //分贝持续数量
|
|
|
int dnum = 0;
|
|
|
- for (Float musicalNotesPitch : musicalNotesPitchs) {
|
|
|
- if (Math.abs(musicalNotesPitch - pitch) <= 10){
|
|
|
- dnum = 0;
|
|
|
- ing = true;
|
|
|
- continue;
|
|
|
+ for (MusicPitchDetailDto musicalNotesPitch : measureSoundPitchInfos) {
|
|
|
+ //计算频率断层次数
|
|
|
+ if (Math.abs(musicalNotesPitch.getFrequency() - cf) > 20){
|
|
|
+ fnum ++;
|
|
|
+ }
|
|
|
+ if (fnum>=5){
|
|
|
+ cf = musicalNotesPitch.getFrequency();
|
|
|
+ fnum = 0;
|
|
|
+ if (cf != -1){
|
|
|
+ errPitchNum ++;
|
|
|
+ ing = true;
|
|
|
+ cd = musicalNotesPitch.getDecibel();
|
|
|
+ }
|
|
|
}
|
|
|
- if (ing && Math.abs(musicalNotesPitch - pitch) > 10){
|
|
|
- dnum++;
|
|
|
+ //计算声音大小断层册数
|
|
|
+ if(ing && Math.abs(musicalNotesPitch.getDecibel() - cd) > 5){
|
|
|
+ dnum ++;
|
|
|
}
|
|
|
- if (dnum>1){
|
|
|
+ if (dnum > 2){
|
|
|
+ cd = musicalNotesPitch.getDecibel();
|
|
|
dnum = 0;
|
|
|
- errPitchNum++;
|
|
|
- ing = false;
|
|
|
+ decibelChangeNum++;
|
|
|
}
|
|
|
}
|
|
|
userSoundInfoMap.get(phone).getMusicalNotePitchMap().put(musicXmlInfo.getMusicalNotesIndex(), (float) pitch);
|
|
@@ -416,8 +438,8 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
|
|
|
//有效节奏占比
|
|
|
float cadenceDuty = cadenceValidNum/compareNum;
|
|
|
- //如果错误频率达到一定数值,则当前小节无效
|
|
|
- if(errPitchNum>=2){
|
|
|
+ //如果频率出现断层或这个音量出现断层,则当前音符节奏无效
|
|
|
+ if(errPitchNum>=2 || decibelChangeNum>1){
|
|
|
cadenceDuty = 0;
|
|
|
}
|
|
|
//节奏
|
|
@@ -425,8 +447,8 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
cadenceNum++;
|
|
|
}
|
|
|
//音准
|
|
|
- if (!CollectionUtils.isEmpty(musicalNotesPitchs)){
|
|
|
- Double avgPitch = musicalNotesPitchs.stream().filter(pitch -> Math.abs((pitch-musicXmlInfo.getFrequency()))<5).collect(Collectors.averagingDouble(pitch -> pitch));
|
|
|
+ if (!CollectionUtils.isEmpty(measureSoundPitchInfos)){
|
|
|
+ Double avgPitch = measureSoundPitchInfos.stream().filter(pitch -> Math.abs((pitch.getFrequency()-musicXmlInfo.getFrequency()))<5).collect(Collectors.averagingDouble(pitch -> pitch.getFrequency()));
|
|
|
//音分
|
|
|
double recordCents = 0;
|
|
|
if (avgPitch > 0){
|