yonge 3 years ago
parent
commit
ec8f29c0cb

+ 15 - 5
audio-analysis/src/main/java/com/yonge/netty/dto/NotePlayResult.java

@@ -5,7 +5,9 @@ public class NotePlayResult {
 	// 0:正确 1:音准过低 2:音准过高
 	private int status;
 	
-	private double migrationRate;
+	private double deviationRate;//偏移比例
+	
+	private double deviationValue;//偏移值
 	
 	public NotePlayResult() {
 		// TODO Auto-generated constructor stub
@@ -19,11 +21,19 @@ public class NotePlayResult {
 		this.status = status;
 	}
 
-	public double getMigrationRate() {
-		return migrationRate;
+	public double getDeviationRate() {
+		return deviationRate;
+	}
+
+	public void setDeviationRate(double deviationRate) {
+		this.deviationRate = deviationRate;
+	}
+
+	public double getDeviationValue() {
+		return deviationValue;
 	}
 
-	public void setMigrationRate(double migrationRate) {
-		this.migrationRate = migrationRate;
+	public void setDeviationValue(double deviationValue) {
+		this.deviationValue = deviationValue;
 	}
 }

+ 26 - 23
audio-analysis/src/main/java/com/yonge/netty/dto/UserChannelContext.java

@@ -15,7 +15,6 @@ import java.util.stream.Collectors;
 
 import javax.sound.sampled.AudioFormat;
 
-import com.yonge.audio.analysis.AudioFloatConverter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -28,7 +27,6 @@ import com.yonge.netty.entity.MusicXmlBasicInfo;
 import com.yonge.netty.entity.MusicXmlNote;
 import com.yonge.netty.entity.MusicXmlSection;
 import com.yonge.netty.server.processor.WaveformWriter;
-import org.springframework.util.CollectionUtils;
 
 /**
  * 用户通道上下文
@@ -48,7 +46,7 @@ public class UserChannelContext {
 	
 	private String user;
 	
-	private double standardFrequecy = 442;
+	private double standardFrequecy = 440;
 	
 	private float offsetMS;
 	
@@ -91,35 +89,40 @@ public class UserChannelContext {
 
 		NotePlayResult result = new NotePlayResult();
 
+		if (Math.round(xmlNote.getFrequency()) == Math.round(playFrequency)) {
+			result.setStatus(0);
+			result.setDeviationRate(0);
+			result.setDeviationValue(0);
+			
+			return result;
+		}
+
 		int status;
-		double migrationRate = 0;
+		double deviationRate = 0;
+		double deviationValue = 0;
+		
+		NoteFrequencyRange noteFrequencyRange = new NoteFrequencyRange(standardFrequecy, xmlNote.getFrequency());
 
-		if (Math.round(xmlNote.getFrequency()) == Math.round(playFrequency)) {
-			status = 0;
-			migrationRate = 0;
+		if (noteFrequencyRange.getMinFrequency() > playFrequency ) {
+			status = 1;//偏低
+		} else if( playFrequency > noteFrequencyRange.getMaxFrequency()){
+			status = 2;//偏高
 		} else {
-			NoteFrequencyRange noteFrequencyRange = new NoteFrequencyRange(standardFrequecy, xmlNote.getFrequency());
 
-			if (noteFrequencyRange.getMinFrequency() > playFrequency ) {
-				status = 1;
-			} else if( playFrequency > noteFrequencyRange.getMaxFrequency()){
-				status = 2;
-			} else {
-
-				status = 0;
+			status = 0;
 
-				if (Math.round(playFrequency) < Math.round(xmlNote.getFrequency())) {
-					double min = Math.abs(xmlNote.getFrequency() - noteFrequencyRange.getMinFrequency()) / 2;
-					migrationRate = Math.abs(playFrequency - xmlNote.getFrequency()) / min;
-				} else {
-					double max = Math.abs(xmlNote.getFrequency() - noteFrequencyRange.getMaxFrequency()) / 2;
-					migrationRate = Math.abs(playFrequency - xmlNote.getFrequency()) / max;
-				}
+			if (Math.round(playFrequency) < Math.round(xmlNote.getFrequency())) {
+				double min = Math.abs(xmlNote.getFrequency() - noteFrequencyRange.getMinFrequency()) / 2;
+				deviationRate = Math.abs(playFrequency - xmlNote.getFrequency()) / min;
+				//deviationValue = 
+			} else {
+				double max = Math.abs(xmlNote.getFrequency() - noteFrequencyRange.getMaxFrequency()) / 2;
+				deviationRate = Math.abs(playFrequency - xmlNote.getFrequency()) / max;
 			}
 		}
 
 		result.setStatus(status);
-		result.setMigrationRate(migrationRate);
+		result.setDeviationRate(deviationRate);
 
 		return result;
 	}