|
@@ -83,6 +83,10 @@ public class SoundCompareHelper implements PitchDetectionHandler {
|
|
|
|
|
|
private List<MusicPitchDetailDto> musicXmlInfos;
|
|
|
|
|
|
+ private long firstMeasureStartBytes = 0;
|
|
|
+
|
|
|
+ private long recordBytes = 0;
|
|
|
+
|
|
|
private String clientId;
|
|
|
|
|
|
private Integer detailId;
|
|
@@ -281,6 +285,22 @@ public class SoundCompareHelper implements PitchDetectionHandler {
|
|
|
this.userScoreMap = userScoreMap;
|
|
|
}
|
|
|
|
|
|
+ public long getFirstMeasureStartBytes() {
|
|
|
+ return firstMeasureStartBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setFirstMeasureStartBytes(long firstMeasureStartBytes) {
|
|
|
+ this.firstMeasureStartBytes = firstMeasureStartBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getRecordBytes() {
|
|
|
+ return recordBytes;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRecordBytes(long recordBytes) {
|
|
|
+ this.recordBytes = recordBytes;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<Integer, Map<String, Object>> getUserMeasureScoreMap() {
|
|
|
return userMeasureScoreMap;
|
|
|
}
|
|
@@ -302,23 +322,6 @@ public class SoundCompareHelper implements PitchDetectionHandler {
|
|
|
int timeStamp = (int) (measureStartTime + audioEvent.getTimeStamp()*1000);
|
|
|
float pitch = pitchDetectionResult.getPitch();
|
|
|
int decibel = (int) (100 - Math.abs(silenceDetector.currentSPL()));
|
|
|
- //初始化偏移时间
|
|
|
- if(offsetTime == -1 && decibel>SoundCompareHandler.soundCompareConfig.validDb){
|
|
|
- offsetTime = timeStamp;
|
|
|
- for (MusicPitchDetailDto musicXmlInfo : musicXmlInfos) {
|
|
|
- if(!musicXmlInfo.getDontEvaluating()){
|
|
|
- if(offsetTime > musicXmlInfo.getTimeStamp()) {
|
|
|
- offsetTime = offsetTime - musicXmlInfo.getTimeStamp();
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- musicXmlInfos.forEach(e->e.setTimeStamp(e.getTimeStamp()+offsetTime));
|
|
|
- for (Map.Entry<Integer, MusicPitchDetailDto> musicPitchDetailDtoEntry : measureEndTime.entrySet()) {
|
|
|
- musicPitchDetailDtoEntry.getValue().setTimeStamp(musicPitchDetailDtoEntry.getValue().getTimeStamp() + offsetTime);
|
|
|
- musicPitchDetailDtoEntry.getValue().setEndTimeStamp(musicPitchDetailDtoEntry.getValue().getEndTimeStamp() + offsetTime);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
if(decibel <= SoundCompareHandler.soundCompareConfig.validDb){
|
|
|
pitch = -1;
|
|
@@ -327,47 +330,38 @@ public class SoundCompareHelper implements PitchDetectionHandler {
|
|
|
|
|
|
SoundCompareHandler.LOGGER.info("时间:{}, 频率:{}, 分贝:{}", timeStamp, pitch, decibel);
|
|
|
|
|
|
-// if(pitch==-1){
|
|
|
-// decibel = SoundCompareHandler.soundCompareConfig.validDb;
|
|
|
-// }
|
|
|
-// recordMeasurePithInfo.add(new MusicPitchDetailDto(timeStamp, pitch, silenceDetector.currentSPL()));
|
|
|
+ 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));
|
|
|
+ Double avgDb = currPitchInfos.stream().skip(1).collect(Collectors.averagingDouble(MusicPitchDetailDto::getDecibel));
|
|
|
|
|
|
- Double avgPitch = currPitchInfos.stream().skip(1).collect(Collectors.averagingDouble(MusicPitchDetailDto::getFrequency));
|
|
|
- Double avgDb = currPitchInfos.stream().skip(1).collect(Collectors.averagingDouble(MusicPitchDetailDto::getDecibel));
|
|
|
+ MusicPitchDetailDto measureDetail = new MusicPitchDetailDto(currPitchInfos.get(0).getTimeStamp(), avgPitch.floatValue(), avgDb);
|
|
|
+ measureDetail.setEndTimeStamp(timeStamp);
|
|
|
+ measureDetail.setDuration(measureDetail.getEndTimeStamp()-measureDetail.getTimeStamp());
|
|
|
|
|
|
- long count = currPitchInfos.stream().filter(p -> p.getFrequency() < 0).count();
|
|
|
- if(currPitchInfos.size()>0&&count/currPitchInfos.size()<0.5){
|
|
|
- avgPitch = currPitchInfos.stream().skip(1).filter(p->p.getFrequency()>0).collect(Collectors.averagingDouble(MusicPitchDetailDto::getFrequency));
|
|
|
- }
|
|
|
- if(Math.abs(avgPitch-pitch)>10||Math.abs(decibel-avgDb)>5){
|
|
|
- obviousChangeNum++;
|
|
|
- }else{
|
|
|
- currTmpPitchInfos.clear();
|
|
|
- obviousChangeNum=0;
|
|
|
- }
|
|
|
-
|
|
|
- if(obviousChangeNum>1){
|
|
|
-// SoundCompareHandler.LOGGER.info("----------------------------{}---{}----{}", avgPitch, avgDb, recordMeasurePitchInfos.size());
|
|
|
-// SoundCompareHandler.LOGGER.info("----------------------------{}", JSON.toJSONString(currPitchInfos.stream().map(MusicPitchDetailDto::getFrequency).collect(Collectors.toList())));
|
|
|
-// SoundCompareHandler.LOGGER.info("----------------------------{}", JSON.toJSONString(currTmpPitchInfos.stream().map(MusicPitchDetailDto::getFrequency).collect(Collectors.toList())));
|
|
|
-
|
|
|
- if(!CollectionUtils.isEmpty(currPitchInfos)&&(avgPitch>0||avgDb>SoundCompareHandler.soundCompareConfig.validDb)){
|
|
|
- MusicPitchDetailDto measureDetail = new MusicPitchDetailDto(currPitchInfos.get(0).getTimeStamp(), avgPitch.floatValue(), avgDb);
|
|
|
- measureDetail.setEndTimeStamp(currTmpPitchInfos.get(0).getTimeStamp());
|
|
|
- measureDetail.setDuration(measureDetail.getEndTimeStamp()-measureDetail.getTimeStamp());
|
|
|
+ if(measureDetail.getDuration()>25&&(avgPitch>0||avgDb>SoundCompareHandler.soundCompareConfig.validDb)){
|
|
|
recordMeasurePitchInfos.add(measureDetail);
|
|
|
}
|
|
|
|
|
|
currPitchInfos.clear();
|
|
|
- currPitchInfos.addAll(currTmpPitchInfos);
|
|
|
- currTmpPitchInfos.clear();
|
|
|
- obviousChangeNum = 0;
|
|
|
- }
|
|
|
- if(obviousChangeNum>0){
|
|
|
- currTmpPitchInfos.add(new MusicPitchDetailDto(timeStamp, pitch, decibel));
|
|
|
- }else{
|
|
|
- currPitchInfos.add(new MusicPitchDetailDto(timeStamp, pitch, decibel));
|
|
|
- }
|
|
|
|
|
|
+ //初始化偏移时间
|
|
|
+ if(offsetTime == -1 && recordMeasurePitchInfos.size() == 1){
|
|
|
+ offsetTime = recordMeasurePitchInfos.get(0).getTimeStamp();
|
|
|
+ for (MusicPitchDetailDto musicXmlInfo : musicXmlInfos) {
|
|
|
+ if(!musicXmlInfo.getDontEvaluating()){
|
|
|
+ if(offsetTime > musicXmlInfo.getTimeStamp()) {
|
|
|
+ offsetTime = offsetTime - musicXmlInfo.getTimeStamp();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ musicXmlInfos.forEach(e->e.setTimeStamp(e.getTimeStamp()+offsetTime));
|
|
|
+ for (Map.Entry<Integer, MusicPitchDetailDto> musicPitchDetailDtoEntry : measureEndTime.entrySet()) {
|
|
|
+ musicPitchDetailDtoEntry.getValue().setTimeStamp(musicPitchDetailDtoEntry.getValue().getTimeStamp() + offsetTime);
|
|
|
+ musicPitchDetailDtoEntry.getValue().setEndTimeStamp(musicPitchDetailDtoEntry.getValue().getEndTimeStamp() + offsetTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ currPitchInfos.add(new MusicPitchDetailDto(timeStamp, pitch, decibel));
|
|
|
}
|
|
|
}
|