|
@@ -21,6 +21,8 @@ import com.ym.mec.common.entity.HttpResponseResult;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -46,6 +48,8 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class SoundServiceImpl implements SoundService {
|
|
|
|
|
|
+ private final Logger LOGGER = LoggerFactory.getLogger(SoundServiceImpl.class);
|
|
|
+
|
|
|
private float sampleRate = 44100;
|
|
|
|
|
|
@Autowired
|
|
@@ -138,13 +142,15 @@ public class SoundServiceImpl implements SoundService {
|
|
|
BigDecimal intonation = BigDecimal.ZERO;
|
|
|
BigDecimal cadence = BigDecimal.ZERO;
|
|
|
BigDecimal integrity = BigDecimal.ZERO;
|
|
|
-
|
|
|
+ File f = null;
|
|
|
try {
|
|
|
URL url = new URL(sysMusicScore.getUrl());
|
|
|
String filePath = FileUtils.getTempDirectoryPath()+ System.currentTimeMillis() + ".mp3";
|
|
|
- File f = new File(filePath);
|
|
|
+ f = new File(filePath);
|
|
|
FileUtils.copyURLToFile(url, f);
|
|
|
|
|
|
+ LOGGER.info("文件名:{},伴奏编号:{},源文件:{}", record.getOriginalFilename(), musicScoreId, filePath);
|
|
|
+
|
|
|
BigDecimal oneHandred = new BigDecimal(100);
|
|
|
|
|
|
BigDecimal l_s = new BigDecimal(0);
|
|
@@ -188,7 +194,6 @@ public class SoundServiceImpl implements SoundService {
|
|
|
}
|
|
|
Double cadence_d = Double.valueOf(sameTimes/times_s.size());
|
|
|
cadence = new BigDecimal(cadence_d).multiply(oneHandred).setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
- System.out.printf("节奏:%.2f", cadence);
|
|
|
|
|
|
integrity = new BigDecimal(1);
|
|
|
if(l_r.compareTo(l_s)<0){
|
|
@@ -202,9 +207,12 @@ public class SoundServiceImpl implements SoundService {
|
|
|
e.printStackTrace();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(f!=null){
|
|
|
+ f.delete();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
result.put("score", score);
|
|
|
result.put("intonation", intonation);
|
|
|
result.put("cadence", cadence);
|