java ACC byte[] 转码PCM byte[]
时间: 2023-09-13 19:07:32 浏览: 205
我可以回答这个问题。你可以使用Java中的AudioSystem将ACC格式的音频文件转换为PCM格式的字节数组。
以下是示例代码:
```java
File audioFile = new File("input.acc");
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audioFile);
AudioFormat audioFormat = audioInputStream.getFormat();
DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(info);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
byte[] accData = new byte[(int) audioFile.length()];
DataInputStream dataInputStream = new DataInputStream(new FileInputStream(audioFile));
dataInputStream.readFully(accData);
byte[] pcmData = new byte[accData.length * 2];
for (int i = 0; i < accData.length; i += 2) {
short sample = (short) ((accData[i] & 0xff) << 8 | (accData[i + 1] & 0xff));
pcmData[i * 2] = (byte) (sample & 0xff);
pcmData[i * 2 + 1] = (byte) ((sample >> 8) & 0xff);
}
sourceDataLine.write(pcmData, 0, pcmData.length);
sourceDataLine.drain();
sourceDataLine.stop();
sourceDataLine.close();
```
这段代码将读取名为`input.acc`的ACC格式音频文件,将其转换为PCM格式的字节数组,并使用SourceDataLine播放PCM音频数据。
阅读全文