|
@@ -59,7 +59,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
List<Double> times = new ArrayList<>();
|
|
|
int size = 256;
|
|
|
int overlap = 128;
|
|
|
- AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromUtl(url, size, overlap);
|
|
|
+ AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromFile(url, size, overlap);
|
|
|
|
|
|
ComplexOnsetDetector detector = new ComplexOnsetDetector(size);
|
|
|
BeatRootOnsetEventHandler handler = new BeatRootOnsetEventHandler();
|
|
@@ -89,7 +89,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
int size = 2048;
|
|
|
int overlap = 0;
|
|
|
final SilenceDetector silenceDetecor = new SilenceDetector();
|
|
|
- AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromUtl(url, size, overlap);
|
|
|
+ AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromFile(url, size, overlap);
|
|
|
dispatcher.addAudioProcessor(silenceDetecor);
|
|
|
dispatcher.addAudioProcessor(new AudioProcessor() {
|
|
|
@Override
|
|
@@ -112,8 +112,11 @@ public class SoundServiceImpl implements SoundService {
|
|
|
return dispatcher;
|
|
|
}
|
|
|
|
|
|
- private AudioDispatcher getFromUtl(String url, int size, int overlap) throws UnsupportedAudioFileException, IOException {
|
|
|
- AudioDispatcher dispatcher = AudioDispatcherFactory.fromURL(new URL(url), size, overlap);
|
|
|
+ private AudioDispatcher getFromFile(String url, int size, int overlap) throws UnsupportedAudioFileException, IOException {
|
|
|
+ PipedAudioStream file = new PipedAudioStream(url);
|
|
|
+ TarsosDSPAudioInputStream stream = file.getMonoStream(44100,0);
|
|
|
+
|
|
|
+ AudioDispatcher dispatcher = new AudioDispatcher(stream, size, overlap);
|
|
|
return dispatcher;
|
|
|
}
|
|
|
|
|
@@ -126,24 +129,17 @@ public class SoundServiceImpl implements SoundService {
|
|
|
|
|
|
try {
|
|
|
URL url = new URL(sysMusicScore.getUrl());
|
|
|
- String filePath = FileUtils.getTempDirectoryPath()+ Math.random() + ".mp3";
|
|
|
+ String filePath = FileUtils.getTempDirectoryPath()+ System.currentTimeMillis() + ".mp3";
|
|
|
File f = new File(filePath);
|
|
|
FileUtils.copyURLToFile(url, f);
|
|
|
|
|
|
+// AudioSystem.getAudioFileFormat(loadedFile);
|
|
|
|
|
|
- PipedAudioStream file_s = new PipedAudioStream(filePath);
|
|
|
- TarsosDSPAudioInputStream stream_s = file_s.getMonoStream((int) sampleRate,0);
|
|
|
-
|
|
|
- System.out.println(stream_s.getFrameLength());
|
|
|
- double l_s = stream_s.getFrameLength()/stream_s.getFormat().getFrameRate();
|
|
|
- System.out.printf("源长度:%.2f \n", l_s);
|
|
|
-
|
|
|
- AudioFileFormat recordFile = AudioSystem.getAudioFileFormat(record.getInputStream());
|
|
|
- double r_s = recordFile.getFrameLength()/recordFile.getFormat().getFrameRate();
|
|
|
- System.out.printf("录音长度:%.2f \n", r_s);
|
|
|
+ double l_s = 0;
|
|
|
+ double l_r = 0;
|
|
|
|
|
|
//相似度
|
|
|
- List<Double> pitchs_s = soundPressureLevelExtractor(null, sysMusicScore.getUrl());
|
|
|
+ List<Double> pitchs_s = soundPressureLevelExtractor(null, filePath);
|
|
|
List<Double> pitchs_r = soundPressureLevelExtractor(record.getBytes(), null);
|
|
|
|
|
|
int maxLength = pitchs_s.size();
|
|
@@ -167,7 +163,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
System.out.printf("音准:%.2f \r\n", intonation);
|
|
|
|
|
|
//节奏
|
|
|
- List<Double> times_s = beatExtractor(null, sysMusicScore.getUrl());
|
|
|
+ List<Double> times_s = beatExtractor(null, filePath);
|
|
|
List<Double> times_r = beatExtractor(record.getBytes(), null);
|
|
|
|
|
|
float sameTimes = 0;
|