[+] 混音

This commit is contained in:
acgist
2023-05-06 23:57:25 +08:00
parent f59840e2c6
commit 739538b34c
20 changed files with 423 additions and 162 deletions

View File

@@ -0,0 +1,31 @@
package com.acgist.taoyao;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
public class AudioMixerTest {
@Test
public void testMixer() throws IOException {
// ffmpeg -i audio.mp3 -f s32le audio.pcm
// ffplay -i audio.pcm -f s32le -ar 48000 -ac 1
final File fileA = new File("D:\\tmp\\mixer\\1.pcm");
final File fileB = new File("D:\\tmp\\mixer\\2.pcm");
final byte[] bytesA = Files.readAllBytes(fileA.toPath());
final byte[] bytesB = Files.readAllBytes(fileB.toPath());
final int length = Math.min(bytesA.length, bytesB.length);
final byte[] target = new byte[length];
int a, b;
for (int i = 0; i < length; i++) {
a = bytesA[i];
b = bytesB[i];
target[i] = (byte) ((a + b) / 2);
}
Files.write(Paths.get("D:\\tmp\\mixer\\3.pcm"), target);
}
}