Преглед изворни кода

修改作品合成播放器处理wav文件头部44长度的问题,防止杂音

Pq пре 10 месеци
родитељ
комит
ef83482a8e

+ 8 - 6
musicMerge/src/main/java/com/cooleshow/musicmerge/player/MergeTrackManager.java

@@ -432,12 +432,7 @@ public class MergeTrackManager {
         if (isLast) {
             System.arraycopy(source, startIndex * destination.length, destination, 0, remainByteLength);
         } else {
-            if (startIndex == 0) {
-                //去掉头部44个字节
-                System.arraycopy(source, WAV_HEADER_LENGTH, destination, 0, destination.length - WAV_HEADER_LENGTH);
-            } else {
-                System.arraycopy(source, startIndex * destination.length, destination, 0, destination.length);
-            }
+            System.arraycopy(source, startIndex * destination.length, destination, 0, destination.length);
         }
         if (isLast) {
             return -1;
@@ -572,6 +567,7 @@ public class MergeTrackManager {
             if (!isStereoWavFile) {
                 audiodata = AudioConverter.convertMonoToStereo(audiodata);
             }
+            audiodata = removeWavHeader(audiodata);
             byteArrayOutputStream.close();
             return audiodata;
         } catch (Exception e) {
@@ -580,6 +576,12 @@ public class MergeTrackManager {
         return null;
     }
 
+    private byte[] removeWavHeader(byte[] audiodata) {
+        byte[] results = new byte[audiodata.length - WAV_HEADER_LENGTH];
+        System.arraycopy(audiodata, WAV_HEADER_LENGTH, results, 0, results.length);
+        return results;
+    }
+
     public void stop() {
         ISPLAYSOUND = false;
         if (mAudioTrack != null) {