KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > midi > SoundbankResource


1 /*
2  * @(#)SoundbankResource.java 1.15 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.midi;
9
10 /**
11  * A <code>SoundbankResource</code> represents any audio resource stored
12  * in a <code>{@link Soundbank}</code>. Common soundbank resources include:
13  * <ul>
14  * <li>Instruments. An instrument may be specified in a variety of
15  * ways. However, all soundbanks have some mechanism for defining
16  * instruments. In doing so, they may reference other resources
17  * stored in the soundbank. Each instrument has a <code>Patch</code>
18  * which specifies the MIDI program and bank by which it may be
19  * referenced in MIDI messages. Instrument information may be
20  * stored in <code>{@link Instrument}</code> objects.
21  * <li>Audio samples. A sample typically is a sampled audio waveform
22  * which contains a short sound recording whose duration is a fraction of
23  * a second, or at most a few seconds. These audio samples may be
24  * used by a <code>{@link Synthesizer}</code> to synthesize sound in response to MIDI
25  * commands, or extracted for use by an application.
26  * (The terminology reflects musicians' use of the word "sample" to refer
27  * collectively to a series of contiguous audio samples or frames, rather than
28  * to a single, instantaneous sample.)
29  * The data class for an audio sample will be an object
30  * that encapsulates the audio sample data itself and information
31  * about how to interpret it (the format of the audio data), such
32  * as an <code>{@link javax.sound.sampled.AudioInputStream}</code>. </li>
33  * <li>Embedded sequences. A sound bank may contain built-in
34  * song data stored in a data object such as a <code>{@link Sequence}</code>.
35  * </ul>
36  * <p>
37  * Synthesizers that use wavetable synthesis or related
38  * techniques play back the audio in a sample when
39  * synthesizing notes, often when emulating the real-world instrument that
40  * was originally recorded. However, there is not necessarily a one-to-one
41  * correspondence between the <code>Instruments</code> and samples
42  * in a <code>Soundbank</code>. A single <code>Instrument</code> can use
43  * multiple SoundbankResources (typically for notes of dissimilar pitch or
44  * brightness). Also, more than one <code>Instrument</code> can use the same
45  * sample.
46  *
47  * @version 1.15, 04/05/05
48  * @author Kara Kytle
49  */

50
51 public abstract class SoundbankResource {
52
53
54     /**
55      * The sound bank that contains the <code>SoundbankResources</code>
56      */

57     private final Soundbank JavaDoc soundBank;
58
59
60     /**
61      * The name of the <code>SoundbankResource</code>
62      */

63     private final String JavaDoc name;
64
65
66     /**
67      * The class used to represent the sample's data.
68      */

69     private final Class JavaDoc dataClass;
70
71
72     /**
73      * The wavetable index.
74      */

75     //private final int index;
76

77
78     /**
79      * Constructs a new <code>SoundbankResource</code> from the given sound bank
80      * and wavetable index. (Setting the <code>SoundbankResource's</code> name,
81      * sampled audio data, and instruments is a subclass responsibility.)
82      * @param soundBank the sound bank containing this <code>SoundbankResource</code>
83      * @param name the name of the sample
84      * @param dataClass the class used to represent the sample's data
85      *
86      * @see #getSoundbank
87      * @see #getName
88      * @see #getDataClass
89      * @see #getData
90      */

91     protected SoundbankResource(Soundbank JavaDoc soundBank, String JavaDoc name, Class JavaDoc<?> dataClass) {
92
93     this.soundBank = soundBank;
94     this.name = name;
95     this.dataClass = dataClass;
96     }
97
98
99     /**
100      * Obtains the sound bank that contains this <code>SoundbankResource</code>.
101      * @return the sound bank in which this <code>SoundbankResource</code> is stored
102      */

103     public Soundbank JavaDoc getSoundbank() {
104     return soundBank;
105     }
106
107
108     /**
109      * Obtains the name of the resource. This should generally be a string
110      * descriptive of the resource.
111      * @return the instrument's name
112      */

113     public String JavaDoc getName() {
114     return name;
115     }
116
117     
118     /**
119      * Obtains the class used by this sample to represent its data.
120      * The object returned by <code>getData</code> will be of this
121      * class. If this <code>SoundbankResource</code> object does not support
122      * direct access to its data, returns <code>null</code>.
123      * @return the class used to represent the sample's data, or
124      * null if the data is not accessible
125      */

126     public Class JavaDoc<?> getDataClass() {
127     return dataClass;
128     }
129
130     
131     /**
132      * Obtains the sampled audio that is stored in this <code>SoundbankResource</code>.
133      * The type of object returned depends on the implementation of the
134      * concrete class, and may be queried using <code>getDataClass</code>.
135      * @return an object containing the sampled audio data
136      * @see #getDataClass
137      */

138     public abstract Object JavaDoc getData();
139
140
141     /**
142      * Obtains the index of this <code>SoundbankResource</code> into the
143      * <code>Soundbank's</code> set of <code>SoundbankResources</code>.
144      * @return the wavetable index
145      */

146     //public int getIndex() {
147
// return index;
148
//}
149

150     
151     /**
152      * Obtains a list of the instruments in the sound bank that use the
153      * <code>SoundbankResource</code> for sound synthesis.
154      * @return an array of <code>Instruments</code> that reference this
155      * <code>SoundbankResource</code>
156      *
157      * @see Instrument#getSamples
158      */

159     //public abstract Instrument[] getInstruments();
160
}
161
162
Popular Tags