コード例 #1
0
 public static void main(String[] args) throws Exception {
   AudioSynthesizer synth = new SoftSynthesizer();
   synth.openStream(null, null);
   Soundbank defsbk = synth.getDefaultSoundbank();
   if (defsbk != null) {
     assertTrue(defsbk.getInstruments().length == synth.getLoadedInstruments().length);
   }
   synth.close();
 }
コード例 #2
0
  public static void render(OutputStream os, AudioFormat format, Map<String, Object> info)
      throws Exception {
    AudioSynthesizer synth = (AudioSynthesizer) new SoftSynthesizer();
    AudioInputStream stream = synth.openStream(format, info);
    Receiver recv = synth.getReceiver();
    Soundbank defsbk = synth.getDefaultSoundbank();
    if (defsbk != null) synth.unloadAllInstruments(defsbk);
    synth.loadAllInstruments(soundbank);

    double totalTime = 5;
    send(sequence, recv);

    long len = (long) (stream.getFormat().getFrameRate() * (totalTime + 4));
    stream = new AudioInputStream(stream, stream.getFormat(), len);

    long t = System.currentTimeMillis();
    AudioSystem.write(stream, AudioFileFormat.Type.WAVE, os);
    t = System.currentTimeMillis() - t;
    stream.close();
  }