|
@@ -62,24 +62,37 @@ public class SoundServiceImpl implements SoundService {
|
|
|
*/
|
|
|
private List<Double> beatExtractor(byte[] bytes, String url) throws UnsupportedAudioFileException {
|
|
|
List<Double> times = new ArrayList<>();
|
|
|
- int size = 256;
|
|
|
- int overlap = 128;
|
|
|
+ int size = 512;
|
|
|
+ int overlap = 256;
|
|
|
AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromFile(url, size, overlap);
|
|
|
|
|
|
- ComplexOnsetDetector detector = new ComplexOnsetDetector(size);
|
|
|
- BeatRootOnsetEventHandler handler = new BeatRootOnsetEventHandler();
|
|
|
- detector.setHandler(handler);
|
|
|
-
|
|
|
+ ComplexOnsetDetector detector = new ComplexOnsetDetector(size,0.7,0.1);
|
|
|
+ detector.setHandler((double time, double salience) -> times.add(time));
|
|
|
dispatcher.addAudioProcessor(detector);
|
|
|
+
|
|
|
dispatcher.run();
|
|
|
+ return times;
|
|
|
+ }
|
|
|
|
|
|
- handler.trackBeats(new OnsetHandler() {
|
|
|
+ private List<Double> rootMeanSquareExtractor(byte[] bytes, String url) throws UnsupportedAudioFileException {
|
|
|
+ List<Double> rootMeans = new ArrayList<>();
|
|
|
+ int size = 2048;
|
|
|
+ int overlap = 0;
|
|
|
+ AudioDispatcher dispatcher = StringUtils.isBlank(url)?getFromByteArray(bytes, size, overlap):getFromFile(url, size, overlap);
|
|
|
+
|
|
|
+ dispatcher.addAudioProcessor(new AudioProcessor() {
|
|
|
@Override
|
|
|
- public void handleOnset(double time, double salience) {
|
|
|
- times.add(time);
|
|
|
+ public void processingFinished() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean process(AudioEvent audioEvent) {
|
|
|
+ rootMeans.add(audioEvent.getRMS());
|
|
|
+ return true;
|
|
|
}
|
|
|
});
|
|
|
- return times;
|
|
|
+ dispatcher.run();
|
|
|
+ return rootMeans;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -186,7 +199,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
if(pitchGap>pitch1){
|
|
|
pitchGap = pitch1;
|
|
|
}
|
|
|
- if(pitchGap<15){
|
|
|
+ if(pitchGap<13){
|
|
|
pitchGap = 0;
|
|
|
}
|
|
|
allPitchGap+=pitchGap;
|
|
@@ -205,7 +218,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
float sameTimes = 0;
|
|
|
for (Double time1 : times_s) {
|
|
|
for (Double time2 : times_r) {
|
|
|
- if(Math.abs(time2-time1)<0.1){
|
|
|
+ if(Math.abs(time2-time1)<1.5){
|
|
|
sameTimes++;
|
|
|
break;
|
|
|
}
|
|
@@ -213,7 +226,7 @@ public class SoundServiceImpl implements SoundService {
|
|
|
}
|
|
|
double cadence_d = 0;
|
|
|
sameTimes = sameTimes>times_r.size()?times_r.size():sameTimes;
|
|
|
- int allTimes = times_s.size()>times_r.size()?times_r.size():times_s.size();
|
|
|
+ int allTimes = times_s.size();
|
|
|
if (times_r.size()>0){
|
|
|
cadence_d = sameTimes/allTimes;
|
|
|
}
|
|
@@ -244,10 +257,10 @@ public class SoundServiceImpl implements SoundService {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
- result.put("score", new BigDecimal(92));
|
|
|
- result.put("intonation", new BigDecimal(100));
|
|
|
- result.put("cadence", new BigDecimal(89));
|
|
|
- result.put("integrity", new BigDecimal(93));
|
|
|
+ result.put("score", score);
|
|
|
+ result.put("intonation", intonation);
|
|
|
+ result.put("cadence", cadence);
|
|
|
+ result.put("integrity", integrity);
|
|
|
return BaseController.succeed(result);
|
|
|
}
|
|
|
}
|