如何发挥在Java PCM原始数据 [英] how to play pcm raw data in java

查看:207
本文介绍了如何发挥在Java PCM原始数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个短阵PCM样本。什么是玩这个最好的出路?
格式为8000Hz的,单声道,16位,大端。
(PCM样是在code产生并通过某些文件无法读取)

Hi I have PCM samples in a short array. What is the best way to play this out? The format is 8000Hz, Mono, 16 bit, big endian. (The PCM samples are generated in the code and not read through some file)

感谢

推荐答案

随着的 javax.sound.sampled中包是pretty多简单,但你必须使用一些样板。

With the javax.sound.sampled package it's pretty much straightforward, but you have to use some boilerplate.

下面是上一个很好的教程: www.wikijava.org /维基/ Play_a_wave_sound_in_Java

Here's a good tutorial on that: www.wikijava.org/wiki/Play_a_wave_sound_in_Java

基本上,你必须从你的阵列创建一个的InputStream 并用它来创建一个的AudioInputStream 。在那里,您必须指定音频数据的格式。

Basically you have to create an InputStream from your array and use that to create an AudioInputStream. There you have to specify the format of your audio data.

然后你打开一个输出流(的SourceDataLine ),并从音频流成流复制字节。

Then you open an output stream (SourceDataLine) and copy the bytes from the audio stream into that stream.

这篇关于如何发挥在Java PCM原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆