Java采样-播放原始PCM Wav数据
我现在正在研究声音 我通过读取wav文件并根据wav规范跳过前44个字节来获取字节[],数据从字节44开始。 我使用22500Hz并通过Audacity将其导出到16位PCM 我的方法是这样的Java采样-播放原始PCM Wav数据,java,javax.sound.sampled,Java,Javax.sound.sampled,我现在正在研究声音 我通过读取wav文件并根据wav规范跳过前44个字节来获取字节[],数据从字节44开始。 我使用22500Hz并通过Audacity将其导出到16位PCM 我的方法是这样的 private static final AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,22500f,16,1,2,2,false); public static void play(Sound
private static final AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,22500f,16,1,2,2,false);
public static void play(Sound s) throws LineUnavailableException, IOException
{
int selectedSample = (int) (Math.random() * ( s.samples.length ));
Clip clip = AudioSystem.getClip();
AudioInputStream ais;
ais = new AudioInputStream(new ByteArrayInputStream(s.samples[selectedSample]),format,s.samples[selectedSample].length);
clip.open (ais);
clip.start ();
}
public class Sound
{
public byte[][] samples;
float pitchLow;
float pitchHigh;
float volumeLow;
float volumeHigh;
byte chance;
}
我的音乐课是这样的
private static final AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,22500f,16,1,2,2,false);
public static void play(Sound s) throws LineUnavailableException, IOException
{
int selectedSample = (int) (Math.random() * ( s.samples.length ));
Clip clip = AudioSystem.getClip();
AudioInputStream ais;
ais = new AudioInputStream(new ByteArrayInputStream(s.samples[selectedSample]),format,s.samples[selectedSample].length);
clip.open (ais);
clip.start ();
}
public class Sound
{
public byte[][] samples;
float pitchLow;
float pitchHigh;
float volumeLow;
float volumeHigh;
byte chance;
}
我做错了什么,我没有收到LineUnavailableException,我什么也没听到