jdk/src/java.desktop/share/classes/javax/sound/midi/SoundbankResource.java
changeset 26037 508779ce6619
parent 26003 d630c97424bd
parent 25859 3317bb8137f4
child 47195 b309b58eb190
equal deleted inserted replaced
25992:e9b05e933ddd 26037:508779ce6619
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package javax.sound.midi;
    26 package javax.sound.midi;
    27 
    27 
       
    28 import javax.sound.sampled.AudioInputStream;
       
    29 
    28 /**
    30 /**
    29  * A <code>SoundbankResource</code> represents any audio resource stored
    31  * A {@code SoundbankResource} represents any audio resource stored in a
    30  * in a <code>{@link Soundbank}</code>.  Common soundbank resources include:
    32  * {@link Soundbank}. Common soundbank resources include:
    31  * <ul>
    33  * <ul>
    32  * <li>Instruments.  An instrument may be specified in a variety of
    34  * <li>Instruments. An instrument may be specified in a variety of ways.
    33  * ways.  However, all soundbanks have some mechanism for defining
    35  * However, all soundbanks have some mechanism for defining instruments. In
    34  * instruments.  In doing so, they may reference other resources
    36  * doing so, they may reference other resources stored in the soundbank. Each
    35  * stored in the soundbank.  Each instrument has a <code>Patch</code>
    37  * instrument has a {@code Patch} which specifies the MIDI program and bank by
    36  * which specifies the MIDI program and bank by which it may be
    38  * which it may be referenced in MIDI messages. Instrument information may be
    37  * referenced in MIDI messages.  Instrument information may be
    39  * stored in {@link Instrument} objects.</li>
    38  * stored in <code>{@link Instrument}</code> objects.
    40  * <li>Audio samples. A sample typically is a sampled audio waveform which
    39  * <li>Audio samples.  A sample typically is a sampled audio waveform
    41  * contains a short sound recording whose duration is a fraction of a second, or
    40  * which contains a short sound recording whose duration is a fraction of
    42  * at most a few seconds. These audio samples may be used by a
    41  * a second, or at most a few seconds.  These audio samples may be
    43  * {@link Synthesizer} to synthesize sound in response to MIDI commands, or
    42  * used by a <code>{@link Synthesizer}</code> to synthesize sound in response to MIDI
    44  * extracted for use by an application. (The terminology reflects musicians' use
    43  * commands, or extracted for use by an application.
    45  * of the word "sample" to refer collectively to a series of contiguous audio
    44  * (The terminology reflects musicians' use of the word "sample" to refer
    46  * samples or frames, rather than to a single, instantaneous sample.) The data
    45  * collectively to a series of contiguous audio samples or frames, rather than
    47  * class for an audio sample will be an object that encapsulates the audio
    46  * to a single, instantaneous sample.)
    48  * sample data itself and information about how to interpret it (the format of
    47  * The data class for an audio sample will be an object
    49  * the audio data), such as an {@link AudioInputStream}.</li>
    48  * that encapsulates the audio sample data itself and information
    50  * <li>Embedded sequences. A sound bank may contain built-in song data stored in
    49  * about how to interpret it (the format of the audio data), such
    51  * a data object such as a {@link Sequence}.</li>
    50  * as an <code>{@link javax.sound.sampled.AudioInputStream}</code>.     </li>
       
    51  * <li>Embedded sequences.  A sound bank may contain built-in
       
    52  * song data stored in a data object such as a <code>{@link Sequence}</code>.
       
    53  * </ul>
    52  * </ul>
    54  * <p>
    53  * Synthesizers that use wavetable synthesis or related techniques play back the
    55  * Synthesizers that use wavetable synthesis or related
    54  * audio in a sample when synthesizing notes, often when emulating the
    56  * techniques play back the audio in a sample when
    55  * real-world instrument that was originally recorded. However, there is not
    57  * synthesizing notes, often when emulating the real-world instrument that
    56  * necessarily a one-to-one correspondence between the {@code Instruments} and
    58  * was originally recorded.  However, there is not necessarily a one-to-one
    57  * samples in a {@code Soundbank}. A single {@code Instrument} can use multiple
    59  * correspondence between the <code>Instruments</code> and samples
    58  * SoundbankResources (typically for notes of dissimilar pitch or brightness).
    60  * in a <code>Soundbank</code>.  A single <code>Instrument</code> can use
    59  * Also, more than one {@code Instrument} can use the same sample.
    61  * multiple SoundbankResources (typically for notes of dissimilar pitch or
       
    62  * brightness).  Also, more than one <code>Instrument</code> can use the same
       
    63  * sample.
       
    64  *
    60  *
    65  * @author Kara Kytle
    61  * @author Kara Kytle
    66  */
    62  */
    67 
       
    68 public abstract class SoundbankResource {
    63 public abstract class SoundbankResource {
    69 
    64 
    70 
       
    71     /**
    65     /**
    72      * The sound bank that contains the <code>SoundbankResources</code>
    66      * The sound bank that contains the {@code SoundbankResources}.
    73      */
    67      */
    74     private final Soundbank soundBank;
    68     private final Soundbank soundBank;
    75 
    69 
    76 
       
    77     /**
    70     /**
    78      * The name of the <code>SoundbankResource</code>
    71      * The name of the {@code SoundbankResource}.
    79      */
    72      */
    80     private final String name;
    73     private final String name;
    81 
       
    82 
    74 
    83     /**
    75     /**
    84      * The class used to represent the sample's data.
    76      * The class used to represent the sample's data.
    85      */
    77      */
    86     private final Class<?> dataClass;
    78     private final Class<?> dataClass;
    87 
    79 
    88 
       
    89     /**
    80     /**
    90      * The wavetable index.
    81      * The wavetable index.
    91      */
    82      */
    92     //private final int index;
    83     //private final int index;
    93 
    84 
    94 
       
    95     /**
    85     /**
    96      * Constructs a new <code>SoundbankResource</code> from the given sound bank
    86      * Constructs a new {@code SoundbankResource} from the given sound bank and
    97      * and wavetable index.  (Setting the <code>SoundbankResource's</code> name,
    87      * wavetable index. (Setting the {@code SoundbankResource's} name, sampled
    98      * sampled audio data, and instruments is a subclass responsibility.)
    88      * audio data, and instruments is a subclass responsibility.)
    99      * @param soundBank the sound bank containing this <code>SoundbankResource</code>
       
   100      * @param name the name of the sample
       
   101      * @param dataClass the class used to represent the sample's data
       
   102      *
    89      *
       
    90      * @param  soundBank the sound bank containing this
       
    91      *         {@code SoundbankResource}
       
    92      * @param  name the name of the sample
       
    93      * @param  dataClass the class used to represent the sample's data
   103      * @see #getSoundbank
    94      * @see #getSoundbank
   104      * @see #getName
    95      * @see #getName
   105      * @see #getDataClass
    96      * @see #getDataClass
   106      * @see #getData
    97      * @see #getData
   107      */
    98      */
   110         this.soundBank = soundBank;
   101         this.soundBank = soundBank;
   111         this.name = name;
   102         this.name = name;
   112         this.dataClass = dataClass;
   103         this.dataClass = dataClass;
   113     }
   104     }
   114 
   105 
   115 
       
   116     /**
   106     /**
   117      * Obtains the sound bank that contains this <code>SoundbankResource</code>.
   107      * Obtains the sound bank that contains this {@code SoundbankResource}.
   118      * @return the sound bank in which this <code>SoundbankResource</code> is stored
   108      *
       
   109      * @return the sound bank in which this {@code SoundbankResource} is stored
   119      */
   110      */
   120     public Soundbank getSoundbank() {
   111     public Soundbank getSoundbank() {
   121         return soundBank;
   112         return soundBank;
   122     }
   113     }
   123 
   114 
   124 
       
   125     /**
   115     /**
   126      * Obtains the name of the resource.  This should generally be a string
   116      * Obtains the name of the resource. This should generally be a string
   127      * descriptive of the resource.
   117      * descriptive of the resource.
       
   118      *
   128      * @return the instrument's name
   119      * @return the instrument's name
   129      */
   120      */
   130     public String getName() {
   121     public String getName() {
   131         return name;
   122         return name;
   132     }
   123     }
   133 
   124 
   134 
       
   135     /**
   125     /**
   136      * Obtains the class used by this sample to represent its data.
   126      * Obtains the class used by this sample to represent its data. The object
   137      * The object returned by <code>getData</code> will be of this
   127      * returned by {@code getData} will be of this class. If this
   138      * class.  If this <code>SoundbankResource</code> object does not support
   128      * {@code SoundbankResource} object does not support direct access to its
   139      * direct access to its data, returns <code>null</code>.
   129      * data, returns {@code null}.
   140      * @return the class used to represent the sample's data, or
   130      *
   141      * null if the data is not accessible
   131      * @return the class used to represent the sample's data, or null if the
       
   132      *         data is not accessible
   142      */
   133      */
   143     public Class<?> getDataClass() {
   134     public Class<?> getDataClass() {
   144         return dataClass;
   135         return dataClass;
   145     }
   136     }
   146 
   137 
   147 
       
   148     /**
   138     /**
   149      * Obtains the sampled audio that is stored in this <code>SoundbankResource</code>.
   139      * Obtains the sampled audio that is stored in this
   150      * The type of object returned depends on the implementation of the
   140      * {@code SoundbankResource}. The type of object returned depends on the
   151      * concrete class, and may be queried using <code>getDataClass</code>.
   141      * implementation of the concrete class, and may be queried using
       
   142      * {@code getDataClass}.
       
   143      *
   152      * @return an object containing the sampled audio data
   144      * @return an object containing the sampled audio data
   153      * @see #getDataClass
   145      * @see #getDataClass
   154      */
   146      */
   155     public abstract Object getData();
   147     public abstract Object getData();
   156 
   148 
   157 
       
   158     /**
   149     /**
   159      * Obtains the index of this <code>SoundbankResource</code> into the
   150      * Obtains the index of this {@code SoundbankResource} into the
   160      * <code>Soundbank's</code> set of <code>SoundbankResources</code>.
   151      * {@code Soundbank's} set of {@code SoundbankResources}.
       
   152      *
   161      * @return the wavetable index
   153      * @return the wavetable index
   162      */
   154      */
   163     //public int getIndex() {
   155     //public int getIndex() {
   164     //  return index;
   156     //  return index;
   165     //}
   157     //}
   166 
   158 
   167 
       
   168     /**
   159     /**
   169      * Obtains a list of the instruments in the sound bank that use the
   160      * Obtains a list of the instruments in the sound bank that use the
   170      * <code>SoundbankResource</code> for sound synthesis.
   161      * {@code SoundbankResource} for sound synthesis.
   171      * @return an array of <code>Instruments</code> that reference this
       
   172      * <code>SoundbankResource</code>
       
   173      *
   162      *
       
   163      * @return an array of {@code Instruments} that reference this
       
   164      *         {@code SoundbankResource}
   174      * @see Instrument#getSamples
   165      * @see Instrument#getSamples
   175      */
   166      */
   176     //public abstract Instrument[] getInstruments();
   167     //public abstract Instrument[] getInstruments();
   177 }
   168 }