1 /*
   2  * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import java.util.Map;
  29 
  30 import javax.sound.midi.MidiUnavailableException;
  31 import javax.sound.midi.Synthesizer;
  32 import javax.sound.sampled.AudioFormat;
  33 import javax.sound.sampled.AudioInputStream;
  34 import javax.sound.sampled.SourceDataLine;
  35 
  36 /**
  37  * {@code AudioSynthesizer} is a {@code Synthesizer}
  38  * which renders it's output audio into {@code SourceDataLine}
  39  * or {@code AudioInputStream}.
  40  *
  41  * @see MidiSystem#getSynthesizer
  42  * @see Synthesizer
  43  *
  44  * @author Karl Helgason
  45  */
  46 public interface AudioSynthesizer extends Synthesizer {
  47 
  48     /**
  49      * Obtains the current format (encoding, sample rate, number of channels,
  50      * etc.) of the synthesizer audio data.
  51      *
  52      * <p>If the synthesizer is not open and has never been opened, it returns
  53      * the default format.
  54      *
  55      * @return current audio data format
  56      * @see AudioFormat
  57      */
  58     AudioFormat getFormat();
  59 
  60     /**
  61      * Gets information about the possible properties for the synthesizer.
  62      *
  63      * @param info a proposed list of tag/value pairs that will be sent on open.
  64      * @return an array of {@code AudioSynthesizerPropertyInfo} objects
  65      * describing possible properties. This array may be an empty array if
  66      * no properties are required.
  67      */
  68     AudioSynthesizerPropertyInfo[] getPropertyInfo(Map<String, Object> info);
  69 
  70     /**
  71      * Opens the synthesizer and starts rendering audio into
  72      * {@code SourceDataLine}.
  73      *
  74      * <p>An application opening a synthesizer explicitly with this call
  75      * has to close the synthesizer by calling {@link #close}. This is
  76      * necessary to release system resources and allow applications to
  77      * exit cleanly.
  78      *
  79      * <p>Note that some synthesizers, once closed, cannot be reopened.
  80      * Attempts to reopen such a synthesizer will always result in
  81      * a {@code MidiUnavailableException}.
  82      *
  83      * @param line which {@code AudioSynthesizer} writes output audio into.
  84      * If {@code line} is null, then line from system default mixer is used.
  85      * @param info a {@code Map<String,Object>} object containing
  86      * properties for additional configuration supported by synthesizer.
  87      * If {@code info} is null then default settings are used.
  88      *
  89      * @throws MidiUnavailableException thrown if the synthesizer cannot be
  90      * opened due to resource restrictions.
  91      * @throws SecurityException thrown if the synthesizer cannot be
  92      * opened due to security restrictions.
  93      *
  94      * @see #close
  95      * @see #isOpen
  96      */
  97     void open(SourceDataLine line, Map<String, Object> info)
  98             throws MidiUnavailableException;
  99 
 100     /**
 101      * Opens the synthesizer and renders audio into returned
 102      * {@code AudioInputStream}.
 103      *
 104      * <p>An application opening a synthesizer explicitly with this call
 105      * has to close the synthesizer by calling {@link #close}. This is
 106      * necessary to release system resources and allow applications to
 107      * exit cleanly.
 108      *
 109      * <p>Note that some synthesizers, once closed, cannot be reopened.
 110      * Attempts to reopen such a synthesizer will always result in
 111      * a {@code MidiUnavailableException}.
 112      *
 113      * @param targetFormat specifies the {@code AudioFormat}
 114      * used in returned {@code AudioInputStream}.
 115      * @param info a {@code Map<String,Object>} object containing
 116      * properties for additional configuration supported by synthesizer.
 117      * If {@code info} is null then default settings are used.
 118      *
 119      * @throws MidiUnavailableException thrown if the synthesizer cannot be
 120      * opened due to resource restrictions.
 121      * @throws SecurityException thrown if the synthesizer cannot be
 122      * opened due to security restrictions.
 123      *
 124      * @see #close
 125      * @see #isOpen
 126      */
 127     AudioInputStream openStream(AudioFormat targetFormat,
 128                                 Map<String, Object> info)
 129             throws MidiUnavailableException;
 130 }