|
@@ -51,7 +51,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
private final int endCheckOffsetTime = 500;
|
|
|
|
|
|
private final float simpleRate = 44100;
|
|
|
- private int simpleSize = 1024;
|
|
|
+ private int simpleSize = 512;
|
|
|
|
|
|
private final AudioFormat audioFormat = new AudioFormat(simpleRate, 16, 1, true, false);
|
|
|
private static final PitchProcessor.PitchEstimationAlgorithm algo = PitchProcessor.PitchEstimationAlgorithm.FFT_YIN;
|
|
@@ -160,7 +160,7 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
}
|
|
|
|
|
|
List<MusicPitchDetailDto> recordInfo = new ArrayList<>();
|
|
|
- AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), audioFormat, simpleSize, 128);
|
|
|
+ AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), audioFormat, simpleSize, 256);
|
|
|
dispatcher.addAudioProcessor(new PitchProcessor(algo, simpleRate, simpleSize, (pitchDetectionResult, audioEvent) -> {
|
|
|
int timeStamp = (int) (userSoundInfoMap.get(phone).getMeasureStartTime() + audioEvent.getTimeStamp()*1000);
|
|
|
float pitch = pitchDetectionResult.getPitch();
|
|
@@ -306,8 +306,9 @@ 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.1);
|
|
|
- int startTimeStamp = musicXmlInfo.getTimeStamp() - ot5;
|
|
|
- int endTimeStamp = musicXmlInfo.getTimeStamp() + musicXmlInfo.getDuration() + ot5;
|
|
|
+ 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;
|
|
|
|
|
|
//时间范围内有效音准数量
|
|
|
float recordValidIntonationNum = 0;
|
|
@@ -323,6 +324,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(userSoundInfoMap.get(phone).getMusicalNotePitchMap().containsKey(musicXmlInfo.getMusicalNotesIndex()-1)){
|
|
|
preMusicalNotesPitch = userSoundInfoMap.get(phone).getMusicalNotePitchMap().get(musicXmlInfo.getMusicalNotesIndex()-1);
|
|
|
}
|
|
|
+ if(userSoundInfoMap.get(phone).getMusicalNotePitchMap().get(musicXmlInfo.getMusicalNotesIndex())==-1){
|
|
|
+ newMeasure = true;
|
|
|
+ }
|
|
|
int newNum = 0;
|
|
|
|
|
|
for (MusicPitchDetailDto recordInfo : userSoundInfoMap.get(phone).getRecordMeasurePithInfo()) {
|
|
@@ -332,11 +336,13 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(newMeasure){
|
|
|
break;
|
|
|
}
|
|
|
- if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>endTimeStamp){
|
|
|
+ if(recordInfo.getTimeStamp()<startTimeStamp||recordInfo.getTimeStamp()>(startTimeStamp+halfOt)){
|
|
|
continue;
|
|
|
}
|
|
|
if(Math.abs(recordInfo.getFrequency()-preMusicalNotesPitch)>10){
|
|
|
newNum++;
|
|
|
+ }else{
|
|
|
+ newNum = 0;
|
|
|
}
|
|
|
if(newNum>=2){
|
|
|
newMeasure = true;
|