コード例 #1
0
  private synchronized void startSampled(AudioInputStream as, InputStream in)
      throws UnsupportedAudioFileException, LineUnavailableException {

    Info info = null;
    DataPusher datapusher = null;
    DataLine.Info lineinfo = null;
    SourceDataLine sourcedataline = null;

    // if ALAW or ULAW, we must convert....
    as = Toolkit.getPCMConvertedAudioInputStream(as);

    if (as == null) {
      // could not convert
      return;
    }

    lineinfo = new DataLine.Info(SourceDataLine.class, as.getFormat());
    if (!(AudioSystem.isLineSupported(lineinfo))) {
      return;
    }
    sourcedataline = (SourceDataLine) AudioSystem.getLine(lineinfo);
    datapusher = new DataPusher(sourcedataline, as);

    info = new Info(null, in, datapusher);
    infos.addElement(info);

    datapusher.start();
  }
コード例 #2
0
ファイル: SoundManager.java プロジェクト: tmackgit/GameDev
  /** Signals that a PooledThread has started. Creates the Thread's line and buffer. */
  protected void threadStarted() {
    // wait for the SoundManager constructor to finish
    synchronized (this) {
      try {
        wait();
      } catch (InterruptedException ex) {
      }
    }

    // use a short, 100ms (1/10th sec) buffer for filters that
    // change in real-time
    int bufferSize =
        playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10);

    // create, open, and start the line
    SourceDataLine line;
    DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat);
    try {
      line = (SourceDataLine) AudioSystem.getLine(lineInfo);
      line.open(playbackFormat, bufferSize);
    } catch (LineUnavailableException ex) {
      // the line is unavailable - signal to end this thread
      Thread.currentThread().interrupt();
      return;
    }

    line.start();

    // create the buffer
    byte[] buffer = new byte[bufferSize];

    // set this thread's locals
    localLine.set(line);
    localBuffer.set(buffer);
  }