|
@@ -42,8 +42,10 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
public static final Map<String, WebSocketSession> WS_CLIENTS = new ConcurrentHashMap<>();
|
|
public static final Map<String, WebSocketSession> WS_CLIENTS = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
private BigDecimal oneHundred = new BigDecimal(100);
|
|
private BigDecimal oneHundred = new BigDecimal(100);
|
|
|
|
|
+ private final float simpleRate = 44100;
|
|
|
|
|
+ private int simpleSize = 1024;
|
|
|
|
|
|
|
|
- private static final AudioFormat audioFormat = new AudioFormat(44100, 16, 1, true, false);
|
|
|
|
|
|
|
+ private final AudioFormat audioFormat = new AudioFormat(simpleRate, 16, 1, true, false);
|
|
|
private static final PitchProcessor.PitchEstimationAlgorithm algo = PitchProcessor.PitchEstimationAlgorithm.FFT_YIN;
|
|
private static final PitchProcessor.PitchEstimationAlgorithm algo = PitchProcessor.PitchEstimationAlgorithm.FFT_YIN;
|
|
|
|
|
|
|
|
private static final String tmpDir = FileUtils.getTempDirectoryPath() + "/soundCompare/";
|
|
private static final String tmpDir = FileUtils.getTempDirectoryPath() + "/soundCompare/";
|
|
@@ -104,9 +106,9 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
if(!userSoundInfoMap.containsKey(phone)){
|
|
if(!userSoundInfoMap.containsKey(phone)){
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- if(!CollectionUtils.isEmpty(userSoundInfoMap.get(phone).getMeasureEndTime())){
|
|
|
|
|
- measureCompare(phone, userSoundInfoMap.get(phone).getMeasureEndTime().keySet().stream().max(Integer::compareTo).get());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// if(!CollectionUtils.isEmpty(userSoundInfoMap.get(phone).getMeasureEndTime())){
|
|
|
|
|
+// measureCompare(phone, userSoundInfoMap.get(phone).getMeasureEndTime().keySet().stream().max(Integer::compareTo).get());
|
|
|
|
|
+// }
|
|
|
calTotalScore(phone);
|
|
calTotalScore(phone);
|
|
|
createHeader(phone);
|
|
createHeader(phone);
|
|
|
break;
|
|
break;
|
|
@@ -125,11 +127,12 @@ public class WebSocketHandler extends AbstractWebSocketHandler {
|
|
|
userSoundInfoMap.get(phone).getAccessFile().write(message.getPayload().array());
|
|
userSoundInfoMap.get(phone).getAccessFile().write(message.getPayload().array());
|
|
|
}
|
|
}
|
|
|
List<MusicPitchDetailDto> recordInfo = new ArrayList<>();
|
|
List<MusicPitchDetailDto> recordInfo = new ArrayList<>();
|
|
|
- AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), audioFormat, 256, 128);
|
|
|
|
|
- dispatcher.addAudioProcessor(new PitchProcessor(algo, 44100, 256, (pitchDetectionResult, audioEvent) -> {
|
|
|
|
|
|
|
+ AudioDispatcher dispatcher = AudioDispatcherFactory.fromByteArray(message.getPayload().array(), audioFormat, simpleSize, 128);
|
|
|
|
|
+ dispatcher.addAudioProcessor(new PitchProcessor(algo, simpleRate, simpleSize, (pitchDetectionResult, audioEvent) -> {
|
|
|
int timeStamp = (int) (userSoundInfoMap.get(phone).getMeasureStartTime() + audioEvent.getTimeStamp()*1000);
|
|
int timeStamp = (int) (userSoundInfoMap.get(phone).getMeasureStartTime() + audioEvent.getTimeStamp()*1000);
|
|
|
float pitch = pitchDetectionResult.getPitch();
|
|
float pitch = pitchDetectionResult.getPitch();
|
|
|
recordInfo.add(new MusicPitchDetailDto(timeStamp, pitch));
|
|
recordInfo.add(new MusicPitchDetailDto(timeStamp, pitch));
|
|
|
|
|
+ LOGGER.info("频率:{}", pitch);
|
|
|
}));
|
|
}));
|
|
|
dispatcher.run();
|
|
dispatcher.run();
|
|
|
if(Objects.isNull(userSoundInfoMap.get(phone).getAccessFile())){
|
|
if(Objects.isNull(userSoundInfoMap.get(phone).getAccessFile())){
|