2 次代碼提交 8c2434c05c ... bff5b10ba4

作者 SHA1 備註 提交日期
  yonge bff5b10ba4 update 4 月之前
  yonge 329ffd3487 update 5 月之前

+ 45 - 2
audio-analysis/src/main/java/com/yonge/netty/dto/UserChannelContext.java

@@ -362,9 +362,10 @@ public class UserChannelContext {
 
 		converter.toFloatArray(datas, samples);
 		
+		/**
 		for(float f : samples) {
 			floatSamples.add(f);
-		}
+		}*/
 		
 		if (detector == null) {
 			detector = new FastYin(audioFormat.getSampleRate(), getBufferSize());
@@ -565,6 +566,11 @@ public class UserChannelContext {
 	public void evaluateForNote(MusicXmlNote musicXmlNote, NoteAnalysis noteAnalysis, List<ChunkAnalysis> chunkAnalysisList) {
 
 		double durationTime = chunkAnalysisList.get(chunkAnalysisList.size() - 1).getEndTime() - chunkAnalysisList.get(0).getStartTime();
+		
+		//如果是跳音
+		if(musicXmlNote.isStaccato()) {
+			durationTime = durationTime / 2;
+		}
 
 		double playDurationTime = 0;
 
@@ -697,6 +703,8 @@ public class UserChannelContext {
 		
 		LOGGER.debug("---------------------TEMPO----------------------");
 		
+		double playDurationTime = chunkAnalysisList.stream().filter(t -> t.getFrequency() > MIN_FREQUECY).mapToDouble(t -> t.getDurationTime()).sum();
+		
 		ChunkAnalysis firstChunkAnalysis = chunkAnalysisList.get(0);
 		
 		noteAnalysis.setRhythmStartTime(musicXmlNote.getTimeStamp() + dynamicOffset);//默认值
@@ -705,6 +713,10 @@ public class UserChannelContext {
 
 		if(musicXmlNote.getFrequency() < MIN_FREQUECY) {
 			if(frequencyRhythmMap.size() == 0) {
+				if((int)playDurationTime > 0) {
+					noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
+					return 0;
+				}
 				noteAnalysis.setMusicalErrorType(NoteErrorType.RIGHT);
 				return 99;
 			} else {
@@ -714,6 +726,21 @@ public class UserChannelContext {
 			}
 		}
 		
+		if(musicXmlNote.isTenutoSound()) {
+			if(frequencyRhythmMap.size() == 0) {
+				if((int)playDurationTime > 0) {
+					noteAnalysis.setMusicalErrorType(NoteErrorType.RIGHT);
+					return 99;
+				}
+				noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
+				return 0;
+			} else {
+				noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
+				LOGGER.debug("根据能量包络检测到[{}]个断点,分别在[{}]", frequencyRhythmMap.size(), frequencyRhythmMap.values().stream().map(value -> value).map(Object::toString).collect(Collectors.joining(",")));
+				return 0;
+			}
+		}
+		
 		if(frequencyRhythmMap.size() > 1) {
 			noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
 			LOGGER.debug("根据音高检测到[{}]个断点,分别在[{}]", frequencyRhythmMap.size(), frequencyRhythmMap.values().stream().map(value -> value).map(Object::toString).collect(Collectors.joining(",")));
@@ -736,10 +763,26 @@ public class UserChannelContext {
 				LOGGER.debug("节奏错误原因:进入时间点[{}]太晚", firstBeatTime);
 				return 0;
 			}
+			
+			//如果是跳音,只需吹奏一半时值,超过一半则节奏错误
+			if(musicXmlNote.isStaccato()) {
+				double durationTime = musicXmlNote.getDuration();
+				
+				if(durationTime / playDurationTime < 2) {
+					noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
+					LOGGER.debug("节奏错误原因:断音吹奏时间过长[{}%]" , playDurationTime * 100 / durationTime);
+					return 0;
+				}
+			}
+			
 			noteAnalysis.setMusicalErrorType(NoteErrorType.RIGHT);
 			LOGGER.debug("找到节奏点StartTime:{}", firstBeatTime);
 		} else {
-			noteAnalysis.setMusicalErrorType(NoteErrorType.NOT_PLAY);
+			if((int)playDurationTime == 0) {
+				noteAnalysis.setMusicalErrorType(NoteErrorType.NOT_PLAY);
+			}else {
+				noteAnalysis.setMusicalErrorType(NoteErrorType.CADENCE_WRONG);
+			}
 			LOGGER.debug("没有找到节奏点");
 			return 0;
 		}

+ 23 - 1
audio-analysis/src/main/java/com/yonge/netty/entity/MusicXmlNote.java

@@ -33,7 +33,13 @@ public class MusicXmlNote {
 	private int denominator;
 	
 	private int measureRenderIndex;
-
+	
+	//是否是延音
+	private boolean isTenutoSound;
+	
+	//是否是跳音
+	private boolean isStaccato;
+	
 	public double getTimeStamp() {
 		return timeStamp;
 	}
@@ -113,4 +119,20 @@ public class MusicXmlNote {
 	public void setMeasureRenderIndex(int measureRenderIndex) {
 		this.measureRenderIndex = measureRenderIndex;
 	}
+
+	public boolean isTenutoSound() {
+		return isTenutoSound;
+	}
+
+	public void setIsTenutoSound(boolean isTenutoSound) {
+		this.isTenutoSound = isTenutoSound;
+	}
+
+	public boolean isStaccato() {
+		return isStaccato;
+	}
+
+	public void setIsStaccato(boolean isStaccato) {
+		this.isStaccato = isStaccato;
+	}
 }

+ 2 - 2
audio-analysis/src/test/java/com/yonge/netty/client/NettyClient.java

@@ -89,11 +89,11 @@ public class NettyClient {
 			String step2 = "{\"header\":{\"commond\":\"recordStart\",\"type\":\"SOUND_COMPARE\",\"status\":200}}";
 			channel.writeAndFlush(new TextWebSocketFrame(step2));
 			
-			String step3 = "{\"body\":{\"micDelay\":122,\"offsetTime\":431},\"uuid\":\"1662715309875118846\",\"header\":{\"commond\":\"audioPlayStart\",\"type\":\"SOUND_COMPARE\"}}";
+			String step3 = "{\"body\":{\"micDelay\":63,\"offsetTime\":201},\"uuid\":\"1662715309875118846\",\"header\":{\"commond\":\"audioPlayStart\",\"type\":\"SOUND_COMPARE\"}}";
 			channel.writeAndFlush(new TextWebSocketFrame(step3));
 			//51. "micDelay\":122,\"offsetTime\":431
 			//step4 发送wav
-			String fileName = "/100254_2406060919766_打击乐51.wav";
+			String fileName = "/2135180_2406261737430.wav";
 			AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(FileUtils.toFile(WebSocketClientHandler.class.getResource(fileName)));
 			
 			AudioFormat baseFormat = audioInputStream.getFormat();

文件差異過大導致無法顯示
+ 0 - 0
audio-analysis/src/test/resoures/9550.json


部分文件因文件數量過多而無法顯示