Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java采样-播放原始PCM Wav数据_Java_Javax.sound.sampled - Fatal编程技术网

Java采样-播放原始PCM Wav数据

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

我现在正在研究声音

我通过读取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 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,我什么也没听到